diff options
author | Theodore Ts'o <tytso@mit.edu> | 2008-03-26 09:42:00 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2008-03-27 21:00:56 -0400 |
commit | 62653d99d823f5d73eba925885896d91ea8bab91 (patch) | |
tree | bdcca6fa5a56b92e5df712c8402b2b196c31ce01 /misc/logsave.c | |
parent | 1dc506cbe956419f0eafb8e84bae108ec2f0b2de (diff) | |
download | e2fsprogs-62653d99d823f5d73eba925885896d91ea8bab91.tar.gz |
logsave: Pass any SIGTERM or SIGINT signals to child process
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'misc/logsave.c')
-rw-r--r-- | misc/logsave.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/misc/logsave.c b/misc/logsave.c index f256c20e..c6fd3f8c 100644 --- a/misc/logsave.c +++ b/misc/logsave.c @@ -19,6 +19,9 @@ #include <fcntl.h> #include <time.h> #include <errno.h> +#ifdef HAVE_SIGNAL_H +#include <signal.h> +#endif #ifdef HAVE_GETOPT_H #include <getopt.h> #else @@ -32,6 +35,7 @@ void *outbuf = 0; int verbose = 0; int do_skip = 0; int skip_mode = 0; +pid_t child_pid = -1; static void usage(char *progname) { @@ -102,17 +106,36 @@ static int do_read(int fd) return c; } +static void signal_term(int sig) +{ + if (child_pid > 0) + kill(child_pid, sig); +} + static int run_program(char **argv) { int fds[2]; int status, rc, pid; char buffer[80]; +#ifdef HAVE_SIGNAL_H + struct sigaction sa; +#endif if (pipe(fds) < 0) { perror("pipe"); exit(1); } +#ifdef HAVE_SIGNAL_H + memset(&sa, 0, sizeof(struct sigaction)); + sa.sa_handler = signal_term; + sigaction(SIGINT, &sa, 0); + sigaction(SIGTERM, &sa, 0); +#ifdef SA_RESTART + sa.sa_flags = SA_RESTART; +#endif +#endif + pid = fork(); if (pid < 0) { perror("vfork"); @@ -127,11 +150,13 @@ static int run_program(char **argv) perror(argv[0]); exit(1); } + child_pid = pid; close(fds[1]); while (!(waitpid(pid, &status, WNOHANG ))) { do_read(fds[0]); } + child_pid = -1; do_read(fds[0]); close(fds[0]); |