2 * Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
3 * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License version 2.1
7 * as published by the Free Software Foundation
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <sys/reboot.h>
16 #include <sys/types.h>
24 static void do_reboot(void)
35 static void signal_shutdown(int signal
, siginfo_t
*siginfo
, void *data
)
55 DEBUG(1, "Triggering %s\n", msg
);
57 procd_shutdown(event
);
60 struct sigaction sa_shutdown
= {
61 .sa_sigaction
= signal_shutdown
,
62 .sa_flags
= SA_SIGINFO
65 static void signal_crash(int signal
, siginfo_t
*siginfo
, void *data
)
67 ERROR("Rebooting as procd has crashed\n");
71 struct sigaction sa_crash
= {
72 .sa_sigaction
= signal_crash
,
73 .sa_flags
= SA_SIGINFO
76 static void signal_dummy(int signal
, siginfo_t
*siginfo
, void *data
)
78 ERROR("Got unexpected signal %d\n", signal
);
81 struct sigaction sa_dummy
= {
82 .sa_sigaction
= signal_dummy
,
83 .sa_flags
= SA_SIGINFO
86 void procd_signal(void)
88 signal(SIGPIPE
, SIG_IGN
);
91 sigaction(SIGTERM
, &sa_shutdown
, NULL
);
92 sigaction(SIGUSR1
, &sa_shutdown
, NULL
);
93 sigaction(SIGUSR2
, &sa_shutdown
, NULL
);
94 sigaction(SIGSEGV
, &sa_crash
, NULL
);
95 sigaction(SIGBUS
, &sa_crash
, NULL
);
96 sigaction(SIGHUP
, &sa_dummy
, NULL
);
97 sigaction(SIGKILL
, &sa_dummy
, NULL
);
98 sigaction(SIGSTOP
, &sa_dummy
, NULL
);
101 void procd_signal_preinit(void)
104 sigaction(SIGTERM
, &sa_shutdown
, NULL
);
105 sigaction(SIGUSR1
, &sa_shutdown
, NULL
);
106 sigaction(SIGUSR2
, &sa_shutdown
, NULL
);