]> git.tuebingen.mpg.de Git - dss.git/blobdiff - sig.c
Improve comment of snapshot_currently_being_removed.
[dss.git] / sig.c
diff --git a/sig.c b/sig.c
index d2d7e3b59076a0c2899d53730bda9aad929f6bc6..fe7fcede927b574391ce0cf4ee8e5035916d4fd1 100644 (file)
--- a/sig.c
+++ b/sig.c
@@ -1,8 +1,4 @@
-/*
- * Copyright (C) 2004-2010 Andre Noll <maan@tuebingen.mpg.de>
- *
- * Licensed under the GPL v2. For licencing details see COPYING.
- */
+/* SPDX-License-Identifier: GPL-2.0 */
 
 #include <string.h>
 #include <errno.h>
@@ -64,12 +60,27 @@ err_out:
        exit(EXIT_FAILURE);
 }
 
-/*
- * just write one integer to signal pipe
- */
+/* Write the signal number to the signal pipe, abort on errors. */
 static void generic_signal_handler(int s)
 {
-       write(signal_pipe[1], &s, sizeof(int));
+       /*
+        * 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)) {
+               errno = save_errno;
+               return;
+       }
+       if (ret < 0)
+               DSS_EMERG_LOG(("%s\n", strerror(errno)));
+       else
+               DSS_EMERG_LOG(("short write to signal pipe\n"));
+       exit(EXIT_FAILURE);
 }
 
 /**