make ue of the md5.c inside libubox
[project/procd.git] / procd.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 #include <sys/stat.h>
18
19 #include <unistd.h>
20 #include <getopt.h>
21 #include <libgen.h>
22
23 #include "procd.h"
24 #include "watchdog.h"
25 #include "plug/hotplug.h"
26
27 unsigned int debug;
28
29 static int usage(const char *prog)
30 {
31         ERROR("Usage: %s [options]\n"
32                 "Options:\n"
33                 "\t-s <path>\tPath to ubus socket\n"
34                 "\t-h <path>\trun as hotplug daemon\n"
35                 "\t-d <level>\tEnable debug messages\n"
36                 "\n", prog);
37         return 1;
38 }
39
40 int main(int argc, char **argv)
41 {
42         int ch;
43
44         while ((ch = getopt(argc, argv, "d:s:h:")) != -1) {
45                 switch (ch) {
46                 case 'h':
47                         return hotplug_run(optarg);
48                 case 's':
49                         ubus_socket = optarg;
50                         break;
51                 case 'd':
52                         debug = atoi(optarg);
53                         break;
54                 default:
55                         return usage(argv[0]);
56                 }
57         }
58         uloop_init();
59         procd_signal();
60         trigger_init();
61         if (getpid() != 1)
62                 procd_connect_ubus();
63         else
64                 procd_state_next();
65         uloop_run();
66
67         return 0;
68 }