Whamcloud - gitweb
LU-8080 utils: Replace calls to signal with sigaction 55/19855/10
authorQuentin Bouget <quentin.bouget.ocre@cea.fr>
Fri, 13 May 2016 07:47:33 +0000 (09:47 +0200)
committerOleg Drokin <oleg.drokin@intel.com>
Fri, 27 May 2016 00:58:04 +0000 (00:58 +0000)
The man page for signal (2) states that sigaction should replace
signal for portability. It also states:
"The effects of signal() in a multithreaded process are unspecified."

This patch affects utils/lhsmtool_posix.c for the second reason and
utils/liblustreapi_hsm.c for completeness even though: "The only
portable use of signal() is to set a signal’s disposition to
SIG_DFL or SIG_IGN." (which is what is done in liblustreapi_hsm.c)

Signed-off-by: Quentin Bouget <quentin.bouget.ocre@cea.fr>
Change-Id: Ib247fab937e3aac514f418c7260cdd67fc9e442c
Reviewed-on: http://review.whamcloud.com/19855
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Tested-by: Jenkins
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Reviewed-by: Henri Doreau <henri.doreau@cea.fr>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/utils/lhsmtool_posix.c
lustre/utils/liblustreapi_hsm.c

index fdf63c8..d99fce3 100644 (file)
@@ -1790,7 +1790,8 @@ static void handler(int signal)
 /* Daemon waits for messages from the kernel; run it in the background. */
 static int ct_run(void)
 {
-       int     rc;
+       struct sigaction cleanup_sigaction;
+       int rc;
 
        if (opt.o_daemonize) {
                rc = daemon(1, 1);
@@ -1820,14 +1821,17 @@ static int ct_run(void)
                return rc;
        }
 
-       signal(SIGINT, handler);
-       signal(SIGTERM, handler);
+       memset(&cleanup_sigaction, 0, sizeof(cleanup_sigaction));
+       cleanup_sigaction.sa_handler = handler;
+       sigemptyset(&cleanup_sigaction.sa_mask);
+       sigaction(SIGINT, &cleanup_sigaction, NULL);
+       sigaction(SIGTERM, &cleanup_sigaction, NULL);
 
        while (1) {
-               struct hsm_action_list  *hal;
-               struct hsm_action_item  *hai;
-               int                      msgsize;
-               int                      i = 0;
+               struct hsm_action_list *hal;
+               struct hsm_action_item *hai;
+               int msgsize;
+               int i = 0;
 
                CT_TRACE("waiting for message from kernel");
 
index 7eaf8eb..0b12f37 100644 (file)
@@ -472,9 +472,10 @@ out_free:
  */
 int llapi_hsm_register_event_fifo(const char *path)
 {
-       int rc;
        int read_fd;
        struct stat statbuf;
+       struct sigaction ignore_action;
+       int rc;
 
        /* Create the FIFO if necessary. */
        if ((mkfifo(path, 0644) < 0) && (errno != EEXIST)) {
@@ -523,7 +524,10 @@ int llapi_hsm_register_event_fifo(const char *path)
        }
 
        /* Ignore SIGPIPEs -- can occur if the reader goes away. */
-       signal(SIGPIPE, SIG_IGN);
+       memset(&ignore_action, 0, sizeof(ignore_action));
+       ignore_action.sa_handler = SIG_IGN;
+       sigemptyset(&ignore_action.sa_mask);
+       sigaction(SIGPIPE, &ignore_action, NULL);
 
        return 0;
 }