Skip to content

Commit

Permalink
Added setsid() to new process when using SpawnWindow() (#489)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerjenigeUberMensch authored Dec 5, 2024
1 parent 2d47ae5 commit cc6eb39
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/toggle.c
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,9 @@ SpawnWindow(const Arg *arg)
err = EX_OSERR;
return;
}

struct sigaction sa;

switch((child = fork()))
{
case -1:
Expand All @@ -906,10 +909,16 @@ SpawnWindow(const Arg *arg)
break;
case 0:
close(pipefds[0]);
struct sigaction sa;
if (_wm.dpy)
close(XCBConnectionNumber(_wm.dpy));
setsid();
{ close(XCBConnectionNumber(_wm.dpy));
}

if(setsid() < 0)
{
perror("setsid");
_exit(EXIT_FAILURE);
}

sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sa.sa_handler = SIG_DFL;
Expand All @@ -923,7 +932,7 @@ SpawnWindow(const Arg *arg)
execvp(((char **)arg->v)[0], (char **)arg->v);
Debug0("execvp() failed.");
write(pipefds[1], &errno, sizeof(int));
_exit(0);
_exit(EXIT_SUCCESS);
break;
default:
close(pipefds[1]);
Expand All @@ -940,6 +949,7 @@ SpawnWindow(const Arg *arg)
return;
}
close(pipefds[0]);
#ifdef DEBUG
Debug0("waiting for child...");
/* would do 0, over WNOHANG, but as the name implies we cant hang the window manager any time */
while (waitpid(child, &err, WNOHANG) == -1)
Expand All @@ -958,6 +968,7 @@ SpawnWindow(const Arg *arg)
else if(WIFSIGNALED(err))
{ Debug("child killed by %d\n", WTERMSIG(err));
}
#endif
}
}

Expand Down

0 comments on commit cc6eb39

Please sign in to comment.