commit da1b0b94b6360e31de9124dd8d121979a0865af4
parent abae1b4c0e7c365162325f2f0f67ebf99e3fcf4b
Author: Robert Russell <robertrussell.72001@gmail.com>
Date: Sat, 3 Sep 2022 22:36:11 -0700
Reap zombies
Diffstat:
1 file changed, 10 insertions(+), 0 deletions(-)
diff --git a/xkbdw.c b/xkbdw.c
@@ -1,8 +1,10 @@
#include <errno.h>
#include <fcntl.h>
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/wait.h>
#include <unistd.h>
#include <rcx/all.h>
@@ -23,6 +25,11 @@ typedef struct {
void
+sigchld(int sig) {
+ while (waitpid(-1, 0, WNOHANG) > 0);
+}
+
+void
spawn(char **argv) {
switch (fork()) {
case 0: /* child */
@@ -62,6 +69,9 @@ main(int argc, char **argv) {
fprintf(stderr, "usage: %s PROG [ARGS...]\n", argv[0]);
exit(1);
}
+
+ if (sigaction(SIGCHLD, &(struct sigaction){.sa_handler = sigchld}, 0) < 0)
+ r_fatalf("sigaction: %s", strerror(errno));
xcb_connection_t *conn = xinit();
fcntl(xcb_get_file_descriptor(conn), F_SETFD, FD_CLOEXEC);