]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(cleanup): New function -- broken out from quit.
authorJim Meyering <jim@meyering.net>
Fri, 22 Dec 1995 06:49:10 +0000 (06:49 +0000)
committerJim Meyering <jim@meyering.net>
Fri, 22 Dec 1995 06:49:10 +0000 (06:49 +0000)
(interrupt_handler): Rewrite to reset default signal handler,
call cleanup, then repost caught signal.

src/dd.c

index ac43697f2cfb5dcef3408fa76b69ae6a6a746fb8..419c1ed345457d4635244176e8d7173d997d9ef8 100644 (file)
--- a/src/dd.c
+++ b/src/dd.c
@@ -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