ctdbd: Make sure we don't kill init process by mistake
authorAmitay Isaacs <amitay@gmail.com>
Thu, 6 Jun 2013 06:42:02 +0000 (16:42 +1000)
committerAmitay Isaacs <amitay@gmail.com>
Fri, 14 Jun 2013 06:39:48 +0000 (16:39 +1000)
If getpgrp() fails, it will return -1 and that will send KILL signal to init
process (PID 1).  This does not happen on RHEL, but does on AIX.

Reported-by: Chris Cowan <cc@us.ibm.com>
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
server/eventscript.c

index 5c448c731ae1ab68ac03d06ca9062c18b0104800..58a42f4d8955a9ae050325dc89760de3a7bae11c 100644 (file)
@@ -34,8 +34,15 @@ static void ctdb_event_script_timeout(struct event_context *ev, struct timed_eve
  */
 static void sigterm(int sig)
 {
+       pid_t pid;
+
        /* all the child processes will be running in the same process group */
-       kill(-getpgrp(), SIGKILL);
+       pid = getpgrp();
+       if (pid == -1) {
+               kill(-getpid(), SIGKILL);
+       } else {
+               kill(-pid, SIGKILL);
+       }
        _exit(1);
 }