]> git.sur5r.net Git - i3/i3/blobdiff - i3bar/src/child.c
Update changelog and copyright, bump version and more
[i3/i3] / i3bar / src / child.c
index 1fae759335684ee3e2dc0f480449658d2523f359..3f59d060f51979d15fd367a9444d8d3eb7f451a2 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * i3bar - an xcb-based status- and ws-bar for i3
  *
- * © 2010 Axel Wagner and contributors
+ * © 2010-2011 Axel Wagner and contributors
  *
  * See file LICNSE for license information
  *
@@ -11,6 +11,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/types.h>
+#include <sys/wait.h>
 #include <signal.h>
 #include <stdio.h>
 #include <fcntl.h>
@@ -35,11 +36,16 @@ char *statusline_buffer = NULL;
  *
  */
 void cleanup() {
-    ev_io_stop(main_loop, stdin_io);
-    ev_child_stop(main_loop, child_sig);
-    FREE(stdin_io);
-    FREE(child_sig);
-    FREE(statusline_buffer);
+    if (stdin_io != NULL) {
+        ev_io_stop(main_loop, stdin_io);
+        FREE(stdin_io);
+        FREE(statusline_buffer);
+    }
+
+    if (child_sig != NULL) {
+        ev_child_stop(main_loop, child_sig);
+        FREE(child_sig);
+    }
 }
 
 /*
@@ -66,18 +72,22 @@ void stdin_io_cb(struct ev_loop *loop, ev_io *watcher, int revents) {
             exit(EXIT_FAILURE);
         }
         if (n == 0) {
-            if (rec == buffer_len) {
-                buffer_len += STDIN_CHUNK_SIZE;
-                buffer = realloc(buffer, buffer_len);
-            } else {
-                if (rec != 0) {
-                    /* remove trailing newline and finish up */
-                    buffer[rec-1] = '\0';
-                }
-                break;
+            if (rec != 0) {
+                /* remove trailing newline and finish up */
+                buffer[rec-1] = '\0';
             }
+
+            /* end of file, kill the watcher */
+            DLOG("stdin: EOF\n");
+            cleanup();
+            break;
         }
         rec += n;
+
+        if (rec == buffer_len) {
+            buffer_len += STDIN_CHUNK_SIZE;
+            buffer = realloc(buffer, buffer_len);
+           }
     }
     if (*buffer == '\0') {
         FREE(buffer);
@@ -143,7 +153,9 @@ void start_child(char *command) {
 
                 /* If hide-on-modifier is set, we start of by sending the
                  * child a SIGSTOP, because the bars aren't mapped at start */
-                stop_child();
+                if (config.hide_on_modifier) {
+                    stop_child();
+                }
 
                 break;
         }
@@ -172,8 +184,11 @@ void kill_child() {
     if (child_pid != 0) {
         kill(child_pid, SIGCONT);
         kill(child_pid, SIGTERM);
+        int status;
+        waitpid(child_pid, &status, 0);
+        child_pid = 0;
+        cleanup();
     }
-    cleanup();
 }
 
 /*