Added signal handling

This commit is contained in:
buffet 2018-09-30 20:06:21 +02:00
parent 764371e47d
commit cbe0f0cbe6

View file

@ -29,6 +29,7 @@ main(int argc, char *argv[])
@{parse arguments}
@{open ipc connection}
@{setup signal handlers}
}
---
@ -215,3 +216,41 @@ if (sock_path) {
strncpy(sock_addr.sun_path, "/tmp/wmaffle.sock", sizeof(sock_addr.sun_path));
}
---
@s Setup signal handlers
We don't want out window manager to just exit on us, so we need to setup signal handler.
Here is it:
--- function definitions +=
static void
sig_handler(int sig)
{
if (sig == SIGCHLD) {
signal(sig, sig_handler);
while (waitpid(-1, 0, WNOHANG) > 0) {
// EMPTY
}
} else if (sig == SIGINT || sig == SIGHUP || sig == SIGTERM) {
// TODO: Set about to quit to 1
}
}
---
Now we only need to register it.
--- setup signal handlers
signal(SIGINT, sig_handler);
signal(SIGHUP, sig_handler);
signal(SIGTERM, sig_handler);
signal(SIGCHLD, sig_handler);
signal(SIGPIPE, SIG_IGN);
---
Which of course requires this.
--- posix headers +=
#include <signal.h>
#include <sys/wait.h>
---