# HG changeset patch # User Rob Landley # Date 1400675056 18000 # Node ID 313980d3d78ca8cd9d7e40b357403175c040ada0 # Parent c25ee9918e65354c885648da4c7821a49e65601b Add generic_signal() handler, which sets toys.signal and writes byte to toys.signalfd if set. diff -r c25ee9918e65 -r 313980d3d78c lib/lib.c --- a/lib/lib.c Wed May 21 07:09:09 2014 -0500 +++ b/lib/lib.c Wed May 21 07:24:16 2014 -0500 @@ -614,12 +614,24 @@ // not in posix: SIGNIFY(STKFLT), SIGNIFY(WINCH), SIGNIFY(IO), SIGNIFY(PWR) // obsolete: SIGNIFY(PROF) SIGNIFY(POLL) +// Handler that sets toys.signal, and writes to toys.signalfd if set +void generic_signal(int sig) +{ + if (toys.signalfd) { + char c = sig; + + writeall(toys.signalfd, &c, 1); + } + toys.signal = sig; +} + // Install the same handler on every signal that defaults to killing the process void sigatexit(void *handler) { int i; for (i=0; signames[i].num != SIGCHLD; i++) signal(signames[i].num, handler); } + // Convert name to signal number. If name == NULL print names. int sig_to_num(char *pidstr) { diff -r c25ee9918e65 -r 313980d3d78c lib/lib.h --- a/lib/lib.h Wed May 21 07:09:09 2014 -0500 +++ b/lib/lib.h Wed May 21 07:24:16 2014 -0500 @@ -174,6 +174,7 @@ // signal +void generic_signal(int signal); void sigatexit(void *handler); int sig_to_num(char *pidstr); char *num_to_sig(int sig); diff -r c25ee9918e65 -r 313980d3d78c main.c --- a/main.c Wed May 21 07:09:09 2014 -0500 +++ b/main.c Wed May 21 07:24:16 2014 -0500 @@ -80,6 +80,7 @@ } toys.old_umask = umask(0); if (!(which->flags & TOYFLAG_UMASK)) umask(toys.old_umask); + toys.signalfd--; } // Setup toybox global state for this command. diff -r c25ee9918e65 -r 313980d3d78c toys.h --- a/toys.h Wed May 21 07:09:09 2014 -0500 +++ b/toys.h Wed May 21 07:24:16 2014 -0500 @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -125,6 +126,8 @@ int exithelp; // Should error_exit print a usage message first? int old_umask; // Old umask preserved by TOYFLAG_UMASK int toycount; // Total number of commands in this build + int signal; // generic_signal() records what signal it saw here + int signalfd; // and writes signal to this fd, if set // This is at the end so toy_init() doesn't zero it. jmp_buf *rebound; // longjmp here instead of exit when do_rebound set