add a ubus call for triggering config reloads
authorFelix Fietkau <nbd@openwrt.org>
Mon, 3 Oct 2011 01:13:30 +0000 (03:13 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Mon, 3 Oct 2011 01:13:30 +0000 (03:13 +0200)
main.c
netifd.h
ubus.c

diff --git a/main.c b/main.c
index e008f64..fe97ee1 100644 (file)
--- a/main.c
+++ b/main.c
@@ -18,14 +18,24 @@ static void netifd_do_restart(struct uloop_timeout *timeout)
        execvp(global_argv[0], global_argv);
 }
 
-static struct uloop_timeout restart_timer = {
-       .cb = netifd_do_restart,
-};
+static void netifd_do_reload(struct uloop_timeout *timeout)
+{
+       config_init_interfaces(NULL);
+}
+
+static struct uloop_timeout main_timer;
+
+void netifd_reload(void)
+{
+       main_timer.cb = netifd_do_reload;
+       uloop_timeout_set(&main_timer, 100);
+}
 
 void netifd_restart(void)
 {
+       main_timer.cb = netifd_do_restart;
        interface_set_down(NULL);
-       uloop_timeout_set(&restart_timer, 1000);
+       uloop_timeout_set(&main_timer, 1000);
 }
 
 static int usage(const char *progname)
index be29b3c..fc2b6a7 100644 (file)
--- a/netifd.h
+++ b/netifd.h
@@ -18,5 +18,6 @@ struct interface;
 
 extern const char *main_path;
 void netifd_restart(void);
+void netifd_reload(void);
 
 #endif
diff --git a/ubus.c b/ubus.c
index 5d9d921..d5a7007 100644 (file)
--- a/ubus.c
+++ b/ubus.c
@@ -57,10 +57,20 @@ netifd_handle_restart(struct ubus_context *ctx, struct ubus_object *obj,
        return 0;
 }
 
+static int
+netifd_handle_reload(struct ubus_context *ctx, struct ubus_object *obj,
+                     struct ubus_request_data *req, const char *method,
+                     struct blob_attr *msg)
+{
+       netifd_reload();
+       return 0;
+}
+
 static struct ubus_method main_object_methods[] = {
        UBUS_METHOD("add_device", netifd_handle_device, dev_policy),
        UBUS_METHOD("remove_device", netifd_handle_device, dev_policy),
        { .name = "restart", .handler = netifd_handle_restart },
+       { .name = "reload", .handler = netifd_handle_reload },
 };
 
 static struct ubus_object_type main_object_type =