if(p == -1) {
pthread_mutex_unlock(&fork_lock);
+ close(fd[0]);
+ close(fd[1]);
tvherror(LS_SPAWN, "Unable to fork() for \"%s\" -- %s",
prog, strerror(errno));
return -1;
if(p == -1) {
pthread_mutex_unlock(&fork_lock);
+ close(fd[0]);
+ close(fd[1]);
tvherror(LS_SPAWN, "Unable to fork() for \"%s\" -- %s",
prog, strerror(errno));
// do not pass the local variable outside
spawn_enq(prog, p);
- if (pid)
+ if (pid) {
*pid = p;
+ // make the spawned process a session leader so killing the
+ // process group recursively kills any child process that
+ // might have been spawned
+ setpgid(p, p);
+ }
+
// do not pass the local variable outside
if (argv[0] == bin)
argv[0] = NULL;