diff options
author | Jim Meyering <jim@meyering.net> | 1995-12-22 06:49:10 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1995-12-22 06:49:10 +0000 |
commit | 05d30f27154d4a7a676e457e57f83ef243ae02cd (patch) | |
tree | 99f000b17766c0c0b0a0e0ccc3f69b5c4f2c906a | |
parent | c8d085374c38b67a6839d7da7ebfbb2d3eb7507e (diff) | |
download | coreutils-05d30f27154d4a7a676e457e57f83ef243ae02cd.tar.xz |
(cleanup): New function -- broken out from quit.
(interrupt_handler): Rewrite to reset default signal handler,
call cleanup, then repost caught signal.
-rw-r--r-- | src/dd.c | 30 |
1 files changed, 23 insertions, 7 deletions
@@ -95,7 +95,7 @@ char *xmalloc (); int safe_read (); int full_write (); -static RETSIGTYPE interrupt_handler __P ((void)); +static RETSIGTYPE interrupt_handler __P ((int)); static int bit_count __P ((register unsigned int i)); static int parse_integer __P ((char *str)); static void apply_translations __P ((void)); @@ -1043,21 +1043,37 @@ print_stats (void) } static void -quit (int code) +cleanup (void) { - int errcode = code ? code : 1; print_stats (); if (close (input_fd) < 0) - error (errcode, errno, "%s", input_file); + error (1, errno, "%s", input_file); if (close (output_fd) < 0) - error (errcode, errno, "%s", output_file); + error (1, errno, "%s", output_file); +} + +static void +quit (int code) +{ + cleanup (); exit (code); } static RETSIGTYPE -interrupt_handler (void) +interrupt_handler (int sig) { - quit (1); +#ifdef SA_INTERRUPT + struct sigaction sigact; + + sigact.sa_handler = SIG_DFL; + sigemptyset (&sigact.sa_mask); + sigact.sa_flags = 0; + sigaction (sig, &sigact, NULL); +#else /* !SA_INTERRUPT */ + signal (sig, SIG_DFL); +#endif /* SA_INTERRUPT */ + cleanup (); + kill (getpid (), sig); } static void |