merge ubus system namespace from rpcd codebase
[project/procd.git] / main.c
1 /*
2 * Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
3 * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
4 *
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
8 *
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.
13 */
14
15 #include <sys/wait.h>
16 #include <sys/types.h>
17
18 #include <unistd.h>
19 #include <getopt.h>
20 #include <libgen.h>
21
22 #include "procd.h"
23 #include "hotplug.h"
24 #include "watchdog.h"
25
26 static int usage(const char *prog)
27 {
28 ERROR("Usage: %s [options]\n"
29 "Options:\n"
30 " -s <path>: Path to ubus socket\n"
31 " -d: Enable debug messages\n"
32 "\n", prog);
33 return 1;
34 }
35
36
37 static int main_procd_init(int argc, char **argv)
38 {
39 procd_signal_preinit();
40 procd_early();
41 debug_init();
42 watchdog_init();
43 system("/sbin/kmodloader /etc/modules-boot.d/");
44 uloop_init();
45 hotplug("/etc/hotplug-preinit.json");
46 procd_preinit();
47 uloop_run();
48 return 0;
49 }
50
51 int main(int argc, char **argv)
52 {
53 int ch;
54
55 if (!strcmp(basename(*argv), "init"))
56 return main_procd_init(argc, argv);
57
58 while ((ch = getopt(argc, argv, "ds:")) != -1) {
59 switch (ch) {
60 case 's':
61 ubus_socket = optarg;
62 break;
63 case 'd':
64 debug++;
65 break;
66 default:
67 return usage(argv[0]);
68 }
69 }
70 uloop_init();
71 procd_signal();
72 if (getpid() != 1)
73 procd_connect_ubus();
74 else
75 procd_state_next();
76 uloop_run();
77
78 return 0;
79 }