removed unused code
[k8sterm.git] / src / childkiller.c
blobb42bca84c5f89c2af4f800ef455759742bc8a9d1
1 //FIXME: is it safe that signal interrupted main program in arbitrary point?
2 static void sigChildKiller (int sig, siginfo_t *siginfo, void *context) {
3 // here we have `siginfo->si_pid`, `siginfo->si_uid`, and `siginfo->si_status` set
4 //
5 if (siginfo->si_code == CLD_EXITED || siginfo->si_code == CLD_KILLED || siginfo->si_code == CLD_DUMPED) {
6 for (int f = 0; f < term_count; ++f) {
7 if (K8T_DATA(term_array[f])->pid == siginfo->si_pid) {
8 // this terminal should die
9 K8Term *tt = term_array[f];
11 K8T_DATA(tt)->pid = 0;
13 if (siginfo->si_code == CLD_EXITED) {
14 tt->dead = 1;
15 K8T_DATA(tt)->exitcode = siginfo->si_status;
16 } else {
17 tt->dead = 0; // we have no child, but we are not dead yet
18 K8T_DATA(tt)->exitcode = 127;
19 K8T_DATA(tt)->waitkeypress = 1;
21 if (K8T_DATA(tt)->exitmsg != NULL) free(K8T_DATA(tt)->exitmsg);
22 K8T_DATA(tt)->exitmsg = SPrintf("Process %d %s!", siginfo->si_pid,
23 (siginfo->si_code == CLD_KILLED ? "was killed" :
24 siginfo->si_code == CLD_DUMPED ? "suicides" :
25 "dies"));
28 updateTabBar = 1;
29 break;
36 static int summonChildKiller (void) {
37 struct sigaction act;
39 memset(&act, 0, sizeof(act));
40 act.sa_sigaction = &sigChildKiller;
41 act.sa_flags = SA_NOCLDSTOP|SA_NOCLDWAIT|SA_SIGINFO;
43 if (sigaction(SIGCHLD, &act, NULL) < 0) return -1;
45 return 0;