Fix to set SIGCHLD to SIG_DFL instead of SIG_IGN in watchdog processes
authorYugo Nagata <nagata@sraoss.co.jp>
Fri, 20 Feb 2015 07:27:32 +0000 (16:27 +0900)
committerYugo Nagata <nagata@sraoss.co.jp>
Fri, 20 Feb 2015 07:27:32 +0000 (16:27 +0900)
When using waitpid, it isn't necessary to set SIGCHLD SIG_IGN. Rather,
waitpid returns ECHLD and WIFEXITED could be zero even when the child
process exit successfully. Due to this, it was recognized that ping
exited abnormally in error.

In addition, signal functions are replaced to pool_singal.

watchdog/watchdog.c
watchdog/wd_child.c
watchdog/wd_if.c
watchdog/wd_lifecheck.c

index e65d26182bf82b82eb6af546c009dbaf0ce192a1..7a04a56b407bc27bd7ff0d8391d75bce40b6d9fb 100644 (file)
@@ -24,7 +24,6 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
-#include <signal.h>
 #include <ctype.h>
 #include <sys/un.h>
 #include <sys/types.h>
@@ -146,12 +145,12 @@ wd_main(int fork_wait_time)
 
        init_ps_display("", "", "", "");
 
-       signal(SIGCHLD, SIG_DFL);
-       signal(SIGHUP, SIG_IGN);        
-       signal(SIGINT, wd_exit);        
-       signal(SIGQUIT, wd_exit);       
-       signal(SIGTERM, wd_exit);       
-       signal(SIGPIPE, SIG_IGN);       
+       pool_signal(SIGCHLD, SIG_DFL);
+       pool_signal(SIGHUP, SIG_IGN);   
+       pool_signal(SIGINT, wd_exit);   
+       pool_signal(SIGQUIT, wd_exit);  
+       pool_signal(SIGTERM, wd_exit);  
+       pool_signal(SIGPIPE, SIG_IGN);  
 
        set_ps_display("lifecheck",false);
        /* wait until ready to go */
index 3c661c3e8ed6650edc08b7e1b0c73818483871a2..f4e2dd0b5553c762404b5654735326545cfb439f 100644 (file)
@@ -23,7 +23,6 @@
  */
 #include <sys/types.h>
 #include <sys/socket.h>
-#include <signal.h>
 #include <stdio.h>
 #include <errno.h>
 #include <string.h>
@@ -60,15 +59,15 @@ wd_child(int fork_wait_time)
 
        myargv = save_ps_display_args(myargc, myargv);
 
-       signal(SIGTERM, wd_child_exit);
-       signal(SIGINT, wd_child_exit);
-       signal(SIGQUIT, wd_child_exit);
-       signal(SIGCHLD, SIG_IGN);
-       signal(SIGHUP, SIG_IGN);
-       signal(SIGUSR1, SIG_IGN);
-       signal(SIGUSR2, SIG_IGN);
-       signal(SIGPIPE, SIG_IGN);
-       signal(SIGALRM, SIG_IGN);
+       pool_signal(SIGTERM, wd_child_exit);
+       pool_signal(SIGINT, wd_child_exit);
+       pool_signal(SIGQUIT, wd_child_exit);
+       pool_signal(SIGCHLD, SIG_DFL);
+       pool_signal(SIGHUP, SIG_IGN);
+       pool_signal(SIGUSR1, SIG_IGN);
+       pool_signal(SIGUSR2, SIG_IGN);
+       pool_signal(SIGPIPE, SIG_IGN);
+       pool_signal(SIGALRM, SIG_IGN);
 
        init_ps_display("", "", "", "");
 
index 6aa6d7f57166d4aeb1c02277b347ff558aaa43b2..ef75c317ae6015ad521f37855c7c75924a52ae6b 100644 (file)
@@ -184,21 +184,31 @@ exec_ifconfig(char * path,char * command)
                for (;;)
                {
                        int result;
-                       result = wait(&status);
+
+                       result = waitpid(pid, &status, 0);
                        if (result < 0)
                        {
                                if (errno == EINTR)
                                        continue;
+
+                               pool_debug("exec_ifconfig: waitpid() failed. reason: %s ", strerror(errno));
+
                                return WD_NG;
                        }
 
                        if (WIFEXITED(status) == 0 || WEXITSTATUS(status) != 0)
+                       {
+                               pool_debug("exec_ifconfig: '%s' failed. exit status: %d",
+                                          command, WEXITSTATUS(status));
                                return WD_NG;
+                       }
                        else
                                break;
                }
                close(pfd[0]);
        }
+       pool_debug("exec_ifconfig: '%s' succeeded", command);
+
        return WD_OK;
 }
 
index 5afa9366eb405e252a28350b8c2f501a5ac26a80..3083e8963f6ba5a9c3e054f117bbb10b2e9a2946 100644 (file)
@@ -27,7 +27,6 @@
 #include <time.h>
 #include <string.h>
 #include <stdlib.h>
-#include <signal.h>
 #include <unistd.h>
 #include <netdb.h>
 #include "pool.h"