]> git.sur5r.net Git - i3/i3/commitdiff
i3bar: Group child processes for signalling
authorTony Crisci <tony@dubstepdish.com>
Sun, 1 Dec 2013 06:37:43 +0000 (01:37 -0500)
committerMichael Stapelberg <michael@stapelberg.de>
Wed, 4 Dec 2013 18:45:19 +0000 (19:45 +0100)
Set the process group id of the child process by calling `setpgid` after
forking and before calling `exec`.

The process group ID will be set to the process ID of the forked
process. Processes spawned by this child process will also have this
group ID.

Send signals to the process group with `killpg`. This will send the
signal to all of the process group.

fixes #1128

i3bar/src/child.c

index dce0218fd305fda1ee38be246a47cc2e3618f249..fd4185eec8ca0fd23a83da74f8950dde9b7766d4 100644 (file)
@@ -424,6 +424,7 @@ void start_child(char *command) {
                 dup2(pipe_in[1], STDOUT_FILENO);
                 dup2(pipe_out[0], STDIN_FILENO);
 
+                setpgid(child.pid, 0);
                 execl(_PATH_BSHELL, _PATH_BSHELL, "-c", command, (char*) NULL);
                 return;
             default:
@@ -507,8 +508,8 @@ void send_block_clicked(int button, const char *name, const char *instance, int
 void kill_child_at_exit(void) {
     if (child.pid > 0) {
         if (child.cont_signal > 0 && child.stopped)
-            kill(child.pid, child.cont_signal);
-        kill(child.pid, SIGTERM);
+            killpg(child.pid, child.cont_signal);
+        killpg(child.pid, SIGTERM);
     }
 }
 
@@ -520,8 +521,8 @@ void kill_child_at_exit(void) {
 void kill_child(void) {
     if (child.pid > 0) {
         if (child.cont_signal > 0 && child.stopped)
-            kill(child.pid, child.cont_signal);
-        kill(child.pid, SIGTERM);
+            killpg(child.pid, child.cont_signal);
+        killpg(child.pid, SIGTERM);
         int status;
         waitpid(child.pid, &status, 0);
         cleanup();
@@ -535,7 +536,7 @@ void kill_child(void) {
 void stop_child(void) {
     if (child.stop_signal > 0 && !child.stopped) {
         child.stopped = true;
-        kill(child.pid, child.stop_signal);
+        killpg(child.pid, child.stop_signal);
     }
 }
 
@@ -546,6 +547,6 @@ void stop_child(void) {
 void cont_child(void) {
     if (child.cont_signal > 0 && child.stopped) {
         child.stopped = false;
-        kill(child.pid, child.cont_signal);
+        killpg(child.pid, child.cont_signal);
     }
 }