Go to the source code of this file.
static void * skn_signal_manager_handler_thread |
( |
void * |
l_thread_complete | ) |
|
|
static |
handler_thread()
Trap linux signals for the whole multi-threaded application.
Params: real_user_id – demos passing a ptr or value into thread context.
Returns/Affects: returns and/or set the atomic gint gi_exit_flag returns last signal
Definition at line 161 of file skn_signal_manager.c.
References gi_exit_flag, PLATFORM_ERROR, SD_NOTICE, SD_WARNING, SKN_RUN_MODE_RUN, SKN_RUN_MODE_STOP, and skn_signal_manager_process_signals().
Referenced by skn_signal_manager_startup().
163 siginfo_t signal_info;
167 long *threadC = (
long *)l_thread_complete;
173 sigfillset(&signal_set);
174 skn_logger(
SD_NOTICE,
"SignalManager: Startup Successful...");
179 sig = sigwaitinfo(&signal_set, &signal_info);
181 if (errno == EAGAIN) {
184 skn_logger(
SD_WARNING,
"SignalManager: sigwaitinfo() returned an error => {%s}", strerror(errno));
194 pthread_sigmask(SIG_UNBLOCK, &signal_set, NULL);
196 skn_logger(
SD_NOTICE,
"SignalManager: Thread Shutdown Complete.");
200 pthread_exit((
void *) (
long int) sig);
static int skn_signal_manager_process_signals(siginfo_t *signal_info)
sig_atomic_t gi_exit_flag
static int skn_signal_manager_process_signals |
( |
siginfo_t * |
signal_info | ) |
|
|
static |
Definition at line 28 of file skn_signal_manager.c.
References gi_exit_flag, and SD_NOTICE.
Referenced by skn_signal_manager_handler_thread().
31 char *pch =
"<unknown>";
33 assert(signal_info != NULL);
35 sig = signal_info->si_signo;
43 skn_logger(
SD_NOTICE,
"%s received: Requesting IP Address Info reload => [pid=%d, uid=%d]", strsignal(sig), signal_info->si_pid,
47 switch (signal_info->si_code) {
49 pch =
"kill(2) or raise(3)";
52 pch =
"Sent by the kernel.";
58 pch =
"POSIX timer expired";
61 pch =
"POSIX message queue state changed";
64 pch =
"AIO completed";
70 pch =
"tkill(2) or tgkill(2)";
76 skn_logger(
SD_NOTICE,
"%s received from => %s ?[pid=%d, uid=%d] signaling application shutdown.", strsignal(sig), pch, signal_info->si_pid, signal_info->si_uid);
80 switch (signal_info->si_code) {
82 pch =
"child has exited";
85 pch =
"child was killed";
88 pch =
"child terminated abnormally";
91 pch =
"traced child has trapped";
94 pch =
"child has stopped";
97 pch =
"stopped child has continued";
103 skn_logger(
SD_NOTICE,
"%s received for pid => %d, w/rc => %d for this reason => %s {Ignored}", strsignal(sig), signal_info->si_pid,
104 signal_info->si_status, pch);
112 switch (signal_info->si_code) {
114 pch =
"kill(2) or raise(3)";
117 pch =
"Sent by the kernel.";
123 pch =
"POSIX timer expired";
126 pch =
"POSIX message queue state changed";
129 pch =
"AIO completed";
132 pch =
"queued SIGIO";
135 pch =
"tkill(2) or tgkill(2)";
141 skn_logger(
SD_NOTICE,
"%s received from => %s ?[pid=%d, uid=%d]{Exiting}", strsignal(sig), pch, signal_info->si_pid, signal_info->si_uid);
sig_atomic_t gi_exit_flag
int skn_signal_manager_shutdown |
( |
pthread_t |
sig_thread, |
|
|
sigset_t * |
psignal_set, |
|
|
long * |
l_thread_complete |
|
) |
| |
Final step
- may send trapped signal to app, so requester knows it was honored
Definition at line 209 of file skn_signal_manager.c.
References gi_exit_flag, SD_NOTICE, SD_WARNING, and SKN_RUN_MODE_STOP.
Referenced by main().
211 int rc = EXIT_SUCCESS;
216 skn_logger(
SD_WARNING,
"shutdown caused by application!");
218 if (*l_thread_complete != 0) {
219 pthread_cancel(sig_thread);
222 skn_logger(
SD_WARNING,
"Collecting (cleanup) threads.");
223 pthread_join(sig_thread, &trc);
226 skn_logger(
SD_NOTICE,
"Collecting signal thread's return code.");
227 pthread_join(sig_thread, &trc);
228 skn_logger(
SD_NOTICE,
"Signal thread was ended by a %d:%s signal.",
gi_exit_flag, strsignal((
int) (
long int) trc));
230 pthread_sigmask(SIG_UNBLOCK, psignal_set, NULL);
sig_atomic_t gi_exit_flag
int skn_signal_manager_startup |
( |
pthread_t * |
psig_thread, |
|
|
sigset_t * |
psignal_set, |
|
|
long * |
l_thread_complete |
|
) |
| |
Initialize signal manager
Definition at line 238 of file skn_signal_manager.c.
References PLATFORM_ERROR, SD_ERR, and skn_signal_manager_handler_thread().
Referenced by main().
241 sigfillset(psignal_set);
242 pthread_sigmask(SIG_BLOCK, psignal_set, NULL);
246 skn_logger(
SD_ERR,
"Create signal thread failed: %d:%s", errno, strerror(errno));
247 pthread_sigmask(SIG_UNBLOCK, psignal_set, NULL);
248 i_thread_rc = EXIT_FAILURE;
static void * skn_signal_manager_handler_thread(void *l_thread_complete)