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
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
);
20 K8T_DATA(tt
)->exitcode
= WEXITSTATUS(status
);
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
)));
30 K8T_DATA(tt
)->exitmsg
= SPrintf("Process %u died due to unknown reason!", (unsigned)pid
);
41 static int summonChildSaviour (void) {
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
);