i3bar: Don't start child unless status_command
If a command is passed to `start_child` which is NULL, such as in the case when there is no `status_command` specified in the bar config, do not start a child process to listen on stdin. fixes #1140
This commit is contained in:
parent
38b6936c25
commit
ac74a63662
|
@ -452,10 +452,16 @@ void child_write_output(void) {
|
||||||
/*
|
/*
|
||||||
* Start a child-process with the specified command and reroute stdin.
|
* Start a child-process with the specified command and reroute stdin.
|
||||||
* We actually start a $SHELL to execute the command so we don't have to care
|
* We actually start a $SHELL to execute the command so we don't have to care
|
||||||
* about arguments and such
|
* about arguments and such.
|
||||||
|
*
|
||||||
|
* If `command' is NULL, such as in the case when no `status_command' is given
|
||||||
|
* in the bar config, no child will be started.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void start_child(char *command) {
|
void start_child(char *command) {
|
||||||
|
if (command == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
/* Allocate a yajl parser which will be used to parse stdin. */
|
/* Allocate a yajl parser which will be used to parse stdin. */
|
||||||
memset(&callbacks, '\0', sizeof(yajl_callbacks));
|
memset(&callbacks, '\0', sizeof(yajl_callbacks));
|
||||||
callbacks.yajl_map_key = stdin_map_key;
|
callbacks.yajl_map_key = stdin_map_key;
|
||||||
|
@ -478,7 +484,6 @@ void start_child(char *command) {
|
||||||
gen = yajl_gen_alloc(NULL);
|
gen = yajl_gen_alloc(NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (command != NULL) {
|
|
||||||
int pipe_in[2]; /* pipe we read from */
|
int pipe_in[2]; /* pipe we read from */
|
||||||
int pipe_out[2]; /* pipe we write to */
|
int pipe_out[2]; /* pipe we write to */
|
||||||
|
|
||||||
|
@ -515,7 +520,6 @@ void start_child(char *command) {
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* We set O_NONBLOCK because blocking is evil in event-driven software */
|
/* We set O_NONBLOCK because blocking is evil in event-driven software */
|
||||||
fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
|
fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
|
||||||
|
|
|
@ -127,10 +127,6 @@ static int config_string_cb(void *params_, const unsigned char *val, unsigned in
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(cur_key, "status_command")) {
|
if (!strcmp(cur_key, "status_command")) {
|
||||||
/* We cannot directly start the child here, because start_child() also
|
|
||||||
* needs to be run when no command was specified (to setup stdin).
|
|
||||||
* Therefore we save the command in 'config' and access it later in
|
|
||||||
* got_bar_config() */
|
|
||||||
DLOG("command = %.*s\n", len, val);
|
DLOG("command = %.*s\n", len, val);
|
||||||
sasprintf(&config.command, "%.*s", len, val);
|
sasprintf(&config.command, "%.*s", len, val);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -100,9 +100,6 @@ void got_bar_config(char *reply) {
|
||||||
/* Resolve color strings to colorpixels and save them, then free the strings. */
|
/* Resolve color strings to colorpixels and save them, then free the strings. */
|
||||||
init_colors(&(config.colors));
|
init_colors(&(config.colors));
|
||||||
|
|
||||||
/* The name of this function is actually misleading. Even if no command is
|
|
||||||
* specified, this function initiates the watchers to listen on stdin and
|
|
||||||
* react accordingly */
|
|
||||||
start_child(config.command);
|
start_child(config.command);
|
||||||
FREE(config.command);
|
FREE(config.command);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue