#include #include #include #include #include #include #include #include void handle_signal(int s) { static sig_atomic_t dead = 0; if(!dead) { pid_t pgid = getpgid(0); dead = 1; killpg(pgid, s); } } int main(int argc, char **argv) { setsid(); struct sigaction act = { 0 }; act.sa_handler = handle_signal; sigaction(SIGHUP, &act, NULL); sigaction(SIGTERM, &act, NULL); sigaction(SIGINT, &act, NULL); if(argc == 2 && fork() == 0) { char *cmd[] = {"/bin/bash", "-c", argv[1], NULL}; execvp(cmd[0], cmd); } xcb_connection_t *c = xcb_connect(NULL, NULL); if(xcb_connection_has_error(c)) return 1; int xfd = xcb_get_file_descriptor(c); fd_set dsc; bool running = true; while(running) { FD_ZERO(&dsc); FD_SET(xfd, &dsc); int rc = select(xfd + 1, &dsc, NULL, NULL, NULL); if((rc == -1 && errno == EINTR)) running = false; else if(rc > 0) { xcb_generic_event_t *e; while((e = xcb_poll_for_event(c))) { free(e); } } if(xcb_connection_has_error(c)) running = false; } xcb_disconnect(c); handle_signal(SIGTERM); return 0; }