switched to `XDrawImageString16()` -- this should solve all rendering problems, once...
[k8sterm.git] / src / childkiller.c
blob4cbeacb4098e47c9fd4c488b3770a162ecca6b8d
1 #include <sys/signalfd.h>
4 static void processDeadChildren (int sigfd) {
5 struct signalfd_siginfo si;
6 while (read(sigfd, &si, sizeof(si)) > 0) {} // ignore errors here
7 for (;;) {
8 int status;
9 pid_t pid = waitpid(-1, &status, WNOHANG);
10 if (pid <= 0) break; // no more dead children
11 // find terminal with this pid
12 for (int f = 0; f < term_count; ++f) {
13 if (K8T_DATA(term_array[f])->pid == pid) {
14 // this terminal should die
15 K8Term *tt = term_array[f];
16 K8T_DATA(tt)->pid = 0;
17 if (WIFEXITED(status)) {
18 fprintf(stderr, "found dead children: %d\n", pid);
19 tt->dead = 1;
20 K8T_DATA(tt)->exitcode = WEXITSTATUS(status);
21 } else {
22 fprintf(stderr, "found murdered children: %d\n", pid);
23 tt->dead = 0; // we have no child, but we are not dead yet
24 K8T_DATA(tt)->exitcode = 127;
25 K8T_DATA(tt)->waitkeypress = 1;
26 if (K8T_DATA(tt)->exitmsg != NULL) free(K8T_DATA(tt)->exitmsg);
27 if (WIFSIGNALED(status)) {
28 K8T_DATA(tt)->exitmsg = SPrintf("Process %u died due to signal %u!", (unsigned)pid, (unsigned)(WTERMSIG(status)));
29 } else {
30 K8T_DATA(tt)->exitmsg = SPrintf("Process %u died due to unknown reason!", (unsigned)pid);
33 updateTabBar = 1;
34 break;
41 static int summonChildSaviour (void) {
42 sigset_t mask;
43 sigemptyset(&mask);
44 sigaddset(&mask, SIGCHLD);
45 sigprocmask(SIG_BLOCK, &mask, NULL); // we block the signal
46 //pthread_sigmask(SIG_BLOCK, &mask, NULL); // we block the signal
47 return signalfd(-1, &mask, SFD_NONBLOCK|SFD_CLOEXEC);