diff options
| author | Roy Marples <roy@marples.name> | 2008-06-10 22:23:57 +0000 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2008-06-10 22:23:57 +0000 |
| commit | eb942e0abce48272767404ca604573d3ea674302 (patch) | |
| tree | 479c4d8049b34bb3758034ca0bd2354dce079ce3 /signals.c | |
| parent | 7349c9bf8cf950dfb92d53f9a860f34b33d97229 (diff) | |
| download | dhcpcd-eb942e0abce48272767404ca604573d3ea674302.tar.xz | |
Remove the signal array stack as our pipe handling should be secure enough now. Also, move the normalize close_on_exec and setting non block.
Diffstat (limited to 'signals.c')
| -rw-r--r-- | signals.c | 34 |
1 files changed, 8 insertions, 26 deletions
@@ -38,7 +38,6 @@ #include "signals.h" static int signal_pipe[2]; -static int signals[5]; static const int handle_sigs[] = { SIGHUP, @@ -50,17 +49,9 @@ static const int handle_sigs[] = { static void signal_handler(int sig) { - unsigned int i = 0; int serrno = errno; - /* Add a signal to our stack */ - while (signals[i]) - i++; - if (i <= sizeof(signals) / sizeof(signals[0])) - signals[i] = sig; - write(signal_pipe[1], &sig, sizeof(sig)); - /* Restore errno */ errno = serrno; } @@ -75,7 +66,7 @@ signal_fd(void) int signal_exists(int fd) { - if (signals[0] || fd_hasdata(fd) == 1) + if (fd_hasdata(fd) == 1) return 0; return -1; } @@ -87,20 +78,9 @@ int signal_read(int fd) { int sig = -1; - unsigned int i = 0; char buf[16]; size_t bytes; - /* Pop a signal off the our stack */ - if (signals[0]) { - sig = signals[0]; - while (i < (sizeof(signals) / sizeof(signals[0])) - 1) { - signals[i] = signals[i + 1]; - if (!signals[++i]) - break; - } - } - if (fd_hasdata(fd) == 1) { memset(buf, 0, sizeof(buf)); bytes = read(signal_pipe[0], buf, sizeof(buf)); @@ -117,12 +97,14 @@ signal_init(void) { if (pipe(signal_pipe) == -1) return -1; - + /* Don't block on read */ + if (set_nonblock(signal_pipe[0]) == -1) + return -1; /* Stop any scripts from inheriting us */ - close_on_exec(signal_pipe[0]); - close_on_exec(signal_pipe[1]); - - memset(signals, 0, sizeof(signals)); + if (set_cloexec(signal_pipe[0]) == -1) + return -1; + if (set_cloexec(signal_pipe[1]) == -1) + return -1; return 0; } |
