#include <stdint.h>
-/*
- * Determines the JSON i3bar protocol version from the given buffer. In case
- * the buffer does not contain valid JSON, or no version field is found, this
- * function returns -1. The amount of bytes consumed by parsing the header is
- * returned in *consumed (if non-NULL).
- *
- * The return type is an int32_t to avoid machines with different sizes of
- * 'int' to allow different values here. It’s highly unlikely we ever exceed
- * even an int8_t, but still…
+/**
+ * Parse the JSON protocol header to determine protocol version and features.
+ * In case the buffer does not contain a valid header (invalid JSON, or no
+ * version field found), the 'correct' field of the returned header is set to
+ * false. The amount of bytes consumed by parsing the header is returned in
+ * *consumed (if non-NULL).
*
*/
void parse_json_header(i3bar_child *child, const unsigned char *buffer, int length, unsigned int *consumed);
* in the future, but for now, we just discard it. */
parse_json_header(&child, buffer, rec, &consumed);
if (child.version > 0) {
+ /* If hide-on-modifier is set, we start of by sending the
+ * child a SIGSTOP, because the bars aren't mapped at start */
+ if (config.hide_on_modifier) {
+ stop_child();
+ }
read_json_input(buffer + consumed, rec - consumed);
} else {
/* In case of plaintext, we just add a single block and change its
dup2(fd[0], STDIN_FILENO);
- /* If hide-on-modifier is set, we start of by sending the
- * child a SIGSTOP, because the bars aren't mapped at start */
- if (config.hide_on_modifier) {
- stop_child();
- }
-
break;
}
}
*/
void kill_child_at_exit(void) {
if (child.pid > 0) {
- kill(child.pid, SIGCONT);
+ if (child.cont_signal > 0 && child.stopped)
+ kill(child.pid, child.cont_signal);
kill(child.pid, SIGTERM);
}
}
*/
void kill_child(void) {
if (child.pid > 0) {
- kill(child.pid, SIGCONT);
+ if (child.cont_signal > 0 && child.stopped)
+ kill(child.pid, child.cont_signal);
kill(child.pid, SIGTERM);
int status;
waitpid(child.pid, &status, 0);
*
*/
void stop_child(void) {
- if (child.pid > 0) {
- kill(child.pid, SIGSTOP);
+ if (child.stop_signal > 0 && !child.stopped) {
+ child.stopped = true;
+ kill(child.pid, child.stop_signal);
}
}
*
*/
void cont_child(void) {
- if (child.pid > 0) {
- kill(child.pid, SIGCONT);
+ if (child.cont_signal > 0 && child.stopped) {
+ child.stopped = false;
+ kill(child.pid, child.cont_signal);
}
}
static enum {
KEY_VERSION,
+ KEY_STOP_SIGNAL,
+ KEY_CONT_SIGNAL,
NO_KEY
} current_key;
case KEY_VERSION:
child->version = val;
break;
+ case KEY_STOP_SIGNAL:
+ child->stop_signal = val;
+ break;
+ case KEY_CONT_SIGNAL:
+ child->cont_signal = val;
+ break;
default:
break;
}
#endif
if (CHECK_KEY("version")) {
current_key = KEY_VERSION;
+ } else if (CHECK_KEY("stop_signal")) {
+ current_key = KEY_STOP_SIGNAL;
+ } else if (CHECK_KEY("cont_signal")) {
+ current_key = KEY_CONT_SIGNAL;
}
return 1;
}
static void child_init(i3bar_child *child) {
child->version = 0;
+ child->stop_signal = SIGSTOP;
+ child->cont_signal = SIGCONT;
}
/*