]> git.sur5r.net Git - i3/i3/blobdiff - i3bar/src/child.c
Merge branch 'master' into next
[i3/i3] / i3bar / src / child.c
index 52019b368611753be6d7d08352da1d27fbcc98ca..cfdf911c11442866176ce158293dd2952befcefc 100644 (file)
 #include "common.h"
 
 /* Global variables for child_*() */
-i3bar_child child = {};
+i3bar_child child;
 
 /* stdin- and sigchild-watchers */
 ev_io    *stdin_io;
 ev_child *child_sig;
 
 /* JSON parser for stdin */
-yajl_callbacks callbacks;
 yajl_handle parser;
 
 /* JSON generator for stdout */
@@ -81,12 +80,7 @@ static void clear_status_blocks() {
  * `draw_bars' is called, the error message text will be drawn on the bar in
  * the space allocated for the statusline.
  */
-
-/* forward function declaration is needed to add __attribute__ mechanism which
- * helps the compiler understand we are defining a printf wrapper */
-static void set_statusline_error(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
-
-static void set_statusline_error(const char *format, ...) {
+__attribute__ ((format (printf, 1, 2))) static void set_statusline_error(const char *format, ...) {
     clear_status_blocks();
 
     char *message;
@@ -272,6 +266,8 @@ static int stdin_end_array(void *context) {
 /*
  * Helper function to read stdin
  *
+ * Returns NULL on EOF.
+ *
  */
 static unsigned char *get_buffer(ev_io *watcher, int *ret_buffer_len) {
     int fd = watcher->fd;
@@ -291,11 +287,7 @@ static unsigned char *get_buffer(ev_io *watcher, int *ret_buffer_len) {
             exit(EXIT_FAILURE);
         }
         if (n == 0) {
-            /* end of file, kill the watcher */
             ELOG("stdin: received EOF\n");
-            cleanup();
-            set_statusline_error("Received EOF from statusline process");
-            draw_bars(false);
             *ret_buffer_len = -1;
             return NULL;
         }
@@ -426,7 +418,7 @@ void child_sig_cb(struct ev_loop *loop, ev_child *watcher, int revents) {
     if (exit_status == 126)
         set_statusline_error("status_command is not executable (exit %d)", exit_status);
     else if (exit_status == 127)
-        set_statusline_error("status_command not found (exit %d)", exit_status);
+        set_statusline_error("status_command not found or is missing a library dependency (exit %d)", exit_status);
     else
         set_statusline_error("status_command process exited unexpectedly (exit %d)", exit_status);
 
@@ -463,15 +455,16 @@ void start_child(char *command) {
         return;
 
     /* Allocate a yajl parser which will be used to parse stdin. */
-    memset(&callbacks, '\0', sizeof(yajl_callbacks));
-    callbacks.yajl_map_key = stdin_map_key;
-    callbacks.yajl_boolean = stdin_boolean;
-    callbacks.yajl_string = stdin_string;
-    callbacks.yajl_integer = stdin_integer;
-    callbacks.yajl_start_array = stdin_start_array;
-    callbacks.yajl_end_array = stdin_end_array;
-    callbacks.yajl_start_map = stdin_start_map;
-    callbacks.yajl_end_map = stdin_end_map;
+    static yajl_callbacks callbacks = {
+        .yajl_boolean = stdin_boolean,
+        .yajl_integer = stdin_integer,
+        .yajl_string = stdin_string,
+        .yajl_start_map = stdin_start_map,
+        .yajl_map_key = stdin_map_key,
+        .yajl_end_map = stdin_end_map,
+        .yajl_start_array = stdin_start_array,
+        .yajl_end_array = stdin_end_array,
+    };
 #if YAJL_MAJOR < 2
     yajl_parser_config parse_conf = { 0, 0 };