11 #include "interface.h"
13 unsigned int debug_mask = 0;
14 const char *main_path = DEFAULT_MAIN_PATH;
15 const char *resolv_conf = DEFAULT_RESOLV_CONF;
16 static char **global_argv;
17 static struct list_head process_list = LIST_HEAD_INIT(process_list);
20 netifd_process_cb(struct uloop_process *proc, int ret)
22 struct netifd_process *np;
23 np = container_of(proc, struct netifd_process, uloop);
25 return np->cb(np, ret);
29 netifd_start_process(const char **argv, char **env, int dir_fd, struct netifd_process *proc)
33 netifd_kill_process(proc);
35 if ((pid = fork()) < 0)
47 execvp(argv[0], (char **) argv);
54 proc->uloop.cb = netifd_process_cb;
55 proc->uloop.pid = pid;
56 uloop_process_add(&proc->uloop);
57 list_add_tail(&proc->list, &process_list);
63 netifd_kill_process(struct netifd_process *proc)
65 if (!proc->uloop.pending)
68 kill(proc->uloop.pid, SIGTERM);
69 uloop_process_delete(&proc->uloop);
70 list_del(&proc->list);
73 static void netifd_do_restart(struct uloop_timeout *timeout)
75 execvp(global_argv[0], global_argv);
78 static void netifd_do_reload(struct uloop_timeout *timeout)
80 config_init_interfaces(NULL);
83 static struct uloop_timeout main_timer;
85 void netifd_reload(void)
87 main_timer.cb = netifd_do_reload;
88 uloop_timeout_set(&main_timer, 100);
91 void netifd_restart(void)
93 main_timer.cb = netifd_do_restart;
94 interface_set_down(NULL);
95 uloop_timeout_set(&main_timer, 1000);
98 static int usage(const char *progname)
100 fprintf(stderr, "Usage: %s [options]\n"
102 " -d <mask>: Mask for debug messages\n"
103 " -s <path>: Path to the ubus socket\n"
104 " -p <path>: Path to netifd addons (default: %s)\n"
105 " -h <path>: Path to the hotplug script\n"
106 " -r <path>: Path to resolv.conf\n"
107 " (default: "DEFAULT_HOTPLUG_PATH")\n"
108 "\n", progname, main_path);
113 int main(int argc, char **argv)
115 const char *socket = NULL;
120 while ((ch = getopt(argc, argv, "d:s:p:h:r:")) != -1) {
123 debug_mask = strtoul(optarg, NULL, 0);
132 hotplug_cmd_path = optarg;
135 resolv_conf = optarg;
138 return usage(argv[0]);
142 if (netifd_ubus_init(socket) < 0) {
143 fprintf(stderr, "Failed to connect to ubus\n");
148 fprintf(stderr, "Failed to initialize system control\n");
152 config_init_interfaces(NULL);