xref: /unit/src/nxt_signal_handlers.c (revision 1488:6976d36be926)
1*1488St.nateldemoura@f5.com 
2*1488St.nateldemoura@f5.com /*
3*1488St.nateldemoura@f5.com  * Copyright (C) Igor Sysoev
4*1488St.nateldemoura@f5.com  * Copyright (C) NGINX, Inc.
5*1488St.nateldemoura@f5.com  */
6*1488St.nateldemoura@f5.com 
7*1488St.nateldemoura@f5.com #include <nxt_main.h>
8*1488St.nateldemoura@f5.com #include <nxt_runtime.h>
9*1488St.nateldemoura@f5.com #include <nxt_port.h>
10*1488St.nateldemoura@f5.com #include <nxt_main_process.h>
11*1488St.nateldemoura@f5.com #include <nxt_router.h>
12*1488St.nateldemoura@f5.com 
13*1488St.nateldemoura@f5.com 
14*1488St.nateldemoura@f5.com static void nxt_signal_handler(nxt_task_t *task, void *obj, void *data);
15*1488St.nateldemoura@f5.com static void nxt_signal_sigterm_handler(nxt_task_t *task, void *obj, void *data);
16*1488St.nateldemoura@f5.com static void nxt_signal_sigquit_handler(nxt_task_t *task, void *obj, void *data);
17*1488St.nateldemoura@f5.com 
18*1488St.nateldemoura@f5.com 
19*1488St.nateldemoura@f5.com const nxt_sig_event_t  nxt_process_signals[] = {
20*1488St.nateldemoura@f5.com     nxt_event_signal(SIGHUP,  nxt_signal_handler),
21*1488St.nateldemoura@f5.com     nxt_event_signal(SIGINT,  nxt_signal_sigterm_handler),
22*1488St.nateldemoura@f5.com     nxt_event_signal(SIGQUIT, nxt_signal_sigquit_handler),
23*1488St.nateldemoura@f5.com     nxt_event_signal(SIGTERM, nxt_signal_sigterm_handler),
24*1488St.nateldemoura@f5.com     nxt_event_signal(SIGCHLD, nxt_signal_handler),
25*1488St.nateldemoura@f5.com     nxt_event_signal(SIGUSR1, nxt_signal_handler),
26*1488St.nateldemoura@f5.com     nxt_event_signal(SIGUSR2, nxt_signal_handler),
27*1488St.nateldemoura@f5.com     nxt_event_signal_end,
28*1488St.nateldemoura@f5.com };
29*1488St.nateldemoura@f5.com 
30*1488St.nateldemoura@f5.com 
31*1488St.nateldemoura@f5.com static void
nxt_signal_handler(nxt_task_t * task,void * obj,void * data)32*1488St.nateldemoura@f5.com nxt_signal_handler(nxt_task_t *task, void *obj, void *data)
33*1488St.nateldemoura@f5.com {
34*1488St.nateldemoura@f5.com     nxt_trace(task, "signal signo:%d (%s) recevied, ignored",
35*1488St.nateldemoura@f5.com               (int) (uintptr_t) obj, data);
36*1488St.nateldemoura@f5.com }
37*1488St.nateldemoura@f5.com 
38*1488St.nateldemoura@f5.com 
39*1488St.nateldemoura@f5.com void
nxt_signal_quit_handler(nxt_task_t * task,nxt_port_recv_msg_t * msg)40*1488St.nateldemoura@f5.com nxt_signal_quit_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
41*1488St.nateldemoura@f5.com {
42*1488St.nateldemoura@f5.com     nxt_process_quit(task, 0);
43*1488St.nateldemoura@f5.com }
44*1488St.nateldemoura@f5.com 
45*1488St.nateldemoura@f5.com 
46*1488St.nateldemoura@f5.com static void
nxt_signal_sigterm_handler(nxt_task_t * task,void * obj,void * data)47*1488St.nateldemoura@f5.com nxt_signal_sigterm_handler(nxt_task_t *task, void *obj, void *data)
48*1488St.nateldemoura@f5.com {
49*1488St.nateldemoura@f5.com     nxt_debug(task, "sigterm handler signo:%d (%s)",
50*1488St.nateldemoura@f5.com               (int) (uintptr_t) obj, data);
51*1488St.nateldemoura@f5.com 
52*1488St.nateldemoura@f5.com     /* A fast exit. */
53*1488St.nateldemoura@f5.com 
54*1488St.nateldemoura@f5.com     nxt_runtime_quit(task, 0);
55*1488St.nateldemoura@f5.com }
56*1488St.nateldemoura@f5.com 
57*1488St.nateldemoura@f5.com 
58*1488St.nateldemoura@f5.com static void
nxt_signal_sigquit_handler(nxt_task_t * task,void * obj,void * data)59*1488St.nateldemoura@f5.com nxt_signal_sigquit_handler(nxt_task_t *task, void *obj, void *data)
60*1488St.nateldemoura@f5.com {
61*1488St.nateldemoura@f5.com     nxt_debug(task, "sigquit handler signo:%d (%s)",
62*1488St.nateldemoura@f5.com               (int) (uintptr_t) obj, data);
63*1488St.nateldemoura@f5.com 
64*1488St.nateldemoura@f5.com     /* A graceful exit. */
65*1488St.nateldemoura@f5.com 
66*1488St.nateldemoura@f5.com     nxt_process_quit(task, 0);
67*1488St.nateldemoura@f5.com }
68