From bc15e751d3b8538720e89848db8bfb9f6f636c20 Mon Sep 17 00:00:00 2001 From: sabetts Date: Sun, 24 Nov 2002 21:52:20 +0000 Subject: * src/main.c: include sys/wait.h (chld_handler): new function * src/events.c: include sys/wait.h (handle_signals): Print an error message in the case of a child signal. * src/data.h (struct rp_child_info): New struct. (child_info): New global. (chld_signalled): likewise * src/actions.c (spawn): Let the SIGCHLD handler handle process completion instead of doing an ugly dance. --- src/main.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index d5d5417..4f4e9af 100644 --- a/src/main.c +++ b/src/main.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "ratpoison.h" @@ -41,6 +42,7 @@ static void init_screen (screen_info *s, int screen_num); int alarm_signalled = 0; int kill_signalled = 0; int hup_signalled = 0; +int chld_signalled = 0; int rat_x; int rat_y; int rat_visible = 1; /* rat is visible by default */ @@ -61,6 +63,7 @@ screen_info *screens; int num_screens; Display *dpy; +struct rp_child_info child_info; struct rp_defaults defaults; int ignore_badwindow = 0; @@ -201,6 +204,33 @@ alrm_handler (int signum) alarm_signalled++; } +void +chld_handler (int signum) +{ + int pid, status, serrno; + serrno = errno; + + while (1) + { + pid = waitpid (WAIT_ANY, &status, WNOHANG); + if (pid <= 0) + break; + + PRINT_DEBUG("Child status: %d\n", WEXITSTATUS (status)); + + /* Tell ratpoison about the CHLD signal. We are only interested + in reporting commands that failed to execute. These processes + have a return value of 127 (according to the sh manual). */ + if (WEXITSTATUS (status) == 127) + { + chld_signalled = 1; + child_info.pid = pid; + child_info.status = status; + } + } + errno = serrno; +} + int handler (Display *d, XErrorEvent *e) { @@ -537,6 +567,7 @@ main (int argc, char *argv[]) set_sig_handler (SIGTERM, sighandler); set_sig_handler (SIGINT, sighandler); set_sig_handler (SIGHUP, hup_handler); + set_sig_handler (SIGCHLD, chld_handler); /* Setup ratpoison's internal structures */ init_defaults(); -- cgit v1.2.3