Handle reload mechanism
[project/odhcpd.git] / src / config.c
index e33c855..f6a5327 100644 (file)
@@ -276,7 +276,7 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
 
        const char *ifname = NULL;
 #ifdef WITH_UBUS
-       if (overwrite)
+       if (overwrite || !iface->ifname[0])
                ifname = ubus_get_ifname(name);
 #endif
        if ((c = tb[IFACE_ATTR_IFNAME]))
@@ -284,10 +284,12 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
        else if ((c = tb[IFACE_ATTR_NETWORKID]))
                ifname = blobmsg_get_string(c);
 
-       if (!ifname)
+       if (!iface->ifname[0] && !ifname)
                return -1;
 
-       strncpy(iface->ifname, ifname, sizeof(iface->ifname) - 1);
+       if (ifname)
+               strncpy(iface->ifname, ifname, sizeof(iface->ifname) - 1);
+
        iface->inuse = true;
 
        if (overwrite)
@@ -486,9 +488,16 @@ static int set_interface(struct uci_section *s)
 
 
 static volatile int do_reload = false;
+void odhcpd_reload(void)
+{
+       uloop_cancelled = true;
+       do_reload = true;
+}
+
+
 static void set_stop(int signal)
 {
-       uloop_end();
+       uloop_cancelled = true;
        do_reload = (signal == SIGHUP);
 }
 
@@ -580,6 +589,7 @@ void odhcpd_run(void)
                                setup_dhcpv6_interface(i, true);
                                setup_ndp_interface(i, true);
                                setup_dhcpv4_interface(i, true);
+                               i->inuse = false;
                        } else {
                                close_interface(i);
                        }