mirror of
https://codeberg.org/dwl/dwl.git
synced 2024-12-27 11:46:31 +00:00
Don't bother with ignoring SIGCHLD
It added complexity, especially with the differences in behavior between handled and ignored signals across an exec().
This commit is contained in:
parent
9c592da01f
commit
68a17f962e
1 changed files with 32 additions and 41 deletions
73
dwl.c
73
dwl.c
|
@ -297,6 +297,7 @@ static void setmon(Client *c, Monitor *m, uint32_t newtags);
|
||||||
static void setpsel(struct wl_listener *listener, void *data);
|
static void setpsel(struct wl_listener *listener, void *data);
|
||||||
static void setsel(struct wl_listener *listener, void *data);
|
static void setsel(struct wl_listener *listener, void *data);
|
||||||
static void setup(void);
|
static void setup(void);
|
||||||
|
static void sigchld(int unused);
|
||||||
static void spawn(const Arg *arg);
|
static void spawn(const Arg *arg);
|
||||||
static void startdrag(struct wl_listener *listener, void *data);
|
static void startdrag(struct wl_listener *listener, void *data);
|
||||||
static void tag(const Arg *arg);
|
static void tag(const Arg *arg);
|
||||||
|
@ -397,7 +398,6 @@ static void configurex11(struct wl_listener *listener, void *data);
|
||||||
static void createnotifyx11(struct wl_listener *listener, void *data);
|
static void createnotifyx11(struct wl_listener *listener, void *data);
|
||||||
static Atom getatom(xcb_connection_t *xc, const char *name);
|
static Atom getatom(xcb_connection_t *xc, const char *name);
|
||||||
static void sethints(struct wl_listener *listener, void *data);
|
static void sethints(struct wl_listener *listener, void *data);
|
||||||
static void sigchld(int unused);
|
|
||||||
static void xwaylandready(struct wl_listener *listener, void *data);
|
static void xwaylandready(struct wl_listener *listener, void *data);
|
||||||
static struct wl_listener new_xwayland_surface = {.notify = createnotifyx11};
|
static struct wl_listener new_xwayland_surface = {.notify = createnotifyx11};
|
||||||
static struct wl_listener xwayland_ready = {.notify = xwaylandready};
|
static struct wl_listener xwayland_ready = {.notify = xwaylandready};
|
||||||
|
@ -1963,8 +1963,6 @@ run(char *startup_cmd)
|
||||||
if ((child_pid = fork()) < 0)
|
if ((child_pid = fork()) < 0)
|
||||||
die("startup: fork:");
|
die("startup: fork:");
|
||||||
if (child_pid == 0) {
|
if (child_pid == 0) {
|
||||||
sa.sa_handler = SIG_DFL;
|
|
||||||
sigaction(SIGCHLD, &sa, NULL);
|
|
||||||
dup2(piperw[0], STDIN_FILENO);
|
dup2(piperw[0], STDIN_FILENO);
|
||||||
close(piperw[0]);
|
close(piperw[0]);
|
||||||
close(piperw[1]);
|
close(piperw[1]);
|
||||||
|
@ -2129,27 +2127,19 @@ setsel(struct wl_listener *listener, void *data)
|
||||||
void
|
void
|
||||||
setup(void)
|
setup(void)
|
||||||
{
|
{
|
||||||
struct sigaction sa_term = {.sa_flags = SA_RESTART, .sa_handler = quitsignal};
|
/* Set up signal handlers */
|
||||||
struct sigaction sa_sigchld = {
|
struct sigaction sa = {.sa_flags = SA_RESTART, .sa_handler = sigchld};
|
||||||
#ifdef XWAYLAND
|
sigemptyset(&sa.sa_mask);
|
||||||
.sa_flags = SA_RESTART,
|
sigaction(SIGCHLD, &sa, NULL);
|
||||||
.sa_handler = sigchld,
|
|
||||||
#else
|
sa.sa_handler = quitsignal;
|
||||||
.sa_flags = SA_NOCLDSTOP | SA_NOCLDWAIT | SA_RESTART,
|
sigaction(SIGINT, &sa, NULL);
|
||||||
.sa_handler = SIG_IGN,
|
sigaction(SIGTERM, &sa, NULL);
|
||||||
#endif
|
|
||||||
};
|
|
||||||
sigemptyset(&sa_term.sa_mask);
|
|
||||||
sigemptyset(&sa_sigchld.sa_mask);
|
|
||||||
/* The Wayland display is managed by libwayland. It handles accepting
|
/* The Wayland display is managed by libwayland. It handles accepting
|
||||||
* clients from the Unix socket, manging Wayland globals, and so on. */
|
* clients from the Unix socket, manging Wayland globals, and so on. */
|
||||||
dpy = wl_display_create();
|
dpy = wl_display_create();
|
||||||
|
|
||||||
/* Set up signal handlers */
|
|
||||||
sigaction(SIGCHLD, &sa_sigchld, NULL);
|
|
||||||
sigaction(SIGINT, &sa_term, NULL);
|
|
||||||
sigaction(SIGTERM, &sa_term, NULL);
|
|
||||||
|
|
||||||
/* The backend is a wlroots feature which abstracts the underlying input and
|
/* The backend is a wlroots feature which abstracts the underlying input and
|
||||||
* output hardware. The autocreate option will choose the most suitable
|
* output hardware. The autocreate option will choose the most suitable
|
||||||
* backend based on the current environment, such as opening an X11 window
|
* backend based on the current environment, such as opening an X11 window
|
||||||
|
@ -2323,13 +2313,32 @@ setup(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sigchld(int unused)
|
||||||
|
{
|
||||||
|
#ifdef XWAYLAND
|
||||||
|
siginfo_t in;
|
||||||
|
/* We should be able to remove this function in favor of a simple
|
||||||
|
* struct sigaction sa = {.sa_handler = SIG_IGN};
|
||||||
|
* sigaction(SIGCHLD, &sa, NULL);
|
||||||
|
* but the Xwayland implementation in wlroots currently prevents us from
|
||||||
|
* setting our own disposition for SIGCHLD.
|
||||||
|
*/
|
||||||
|
/* WNOWAIT leaves the child in a waitable state, in case this is the
|
||||||
|
* XWayland process
|
||||||
|
*/
|
||||||
|
while (!waitid(P_ALL, 0, &in, WEXITED|WNOHANG|WNOWAIT) && in.si_pid
|
||||||
|
&& (!xwayland || in.si_pid != xwayland->server->pid))
|
||||||
|
waitpid(in.si_pid, NULL, 0);
|
||||||
|
#else
|
||||||
|
while (waitpid(-1, NULL, WNOHANG) > 0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
spawn(const Arg *arg)
|
spawn(const Arg *arg)
|
||||||
{
|
{
|
||||||
if (fork() == 0) {
|
if (fork() == 0) {
|
||||||
struct sigaction sa = {.sa_flags = SA_RESTART, .sa_handler = SIG_DFL};
|
|
||||||
sigemptyset(&sa.sa_mask);
|
|
||||||
sigaction(SIGCHLD, &sa, NULL);
|
|
||||||
dup2(STDERR_FILENO, STDOUT_FILENO);
|
dup2(STDERR_FILENO, STDOUT_FILENO);
|
||||||
setsid();
|
setsid();
|
||||||
execvp(((char **)arg->v)[0], (char **)arg->v);
|
execvp(((char **)arg->v)[0], (char **)arg->v);
|
||||||
|
@ -2772,24 +2781,6 @@ sethints(struct wl_listener *listener, void *data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
sigchld(int unused)
|
|
||||||
{
|
|
||||||
siginfo_t in;
|
|
||||||
/* We should be able to remove this function in favor of a simple
|
|
||||||
* struct sigaction sa = {.sa_handler = SIG_IGN};
|
|
||||||
* sigaction(SIGCHLD, &sa, NULL);
|
|
||||||
* but the Xwayland implementation in wlroots currently prevents us from
|
|
||||||
* setting our own disposition for SIGCHLD.
|
|
||||||
*/
|
|
||||||
/* WNOWAIT leaves the child in a waitable state, in case this is the
|
|
||||||
* XWayland process
|
|
||||||
*/
|
|
||||||
while (!waitid(P_ALL, 0, &in, WEXITED|WNOHANG|WNOWAIT) && in.si_pid
|
|
||||||
&& (!xwayland || in.si_pid != xwayland->server->pid))
|
|
||||||
waitpid(in.si_pid, NULL, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
xwaylandready(struct wl_listener *listener, void *data)
|
xwaylandready(struct wl_listener *listener, void *data)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue