]> 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 890dce29b58211f29ff8d73cf6a19a51a0015d46..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
  *
@@ -38,11 +38,14 @@ char *statusline_buffer = NULL;
 void cleanup() {
     if (stdin_io != NULL) {
         ev_io_stop(main_loop, stdin_io);
-        ev_child_stop(main_loop, child_sig);
         FREE(stdin_io);
-        FREE(child_sig);
         FREE(statusline_buffer);
     }
+
+    if (child_sig != NULL) {
+        ev_child_stop(main_loop, child_sig);
+        FREE(child_sig);
+    }
 }
 
 /*
@@ -69,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);