blob: e99a3fcd35bef8659e6b12889dce57c3635ad897 [file] [log] [blame]
Scott James Remnant50748842006-05-16 21:02:31 +01001/* upstart
2 *
Scott James Remnantb6270dd2006-07-13 02:16:38 +01003 * Copyright © 2006 Canonical Ltd.
4 * Author: Scott James Remnant <scott@ubuntu.com>.
Scott James Remnant50748842006-05-16 21:02:31 +01005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifdef HAVE_CONFIG_H
22# include <config.h>
23#endif /* HAVE_CONFIG_H */
24
25
Scott James Remnant77e8db32006-08-21 08:47:50 +020026#include <nih/macros.h>
27#include <nih/alloc.h>
28#include <nih/list.h>
29#include <nih/timer.h>
30#include <nih/signal.h>
31#include <nih/child.h>
32#include <nih/main.h>
33#include <nih/logging.h>
34
35#include "process.h"
36#include "job.h"
37#include "event.h"
38#include "control.h"
39#include "cfgfile.h"
Scott James Remnant50748842006-05-16 21:02:31 +010040
41
42int
43main (int argc,
44 char *argv[])
45{
Scott James Remnant77e8db32006-08-21 08:47:50 +020046 int ret, i;
Scott James Remnant50748842006-05-16 21:02:31 +010047
Scott James Remnant77e8db32006-08-21 08:47:50 +020048 nih_main_init (argv[0]);
49
50 nih_log_set_priority (NIH_LOG_DEBUG);
51
52
53 /* Reset the signal state and install the signal handler for those
54 * signals we actually want to catch; this also sets those that
55 * can be sent to us, because we're special
56 */
57 nih_signal_reset ();
58 nih_signal_set_handler (SIGALRM, nih_signal_handler);
59 nih_signal_set_handler (SIGTERM, nih_signal_handler);
60 nih_signal_set_handler (SIGHUP, nih_signal_handler);
61
62 nih_signal_add_callback (NULL, SIGTERM, nih_main_term_signal, NULL);
63 nih_signal_add_callback (NULL, SIGHUP, (NihSignalCb)cfg_read, NULL);
64
65 /* Reap all children that die */
66 nih_child_add_watch (NULL, -1, job_child_reaper, NULL);
67
68 /* Process the event queue every time through the main loop */
69 nih_main_loop_add_func (NULL, event_queue_run, NULL);
70
71
72 /* Close any file descriptors we inherited, and open the console
73 * device instead
74 */
75 for (i = 0; i < 3; i++)
76 close (i);
77
78 process_setup_console (CONSOLE_OUTPUT);
79
80
81 /* Become session and process group leader (should be already,
82 * but you never know what initramfs did
83 */
84 setsid ();
85
86 /* Open control socket */
87 control_open ();
88
89 /* Read configuration */
90 cfg_read ();
91
92
93 /* Generate and run the startup event */
94 event_queue_edge ("startup");
95 event_queue_run (NULL, NULL);
96
97 /* Go! */
98 ret = nih_main_loop ();
99
100 return ret;
Scott James Remnant50748842006-05-16 21:02:31 +0100101}