d1f976d3e011cb18b38cde76398d00e87182f3fe
[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
10 static char **global_argv;
11
12 static void netifd_do_restart(struct uloop_timeout *timeout)
13 {
14         execvp(global_argv[0], global_argv);
15 }
16
17 static struct uloop_timeout restart_timer = {
18         .cb = netifd_do_restart,
19 };
20
21 void netifd_restart(void)
22 {
23         uloop_timeout_set(&restart_timer, 1000);
24 }
25
26 static int usage(const char *progname)
27 {
28         fprintf(stderr, "Usage: %s [options]\n"
29                 "Options:\n"
30                 " -s <path>:            Path to the ubus socket\n"
31                 "\n", progname);
32
33         return 1;
34 }
35
36 int main(int argc, char **argv)
37 {
38         const char *socket = NULL;
39         int ch;
40
41         global_argv = argv;
42
43         while ((ch = getopt(argc, argv, "s:")) != -1) {
44                 switch(ch) {
45                 case 's':
46                         socket = optarg;
47                         break;
48                 default:
49                         return usage(argv[0]);
50                 }
51         }
52
53         if (netifd_ubus_init(NULL) < 0) {
54                 fprintf(stderr, "Failed to connect to ubus\n");
55                 return 1;
56         }
57
58         config_init_interfaces(NULL);
59
60         uloop_run();
61
62         netifd_ubus_done();
63
64         return 0;
65 }