add an ubus call for restarting netifd
authorFelix Fietkau <nbd@openwrt.org>
Fri, 9 Sep 2011 15:56:51 +0000 (17:56 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Fri, 9 Sep 2011 15:56:51 +0000 (17:56 +0200)
main.c
netifd.h
ubus.c

diff --git a/main.c b/main.c
index dc69abc..d1f976d 100644 (file)
--- a/main.c
+++ b/main.c
@@ -7,6 +7,22 @@
 #include "ubus.h"
 #include "config.h"
 
+static char **global_argv;
+
+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,
+};
+
+void netifd_restart(void)
+{
+       uloop_timeout_set(&restart_timer, 1000);
+}
+
 static int usage(const char *progname)
 {
        fprintf(stderr, "Usage: %s [options]\n"
@@ -22,6 +38,8 @@ int main(int argc, char **argv)
        const char *socket = NULL;
        int ch;
 
+       global_argv = argv;
+
        while ((ch = getopt(argc, argv, "s:")) != -1) {
                switch(ch) {
                case 's':
index 69210ac..916b79e 100644 (file)
--- a/netifd.h
+++ b/netifd.h
@@ -16,4 +16,6 @@
 struct device;
 struct interface;
 
+void netifd_restart(void);
+
 #endif
diff --git a/ubus.c b/ubus.c
index c914cc5..c8f178c 100644 (file)
--- a/ubus.c
+++ b/ubus.c
@@ -47,9 +47,19 @@ netifd_handle_device(struct ubus_context *ctx, struct ubus_object *obj,
        return 0;
 }
 
+static int
+netifd_handle_restart(struct ubus_context *ctx, struct ubus_object *obj,
+                     struct ubus_request_data *req, const char *method,
+                     struct blob_attr *msg)
+{
+       netifd_restart();
+       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 },
 };
 
 static struct ubus_object_type main_object_type =