diff options
author | sabetts <sabetts> | 2002-11-24 21:52:20 +0000 |
---|---|---|
committer | sabetts <sabetts> | 2002-11-24 21:52:20 +0000 |
commit | bc15e751d3b8538720e89848db8bfb9f6f636c20 (patch) | |
tree | d192ee4116d97cdac29c2e5ee9095ab063930e23 /src/main.c | |
parent | 1445719b28b87a3be8f13f5a931adc6fc3da9da3 (diff) | |
download | ratpoison-bc15e751d3b8538720e89848db8bfb9f6f636c20.zip |
* 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.
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -33,6 +33,7 @@ #include <unistd.h> #include <getopt.h> #include <string.h> +#include <sys/wait.h> #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(); |