]> granicus.if.org Git - sysstat/commitdiff
sadc: Don't send signal if parent process is already dead
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 18 Oct 2014 13:35:43 +0000 (15:35 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 18 Oct 2014 13:35:43 +0000 (15:35 +0200)
If sar (parent of sadc) dies before sadc completes its job
then init will become sadc parent. Now if we pass SIGINT to
sadc, it will pass that to init process and result in system
reboot.

This patch check parent process before sending signal.

Test case:
  Run sar_test script in shell prompt and press ctrl+C twice.

  cat sar_test
    while true; do /usr/local/bin/sar -n DEV 1 3; sleep 3; done

Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
sadc.c

diff --git a/sadc.c b/sadc.c
index 55e76f5ac2179b306685fc56b6ba17a7feeacb27..4d737d0c0dd4710cf4f3f62862e12e28135ea4f1 100644 (file)
--- a/sadc.c
+++ b/sadc.c
@@ -242,6 +242,10 @@ void int_handler(int sig)
                exit(1);
        }
 
+       /* Don't send signal to init process!! */
+       if (getppid() == 1)
+               return;
+
        /*
         * When starting sar then pressing ctrl/c, SIGINT is received
         * by sadc, not sar. So send SIGINT to sar so that average stats