5 #include "trinity.h" // __unused__
6 #include "params.h" // debug
15 static void ctrlc_handler(__unused__
int sig
)
17 shm
->exit_reason
= EXIT_SIGINT
;
20 static void sighandler(int sig
)
28 slot
= find_pid_slot(getpid());
29 if (slot
== PIDSLOT_NOT_FOUND
)
30 _exit(EXIT_SUCCESS
); /* Hell knows what happened, just bail. */
32 /* Check if we're blocking because we're stuck on an fd. */
33 if (check_if_fd(slot
) == TRUE
) {
35 /* avoid doing it again from other threads. */
38 /* TODO: Somehow mark the fd in the parent not to be used again too. */
41 /* Re-arm the alarm. */
44 /* TODO: If we get back here after the 10s alarm, we should exit instead of longjmp */
46 /* Jump back, maybe we'll make progress. */
47 (void)signal(sig
, sighandler
);
48 siglongjmp(ret_jump
, 1);
56 void mask_signals_child(void)
62 for (i
= 1; i
< 512; i
++) {
63 (void)sigfillset(&ss
);
64 sa
.sa_flags
= SA_RESTART
;
65 sa
.sa_handler
= sighandler
;
67 (void)sigaction(i
, &sa
, NULL
);
69 /* we want default behaviour for child process signals */
70 (void)signal(SIGCHLD
, SIG_DFL
);
72 /* ignore signals we don't care about */
73 (void)signal(SIGFPE
, SIG_IGN
);
74 (void)signal(SIGXCPU
, SIG_IGN
);
75 (void)signal(SIGTSTP
, SIG_IGN
);
76 (void)signal(SIGWINCH
, SIG_IGN
);
77 (void)signal(SIGIO
, SIG_IGN
);
78 (void)signal(SIGPIPE
, SIG_IGN
);
80 /* Ignore the RT signals. */
81 for (i
= SIGRTMIN
; i
<= SIGRTMAX
; i
++)
82 (void)signal(i
, SIG_IGN
);
84 /* If we are in debug mode, we want segfaults and core dumps */
86 (void)signal(SIGABRT
, SIG_DFL
);
87 (void)signal(SIGSEGV
, SIG_DFL
);
91 (void)signal(SIGINT
, ctrlc_handler
);
95 void setup_main_signals(void)
97 /* we want default behaviour for child process signals */
98 (void)signal(SIGFPE
, SIG_DFL
);
99 (void)signal(SIGCHLD
, SIG_DFL
);
101 (void)signal(SIGINT
, ctrlc_handler
);