blob: c09821f0228eeb4d29fefba02fb16958bfe68ad1 [file] [log] [blame]
Scott James Remnant50748842006-05-16 21:02:31 +01001/* upstart
2 *
Scott James Remnant75123022009-05-22 13:27:56 +02003 * Copyright © 2009 Canonical Ltd.
Scott James Remnant7d5b2ea2009-05-22 15:20:12 +02004 * Author: Scott James Remnant <scott@netsplit.com>.
Scott James Remnant50748842006-05-16 21:02:31 +01005 *
Scott James Remnant75123022009-05-22 13:27:56 +02006 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3, as
8 * published by the Free Software Foundation.
Scott James Remnant50748842006-05-16 21:02:31 +01009 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
Scott James Remnant75123022009-05-22 13:27:56 +020016 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Scott James Remnant50748842006-05-16 21:02:31 +010017 */
18
19#ifdef HAVE_CONFIG_H
20# include <config.h>
21#endif /* HAVE_CONFIG_H */
22
23
Scott James Remnantf43bdf32006-08-27 18:20:29 +010024#include <sys/types.h>
Scott James Remnantea806b72006-10-18 15:01:00 +010025#include <sys/time.h>
Scott James Remnantf43bdf32006-08-27 18:20:29 +010026#include <sys/wait.h>
27#include <sys/ioctl.h>
28#include <sys/reboot.h>
29#include <sys/resource.h>
30
Scott James Remnant3401ab72006-09-01 02:14:47 +010031#include <errno.h>
32#include <stdio.h>
Scott James Remnantf43bdf32006-08-27 18:20:29 +010033#include <signal.h>
Scott James Remnant94d00982006-08-25 15:38:22 +020034#include <stdlib.h>
Scott James Remnant3401ab72006-09-01 02:14:47 +010035#include <string.h>
Scott James Remnant12a330f2006-08-24 02:19:09 +020036#include <syslog.h>
Scott James Remnant027dd7b2006-08-21 09:01:25 +020037#include <unistd.h>
38
Scott James Remnant097b2a92006-09-01 19:30:37 +010039#include <linux/kd.h>
40
Scott James Remnant77e8db32006-08-21 08:47:50 +020041#include <nih/macros.h>
42#include <nih/alloc.h>
43#include <nih/list.h>
44#include <nih/timer.h>
45#include <nih/signal.h>
46#include <nih/child.h>
Scott James Remnant3401ab72006-09-01 02:14:47 +010047#include <nih/option.h>
Scott James Remnant77e8db32006-08-21 08:47:50 +020048#include <nih/main.h>
Scott James Remnant28fcc922006-09-01 04:15:57 +010049#include <nih/error.h>
Scott James Remnant77e8db32006-08-21 08:47:50 +020050#include <nih/logging.h>
51
Scott James Remnantf2f69d02008-04-29 23:38:23 +010052#include "paths.h"
Scott James Remnant5d82d902008-04-30 00:03:29 +010053#include "events.h"
Scott James Remnantf2f69d02008-04-29 23:38:23 +010054#include "system.h"
Scott James Remnant63fd5c72008-04-30 21:34:31 +010055#include "job_process.h"
Scott James Remnant77e8db32006-08-21 08:47:50 +020056#include "event.h"
Scott James Remnant54b2a952007-06-10 22:15:24 +010057#include "conf.h"
Scott James Remnantf8491442008-04-18 13:19:24 +010058#include "control.h"
Scott James Remnant50748842006-05-16 21:02:31 +010059
60
Scott James Remnantf43bdf32006-08-27 18:20:29 +010061/* Prototypes for static functions */
Scott James Remnant9f62a8e2008-01-15 19:22:36 +000062#ifndef DEBUG
Scott James Remnant16a286f2007-01-10 15:38:33 +000063static void crash_handler (int signum);
Scott James Remnant3401ab72006-09-01 02:14:47 +010064static void cad_handler (void *data, NihSignal *signal);
65static void kbd_handler (void *data, NihSignal *signal);
Scott James Remnant2c950692007-02-25 09:13:38 +000066static void pwr_handler (void *data, NihSignal *signal);
Scott James Remnant7ba2cf62007-06-10 22:20:38 +010067static void hup_handler (void *data, NihSignal *signal);
Scott James Remnantf3ef5112008-06-05 01:26:10 +010068#endif /* DEBUG */
Scott James Remnant3401ab72006-09-01 02:14:47 +010069
Scott James Remnant1db88042006-09-01 03:14:19 +010070
Scott James Remnant3401ab72006-09-01 02:14:47 +010071/**
Scott James Remnant06abbec2007-03-09 13:02:38 +000072 * argv0:
73 *
74 * Path to program executed, used for re-executing the init binary from the
75 * same location we were executed from.
76 **/
77static const char *argv0 = NULL;
78
79/**
Scott James Remnant1db88042006-09-01 03:14:19 +010080 * restart:
Scott James Remnant3401ab72006-09-01 02:14:47 +010081 *
Scott James Remnant8b227402006-10-11 17:55:27 +010082 * This is set to TRUE if we're being re-exec'd by an existing init
Scott James Remnant1db88042006-09-01 03:14:19 +010083 * process.
Scott James Remnant3401ab72006-09-01 02:14:47 +010084 **/
Scott James Remnant1db88042006-09-01 03:14:19 +010085static int restart = FALSE;
Scott James Remnant3401ab72006-09-01 02:14:47 +010086
87
88/**
89 * options:
90 *
91 * Command-line options we accept.
92 **/
93static NihOption options[] = {
Scott James Remnant1db88042006-09-01 03:14:19 +010094 { 0, "restart", NULL, NULL, NULL, &restart, NULL },
Scott James Remnant3401ab72006-09-01 02:14:47 +010095
96 /* Ignore invalid options */
97 { '-', "--", NULL, NULL, NULL, NULL, NULL },
98
99 NIH_OPTION_LAST
100};
Scott James Remnantff0d26a2006-08-31 20:49:43 +0100101
Scott James Remnantf43bdf32006-08-27 18:20:29 +0100102
Scott James Remnant50748842006-05-16 21:02:31 +0100103int
104main (int argc,
105 char *argv[])
106{
Scott James Remnant3401ab72006-09-01 02:14:47 +0100107 char **args;
Scott James Remnant2e204b72007-02-03 23:15:28 +0000108 int ret;
Scott James Remnant50748842006-05-16 21:02:31 +0100109
Scott James Remnant06abbec2007-03-09 13:02:38 +0000110 argv0 = argv[0];
111 nih_main_init (argv0);
Scott James Remnant77e8db32006-08-21 08:47:50 +0200112
Scott James Remnant930e25a2006-10-13 12:28:05 +0100113 nih_option_set_synopsis (_("Process management daemon."));
Scott James Remnant462734c2006-10-13 13:36:00 +0100114 nih_option_set_help (
115 _("This daemon is normally executed by the kernel and given "
116 "process id 1 to denote its special status. When executed "
117 "by a user process, it will actually run /sbin/telinit."));
Scott James Remnanta6ed7eb2006-10-13 12:14:45 +0100118
Scott James Remnant3401ab72006-09-01 02:14:47 +0100119 args = nih_option_parser (NULL, argc, argv, options, FALSE);
120 if (! args)
121 exit (1);
Scott James Remnant12a330f2006-08-24 02:19:09 +0200122
Scott James Remnant9f62a8e2008-01-15 19:22:36 +0000123#ifndef DEBUG
Scott James Remnanta17917d2006-09-07 00:18:28 +0100124 /* Check we're root */
125 if (getuid ()) {
Scott James Remnant31421b72007-03-08 23:53:05 +0000126 nih_fatal (_("Need to be root"));
Scott James Remnanta17917d2006-09-07 00:18:28 +0100127 exit (1);
128 }
129
130 /* Check we're process #1 */
131 if (getpid () > 1) {
Scott James Remnante0d0dd12006-09-14 10:51:05 +0100132 execv (TELINIT, argv);
Scott James Remnanta17917d2006-09-07 00:18:28 +0100133 /* Ignore failure, probably just that telinit doesn't exist */
134
Scott James Remnant31421b72007-03-08 23:53:05 +0000135 nih_fatal (_("Not being executed as init"));
Scott James Remnanta17917d2006-09-07 00:18:28 +0100136 exit (1);
137 }
138
Scott James Remnant78626fb2007-01-10 16:48:10 +0000139 /* Clear our arguments from the command-line, so that we show up in
140 * ps or top output as /sbin/init, with no extra flags.
141 *
142 * This is a very Linux-specific trick; by deleting the NULL
143 * terminator at the end of the last argument, we fool the kernel
144 * into believing we used a setproctitle()-a-like to extend the
145 * argument space into the environment space, and thus make it use
146 * strlen() instead of its own assumed length. In fact, we've done
147 * the exact opposite, and shrunk the command line length to just that
148 * of whatever is in argv[0].
149 *
150 * If we don't do this, and just write \0 over the rest of argv, for
151 * example; the command-line length still includes those \0s, and ps
152 * will show whitespace in their place.
153 */
154 if (argc > 1) {
Scott James Remnant505f9282007-01-10 18:44:38 +0000155 char *arg_end;
Scott James Remnant78626fb2007-01-10 16:48:10 +0000156
Scott James Remnant505f9282007-01-10 18:44:38 +0000157 arg_end = argv[argc-1] + strlen (argv[argc-1]);
158 *arg_end = ' ';
Scott James Remnant78626fb2007-01-10 16:48:10 +0000159 }
Scott James Remnant7f4db422007-01-09 20:51:08 +0000160
Scott James Remnantfa733382008-01-15 15:33:27 +0000161
162 /* Become the leader of a new session and process group, shedding
163 * any controlling tty (which we shouldn't have had anyway - but
164 * you never know what initramfs did).
Scott James Remnant2e204b72007-02-03 23:15:28 +0000165 */
166 setsid ();
Scott James Remnanta17917d2006-09-07 00:18:28 +0100167
Scott James Remnantfa733382008-01-15 15:33:27 +0000168 /* Set the standard file descriptors to the ordinary console device,
169 * resetting it to sane defaults unless we're inheriting from another
170 * init process which we know left it in a sane state.
Scott James Remnant77e8db32006-08-21 08:47:50 +0200171 */
Scott James Remnantf2f69d02008-04-29 23:38:23 +0100172 if (system_setup_console (CONSOLE_OUTPUT, (! restart)) < 0)
Scott James Remnant5d702952007-01-05 17:21:34 +0000173 nih_free (nih_error_get ());
Scott James Remnant77e8db32006-08-21 08:47:50 +0200174
Scott James Remnant2e204b72007-02-03 23:15:28 +0000175 /* Set the PATH environment variable */
176 setenv ("PATH", PATH, TRUE);
177
Scott James Remnantfa733382008-01-15 15:33:27 +0000178 /* Switch to the root directory in case we were started from some
179 * strange place, or worse, some directory in the initramfs that's
180 * going to go away soon.
181 */
Scott James Remnant5635e072008-05-06 23:22:58 +0100182 if (chdir ("/"))
183 nih_warn ("%s: %s", _("Unable to set root directory"),
184 strerror (errno));
Scott James Remnant9f62a8e2008-01-15 19:22:36 +0000185#else /* DEBUG */
186 nih_log_set_priority (NIH_LOG_DEBUG);
187#endif /* DEBUG */
Scott James Remnantfa733382008-01-15 15:33:27 +0000188
Scott James Remnant2e204b72007-02-03 23:15:28 +0000189
Scott James Remnantf43bdf32006-08-27 18:20:29 +0100190 /* Reset the signal state and install the signal handler for those
191 * signals we actually want to catch; this also sets those that
192 * can be sent to us, because we're special
193 */
Scott James Remnant4b56d6f2008-04-12 12:23:15 +0100194 if (! restart)
Scott James Remnant2e204b72007-02-03 23:15:28 +0000195 nih_signal_reset ();
196
Scott James Remnant2c0bd592008-04-12 12:31:49 +0100197#ifndef DEBUG
Scott James Remnant9f62a8e2008-01-15 19:22:36 +0000198 /* Catch fatal errors immediately rather than waiting for a new
Scott James Remnantfa733382008-01-15 15:33:27 +0000199 * iteration through the main loop.
200 */
201 nih_signal_set_handler (SIGSEGV, crash_handler);
202 nih_signal_set_handler (SIGABRT, crash_handler);
Scott James Remnant9f62a8e2008-01-15 19:22:36 +0000203#endif /* DEBUG */
Scott James Remnantfa733382008-01-15 15:33:27 +0000204
Scott James Remnant5c408432007-11-07 21:42:25 -0500205 /* Don't ignore SIGCHLD or SIGALRM, but don't respond to them
206 * directly; it's enough that they interrupt the main loop and
207 * get dealt with during it.
208 */
209 nih_signal_set_handler (SIGCHLD, nih_signal_handler);
210 nih_signal_set_handler (SIGALRM, nih_signal_handler);
Scott James Remnantf43bdf32006-08-27 18:20:29 +0100211
Scott James Remnant9f62a8e2008-01-15 19:22:36 +0000212#ifndef DEBUG
Scott James Remnantf43bdf32006-08-27 18:20:29 +0100213 /* Ask the kernel to send us SIGINT when control-alt-delete is
214 * pressed; generate an event with the same name.
215 */
216 reboot (RB_DISABLE_CAD);
Scott James Remnant5c408432007-11-07 21:42:25 -0500217 nih_signal_set_handler (SIGINT, nih_signal_handler);
Scott James Remnant5d702952007-01-05 17:21:34 +0000218 NIH_MUST (nih_signal_add_handler (NULL, SIGINT, cad_handler, NULL));
Scott James Remnantf43bdf32006-08-27 18:20:29 +0100219
220 /* Ask the kernel to send us SIGWINCH when alt-uparrow is pressed;
Scott James Remnant2c0bd592008-04-12 12:31:49 +0100221 * generate a keyboard-request event.
Scott James Remnantf43bdf32006-08-27 18:20:29 +0100222 */
Scott James Remnant5c408432007-11-07 21:42:25 -0500223 if (ioctl (0, KDSIGACCEPT, SIGWINCH) == 0) {
224 nih_signal_set_handler (SIGWINCH, nih_signal_handler);
Scott James Remnant5d702952007-01-05 17:21:34 +0000225 NIH_MUST (nih_signal_add_handler (NULL, SIGWINCH,
226 kbd_handler, NULL));
Scott James Remnant5c408432007-11-07 21:42:25 -0500227 }
Scott James Remnantf43bdf32006-08-27 18:20:29 +0100228
Scott James Remnant2c950692007-02-25 09:13:38 +0000229 /* powstatd sends us SIGPWR when it changes /etc/powerstatus */
Scott James Remnant5c408432007-11-07 21:42:25 -0500230 nih_signal_set_handler (SIGPWR, nih_signal_handler);
Scott James Remnant2c950692007-02-25 09:13:38 +0000231 NIH_MUST (nih_signal_add_handler (NULL, SIGPWR, pwr_handler, NULL));
232
Scott James Remnant7ba2cf62007-06-10 22:20:38 +0100233 /* SIGHUP instructs us to re-load our configuration */
Scott James Remnant5c408432007-11-07 21:42:25 -0500234 nih_signal_set_handler (SIGHUP, nih_signal_handler);
Scott James Remnant7ba2cf62007-06-10 22:20:38 +0100235 NIH_MUST (nih_signal_add_handler (NULL, SIGHUP, hup_handler, NULL));
Scott James Remnantf3ef5112008-06-05 01:26:10 +0100236#endif /* DEBUG */
Scott James Remnant1db88042006-09-01 03:14:19 +0100237
Scott James Remnantfa733382008-01-15 15:33:27 +0000238
Scott James Remnant0eade492007-11-15 05:48:07 +0000239 /* Watch children for events */
Scott James Remnant5ebc6c62007-12-06 16:01:13 +0000240 NIH_MUST (nih_child_add_watch (NULL, -1, NIH_CHILD_ALL,
Scott James Remnant63fd5c72008-04-30 21:34:31 +0100241 job_process_handler, NULL));
Scott James Remnantf43bdf32006-08-27 18:20:29 +0100242
Scott James Remnant5c408432007-11-07 21:42:25 -0500243 /* Process the event queue each time through the main loop */
Scott James Remnanta39da0f2007-02-07 13:52:42 +0000244 NIH_MUST (nih_main_loop_add_func (NULL, (NihMainLoopCb)event_poll,
Scott James Remnant5d702952007-01-05 17:21:34 +0000245 NULL));
Scott James Remnantf43bdf32006-08-27 18:20:29 +0100246
Scott James Remnant94d00982006-08-25 15:38:22 +0200247
Scott James Remnant54b2a952007-06-10 22:15:24 +0100248 /* Read configuration */
Scott James Remnant854fda22009-06-23 01:21:55 +0100249 NIH_MUST (conf_source_new (NULL, CONFFILE, CONF_FILE));
250 NIH_MUST (conf_source_new (NULL, CONFDIR, CONF_JOB_DIR));
Scott James Remnant54b2a952007-06-10 22:15:24 +0100251
252 conf_reload ();
Scott James Remnantd03c53c2007-03-13 19:13:19 +0000253
Scott James Remnant1ba7f7a2008-05-07 23:52:11 +0100254 /* Create a listening server for private connections. */
255 while (control_server_open () < 0) {
256 NihError *err;
257
258 err = nih_error_get ();
259 if (err->number != ENOMEM) {
260 nih_warn ("%s: %s", _("Unable to listen for private connections"),
261 err->message);
262 nih_free (err);
263 break;
264 }
265 nih_free (err);
266 }
267
Scott James Remnantf8491442008-04-18 13:19:24 +0100268 /* Open connection to the system bus; we normally expect this to
269 * fail and will try again later - don't let ENOMEM stop us though.
270 */
271 while (control_bus_open () < 0) {
272 NihError *err;
273 int number;
274
275 err = nih_error_get ();
276 number = err->number;
277 nih_free (err);
278
279 if (number != ENOMEM)
280 break;
281 }
282
Scott James Remnant2c0bd592008-04-12 12:31:49 +0100283#ifndef DEBUG
Scott James Remnantfa733382008-01-15 15:33:27 +0000284 /* Now that the startup is complete, send all further logging output
285 * to syslog instead of to the console.
286 */
287 openlog (program_name, LOG_CONS, LOG_DAEMON);
288 nih_log_set_logger (nih_logger_syslog);
Scott James Remnant9f62a8e2008-01-15 19:22:36 +0000289#endif /* DEBUG */
Scott James Remnantfa733382008-01-15 15:33:27 +0000290
291
Scott James Remnant3401ab72006-09-01 02:14:47 +0100292 /* Generate and run the startup event or read the state from the
293 * init daemon that exec'd us
294 */
Scott James Remnant4b56d6f2008-04-12 12:23:15 +0100295 if (! restart) {
Scott James Remnantd0258e02008-06-06 02:09:38 +0100296 NIH_MUST (event_new (NULL, STARTUP_EVENT, NULL));
Scott James Remnant3401ab72006-09-01 02:14:47 +0100297 } else {
Scott James Remnant1db88042006-09-01 03:14:19 +0100298 sigset_t mask;
299
Scott James Remnant1db88042006-09-01 03:14:19 +0100300 /* We're ok to receive signals again */
301 sigemptyset (&mask);
302 sigprocmask (SIG_SETMASK, &mask, NULL);
Scott James Remnant3401ab72006-09-01 02:14:47 +0100303 }
304
Scott James Remnantfa733382008-01-15 15:33:27 +0000305 /* Run through the loop at least once to deal with signals that were
306 * delivered to the previous process while the mask was set or to
307 * process the startup event we emitted.
308 */
Scott James Remnanta39da0f2007-02-07 13:52:42 +0000309 nih_main_loop_interrupt ();
Scott James Remnant77e8db32006-08-21 08:47:50 +0200310 ret = nih_main_loop ();
311
312 return ret;
Scott James Remnant50748842006-05-16 21:02:31 +0100313}
Scott James Remnantf43bdf32006-08-27 18:20:29 +0100314
315
Scott James Remnant9f62a8e2008-01-15 19:22:36 +0000316#ifndef DEBUG
Scott James Remnantf43bdf32006-08-27 18:20:29 +0100317/**
Scott James Remnant16a286f2007-01-10 15:38:33 +0000318 * crash_handler:
Scott James Remnant8b227402006-10-11 17:55:27 +0100319 * @signum: signal number received.
Scott James Remnantf43bdf32006-08-27 18:20:29 +0100320 *
Scott James Remnant16a286f2007-01-10 15:38:33 +0000321 * Handle receiving the SEGV or ABRT signal, usually caused by one of
322 * our own mistakes. We deal with it by dumping core in a child process
Scott James Remnant4b56d6f2008-04-12 12:23:15 +0100323 * and then killing the parent.
Scott James Remnant16a286f2007-01-10 15:38:33 +0000324 *
Scott James Remnant4b56d6f2008-04-12 12:23:15 +0100325 * Sadly there's no real alternative to the ensuing kernel panic. Our
326 * state is likely in tatters, so we can't sigjmp() anywhere "safe" or
327 * re-exec since the system will be suddenly lobotomised. We definitely
328 * don't want to start a root shell or anything like that. Best thing is
329 * to just stop the whole thing and hope that bug report comes quickly.
Scott James Remnantf43bdf32006-08-27 18:20:29 +0100330 **/
331static void
Scott James Remnant16a286f2007-01-10 15:38:33 +0000332crash_handler (int signum)
Scott James Remnantf43bdf32006-08-27 18:20:29 +0100333{
Scott James Remnant4b56d6f2008-04-12 12:23:15 +0100334 pid_t pid;
Scott James Remnant06abbec2007-03-09 13:02:38 +0000335
336 nih_assert (argv0 != NULL);
Scott James Remnantf43bdf32006-08-27 18:20:29 +0100337
338 pid = fork ();
339 if (pid == 0) {
340 struct sigaction act;
341 struct rlimit limit;
342 sigset_t mask;
343
344 /* Mask out all signals */
345 sigfillset (&mask);
346 sigprocmask (SIG_SETMASK, &mask, NULL);
347
Scott James Remnant16a286f2007-01-10 15:38:33 +0000348 /* Set the handler to the default so core is dumped */
Scott James Remnantf43bdf32006-08-27 18:20:29 +0100349 act.sa_handler = SIG_DFL;
350 act.sa_flags = 0;
351 sigemptyset (&act.sa_mask);
Scott James Remnant16a286f2007-01-10 15:38:33 +0000352 sigaction (signum, &act, NULL);
Scott James Remnantf43bdf32006-08-27 18:20:29 +0100353
Scott James Remnantf43bdf32006-08-27 18:20:29 +0100354 /* Don't limit the core dump size */
355 limit.rlim_cur = RLIM_INFINITY;
356 limit.rlim_max = RLIM_INFINITY;
357 setrlimit (RLIMIT_CORE, &limit);
358
Scott James Remnantfa733382008-01-15 15:33:27 +0000359 /* Dump in the root directory */
Scott James Remnant5635e072008-05-06 23:22:58 +0100360 nih_warn ("%s: %s", _("Unable to set root directory"),
361 strerror (errno));
Scott James Remnantfa733382008-01-15 15:33:27 +0000362
Scott James Remnant16a286f2007-01-10 15:38:33 +0000363 /* Raise the signal again */
364 raise (signum);
Scott James Remnantf43bdf32006-08-27 18:20:29 +0100365
366 /* Unmask so that we receive it */
Scott James Remnant16a286f2007-01-10 15:38:33 +0000367 sigdelset (&mask, signum);
Scott James Remnantf43bdf32006-08-27 18:20:29 +0100368 sigprocmask (SIG_SETMASK, &mask, NULL);
369
370 /* Wait for death */
371 pause ();
372 exit (0);
373 } else if (pid > 0) {
374 /* Wait for the core to be generated */
375 waitpid (pid, NULL, 0);
376
Scott James Remnant31421b72007-03-08 23:53:05 +0000377 nih_fatal (_("Caught %s, core dumped"),
Scott James Remnantde443012007-01-10 18:45:40 +0000378 (signum == SIGSEGV
379 ? "segmentation fault" : "abort"));
Scott James Remnantf43bdf32006-08-27 18:20:29 +0100380 } else {
Scott James Remnant31421b72007-03-08 23:53:05 +0000381 nih_fatal (_("Caught %s, unable to dump core"),
Scott James Remnantde443012007-01-10 18:45:40 +0000382 (signum == SIGSEGV
383 ? "segmentation fault" : "abort"));
Scott James Remnantf43bdf32006-08-27 18:20:29 +0100384 }
Scott James Remnant502ea702007-03-05 20:47:18 +0000385
Scott James Remnant4b56d6f2008-04-12 12:23:15 +0100386 /* Goodbye, cruel world. */
387 exit (signum);
Scott James Remnantf43bdf32006-08-27 18:20:29 +0100388}
389
390/**
391 * cad_handler:
392 * @data: unused,
393 * @signal: signal that called this handler.
394 *
395 * Handle having recieved the SIGINT signal, sent to us when somebody
396 * presses Ctrl-Alt-Delete on the console. We just generate a
Scott James Remnantbb3cc3f2006-09-08 17:17:47 +0100397 * ctrlaltdel event.
Scott James Remnantf43bdf32006-08-27 18:20:29 +0100398 **/
399static void
400cad_handler (void *data,
401 NihSignal *signal)
402{
Scott James Remnantd0258e02008-06-06 02:09:38 +0100403 NIH_MUST (event_new (NULL, CTRLALTDEL_EVENT, NULL));
Scott James Remnantf43bdf32006-08-27 18:20:29 +0100404}
405
406/**
407 * kbd_handler:
408 * @data: unused,
409 * @signal: signal that called this handler.
410 *
411 * Handle having recieved the SIGWINCH signal, sent to us when somebody
412 * presses Alt-UpArrow on the console. We just generate a
413 * kbdrequest event.
414 **/
415static void
416kbd_handler (void *data,
417 NihSignal *signal)
418{
Scott James Remnantd0258e02008-06-06 02:09:38 +0100419 NIH_MUST (event_new (NULL, KBDREQUEST_EVENT, NULL));
Scott James Remnantf43bdf32006-08-27 18:20:29 +0100420}
Scott James Remnanteabb7802006-08-31 15:39:04 +0100421
422/**
Scott James Remnant2c950692007-02-25 09:13:38 +0000423 * pwr_handler:
424 * @data: unused,
425 * @signal: signal that called this handler.
426 *
427 * Handle having recieved the SIGPWR signal, sent to us when powstatd
428 * changes the /etc/powerstatus file. We just generate a
429 * power-status-changed event and jobs read the file.
430 **/
431static void
432pwr_handler (void *data,
433 NihSignal *signal)
434{
Scott James Remnantd0258e02008-06-06 02:09:38 +0100435 NIH_MUST (event_new (NULL, PWRSTATUS_EVENT, NULL));
Scott James Remnant2c950692007-02-25 09:13:38 +0000436}
437
438/**
Scott James Remnant7ba2cf62007-06-10 22:20:38 +0100439 * hup_handler:
440 * @data: unused,
441 * @signal: signal that called this handler.
442 *
443 * Handle having recieved the SIGHUP signal, which we use to instruct us to
444 * reload our configuration.
445 **/
446static void
447hup_handler (void *data,
448 NihSignal *signal)
449{
450 nih_info (_("Reloading configuration"));
451 conf_reload ();
452}
Scott James Remnantf3ef5112008-06-05 01:26:10 +0100453#endif /* DEBUG */