proto-shell: parse ipv4/ipv6 address lists
[project/netifd.git] / main.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <getopt.h>
5
6 #include "netifd.h"
7 #include "ubus.h"
8 #include "config.h"
9 #include "interface.h"
10
11 const char *main_path = ".";
12 static char **global_argv;
13
14 static void netifd_do_restart(struct uloop_timeout *timeout)
15 {
16 execvp(global_argv[0], global_argv);
17 }
18
19 static struct uloop_timeout restart_timer = {
20 .cb = netifd_do_restart,
21 };
22
23 void netifd_restart(void)
24 {
25 interface_set_down(NULL);
26 uloop_timeout_set(&restart_timer, 1000);
27 }
28
29 static int usage(const char *progname)
30 {
31 fprintf(stderr, "Usage: %s [options]\n"
32 "Options:\n"
33 " -s <path>: Path to the ubus socket\n"
34 " -p <path>: Path to netifd addons (default: %s)\n"
35 "\n", progname, main_path);
36
37 return 1;
38 }
39
40 int main(int argc, char **argv)
41 {
42 const char *socket = NULL;
43 int ch;
44
45 global_argv = argv;
46
47 while ((ch = getopt(argc, argv, "s:")) != -1) {
48 switch(ch) {
49 case 's':
50 socket = optarg;
51 break;
52 case 'p':
53 main_path = optarg;
54 break;
55 default:
56 return usage(argv[0]);
57 }
58 }
59
60 if (netifd_ubus_init(NULL) < 0) {
61 fprintf(stderr, "Failed to connect to ubus\n");
62 return 1;
63 }
64
65 config_init_interfaces(NULL);
66
67 uloop_run();
68
69 netifd_ubus_done();
70
71 return 0;
72 }