#include "common.h"
/* Global variables for child_*() */
-i3bar_child child = { 0 };
+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 */
* `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;
/*
* 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;
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;
}
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);
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 };