watchdog: add support for starting/stopping watchdog refresh
[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_early();
40         debug_init();
41         watchdog_init();
42         uloop_init();
43         hotplug("/etc/hotplug-preinit.json");
44         procd_preinit();
45         uloop_run();
46         return 0;
47 }
48
49 int main(int argc, char **argv)
50 {
51         int ch;
52
53         if (!strcmp(basename(*argv), "init"))
54                 return main_procd_init(argc, argv);
55
56         while ((ch = getopt(argc, argv, "ds:")) != -1) {
57                 switch (ch) {
58                 case 's':
59                         ubus_socket = optarg;
60                         break;
61                 case 'd':
62                         debug++;
63                         break;
64                 default:
65                         return usage(argv[0]);
66                 }
67         }
68         uloop_init();
69         procd_signal();
70         if (getpid() != 1)
71                 procd_connect_ubus();
72         else
73                 procd_state_next();
74         uloop_run();
75
76         return 0;
77 }