strip_dzen_formats(buffer);
FREE(statusline);
statusline = buffer;
- printf("%s", buffer);
+ printf("%s\n", buffer);
draw_bars();
}
}
void start_child(char *command) {
- int fd[2];
- pipe(fd);
- child_pid = fork();
- switch (child_pid) {
- case -1:
- printf("ERROR: Couldn't fork()");
- exit(EXIT_FAILURE);
- case 0:
- close(fd[0]);
+ child_pid = 0;
+ if (command != NULL) {
+ int fd[2];
+ pipe(fd);
+ child_pid = fork();
+ switch (child_pid) {
+ case -1:
+ printf("ERROR: Couldn't fork()");
+ exit(EXIT_FAILURE);
+ case 0:
+ close(fd[0]);
+
+ dup2(fd[1], STDOUT_FILENO);
- dup2(fd[1], STDOUT_FILENO);
+ static const char *shell = NULL;
- static const char *shell = NULL;
+ if ((shell = getenv("SHELL")) == NULL)
+ shell = "/bin/sh";
- if ((shell = getenv("SHELL")) == NULL)
- shell = "/bin/sh";
+ execl(shell, shell, "-c", command, (char*) NULL);
+ return;
+ default:
+ close(fd[1]);
- execl(shell, shell, "-c", command, (char*) NULL);
- break;
- default:
- close(fd[1]);
+ dup2(fd[0], STDIN_FILENO);
+
+ break;
+ }
+ }
- dup2(fd[0], STDIN_FILENO);
- fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
+ fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
- child_io = malloc(sizeof(ev_io));
- ev_io_init(child_io, &child_io_cb, STDIN_FILENO, EV_READ);
- ev_io_start(main_loop, child_io);
+ child_io = malloc(sizeof(ev_io));
+ ev_io_init(child_io, &child_io_cb, STDIN_FILENO, EV_READ);
+ ev_io_start(main_loop, child_io);
- /* We must cleanup, if the child unexpectedly terminates */
- child_sig = malloc(sizeof(ev_io));
- ev_child_init(child_sig, &child_sig_cb, child_pid, 0);
- ev_child_start(main_loop, child_sig);
+ /* We must cleanup, if the child unexpectedly terminates */
+ child_sig = malloc(sizeof(ev_io));
+ ev_child_init(child_sig, &child_sig_cb, child_pid, 0);
+ ev_child_start(main_loop, child_sig);
- break;
- }
}
void kill_child() {
- kill(child_pid, SIGQUIT);
+ if (child_pid != 0) {
+ kill(child_pid, SIGQUIT);
+ }
cleanup();
}