#include <yajl/yajl_parse.h>
#include <yajl/yajl_version.h>
#include <yajl/yajl_gen.h>
+#include <paths.h>
#include "common.h"
struct statusline_head statusline_head = TAILQ_HEAD_INITIALIZER(statusline_head);
char *statusline_buffer = NULL;
+int child_stdin;
+
/*
* Stop and free() the stdin- and sigchild-watchers
*
void child_write_output(void) {
if (child.click_events) {
const unsigned char *output;
+#if YAJL_MAJOR < 2
+ unsigned int size;
+#else
size_t size;
+#endif
yajl_gen_get_buf(gen, &output, &size);
- fwrite(output, 1, size, stdout);
- fwrite("\n", 1, 1, stdout);
- fflush(stdout);
+ write(child_stdin, output, size);
+ write(child_stdin, "\n", 1);
yajl_gen_clear(gen);
}
}
yajl_parser_config parse_conf = { 0, 0 };
parser = yajl_alloc(&callbacks, &parse_conf, NULL, (void*)&parser_context);
+
+ gen = yajl_gen_alloc(NULL, NULL);
#else
parser = yajl_alloc(&callbacks, NULL, &parser_context);
-#endif
gen = yajl_gen_alloc(NULL);
+#endif
if (command != NULL) {
int pipe_in[2]; /* pipe we read from */
dup2(pipe_in[1], STDOUT_FILENO);
dup2(pipe_out[0], STDIN_FILENO);
- static const char *shell = NULL;
-
- if ((shell = getenv("SHELL")) == NULL)
- shell = "/bin/sh";
-
- execl(shell, shell, "-c", command, (char*) NULL);
+ setpgid(child.pid, 0);
+ execl(_PATH_BSHELL, _PATH_BSHELL, "-c", command, (char*) NULL);
return;
default:
/* Parent-process. Reroute streams */
close(pipe_out[0]);
dup2(pipe_in[0], STDIN_FILENO);
- dup2(pipe_out[1], STDOUT_FILENO);
+ child_stdin = pipe_out[1];
break;
}
void kill_child_at_exit(void) {
if (child.pid > 0) {
if (child.cont_signal > 0 && child.stopped)
- kill(child.pid, child.cont_signal);
- kill(child.pid, SIGTERM);
+ killpg(child.pid, child.cont_signal);
+ killpg(child.pid, SIGTERM);
}
}
void kill_child(void) {
if (child.pid > 0) {
if (child.cont_signal > 0 && child.stopped)
- kill(child.pid, child.cont_signal);
- kill(child.pid, SIGTERM);
+ killpg(child.pid, child.cont_signal);
+ killpg(child.pid, SIGTERM);
int status;
waitpid(child.pid, &status, 0);
cleanup();
void stop_child(void) {
if (child.stop_signal > 0 && !child.stopped) {
child.stopped = true;
- kill(child.pid, child.stop_signal);
+ killpg(child.pid, child.stop_signal);
}
}
void cont_child(void) {
if (child.cont_signal > 0 && child.stopped) {
child.stopped = false;
- kill(child.pid, child.cont_signal);
+ killpg(child.pid, child.cont_signal);
}
}