OSDN Git Service

Ensure dumpstate children die
authorJohn Michelau <w14107@motorola.com>
Thu, 7 Mar 2013 21:35:35 +0000 (15:35 -0600)
committerJohn Michelau <w14107@motorola.com>
Mon, 11 Mar 2013 16:44:15 +0000 (11:44 -0500)
Use prctl(PR_SET_PDEATHSIG, SIGKILL) in each forked child to ensure
it dies when dumpstate dies.

This is important for two cases:
- dumpstate runs a timer for each child process.  On expiration, it
  sends SIGTERM to kill the process.  Sometimes SIGTERM isn't enough
  to kill a hung process, so the child lives on.
- When dumpstate is killed by the user before completing, outstanding
  children continue to run and generate output.

Change-Id: I96e0dc918c26d56c9fee53611980ba2edd238712

cmds/dumpstate/utils.c

index 8f132d5..eaef3d4 100644 (file)
@@ -31,6 +31,7 @@
 #include <sys/klog.h>
 #include <time.h>
 #include <unistd.h>
+#include <sys/prctl.h>
 
 #include <cutils/debugger.h>
 #include <cutils/properties.h>
@@ -199,6 +200,9 @@ int run_command(const char *title, int timeout_seconds, const char *command, ...
         const char *args[1024] = {command};
         size_t arg;
 
+        /* make sure the child dies when dumpstate dies */
+        prctl(PR_SET_PDEATHSIG, SIGKILL);
+
         va_list ap;
         va_start(ap, command);
         if (title) printf("------ %s (%s", title, command);