manual: Remove outdated sentence about para_afh.
[paraslash.git] / signal.c
index b2317c9b3a51fefca4c490681424a2f8709563b2..3b202a2c8ba6a62b23fa46f7e99ed207c4f08750 100644 (file)
--- a/signal.c
+++ b/signal.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2004-2012 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2004-2013 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -51,15 +51,22 @@ err_out:
        exit(EXIT_FAILURE);
 }
 
-/*
- * just write one integer to signal pipe
- */
+/* Write the signal number to signal pipe. */
 static void generic_signal_handler(int s)
 {
+       /*
+        * Signal handlers that make system calls must save a copy of errno on
+        * entry to the handler and restore it on exit, to prevent the
+        * possibility of overwriting a errno value that had previously been
+        * set in the main program.
+        */
+       int save_errno = errno;
        ssize_t ret = write(signal_pipe[1], &s, sizeof(int));
 
-       if (ret == sizeof(int))
+       if (ret == sizeof(int)) {
+               errno = save_errno;
                return;
+       }
        if (ret < 0)
                PARA_EMERG_LOG("%s\n", strerror(errno));
        else