fix behaviour during sysupgrade
authorJohn Crispin <blogic@openwrt.org>
Thu, 18 Apr 2013 19:27:58 +0000 (21:27 +0200)
committerJohn Crispin <blogic@openwrt.org>
Tue, 23 Apr 2013 16:54:03 +0000 (18:54 +0200)
Signed-off-by: John Crispin <blogic@openwrt.org>
hotplug.c
hotplug.h
procd.h
syslog.c
syslog.h
system.c
ubus.c

index ac54da4..f7e2ce9 100644 (file)
--- a/hotplug.c
+++ b/hotplug.c
@@ -434,3 +434,9 @@ void hotplug(char *rules)
        queue_proc.cb = queue_proc_cb;
        uloop_fd_add(&hotplug_fd, ULOOP_READ);
 }
        queue_proc.cb = queue_proc_cb;
        uloop_fd_add(&hotplug_fd, ULOOP_READ);
 }
+
+void hotplug_shutdown(void)
+{
+       uloop_fd_delete(&hotplug_fd);
+       close(hotplug_fd.fd);
+}
index 7018d23..e33afcb 100644 (file)
--- a/hotplug.h
+++ b/hotplug.h
@@ -18,6 +18,7 @@
 #include <libubox/uloop.h>
 
 void hotplug(char *rules);
 #include <libubox/uloop.h>
 
 void hotplug(char *rules);
+void hotplug_shutdown(void);
 void hotplug_last_event(uloop_timeout_handler handler);
 
 #endif
 void hotplug_last_event(uloop_timeout_handler handler);
 
 #endif
diff --git a/procd.h b/procd.h
index a500f00..8c2892d 100644 (file)
--- a/procd.h
+++ b/procd.h
@@ -47,6 +47,7 @@ extern unsigned int debug;
 void debug_init(void);
 
 void procd_connect_ubus(void);
 void debug_init(void);
 
 void procd_connect_ubus(void);
+void procd_reconnect_ubus(int reconnect);
 void ubus_init_service(struct ubus_context *ctx);
 void ubus_init_log(struct ubus_context *ctx);
 void ubus_init_system(struct ubus_context *ctx);
 void ubus_init_service(struct ubus_context *ctx);
 void ubus_init_log(struct ubus_context *ctx);
 void ubus_init_system(struct ubus_context *ctx);
index 416740b..fa4a9b3 100644 (file)
--- a/syslog.c
+++ b/syslog.c
@@ -276,3 +276,11 @@ void log_init(void)
        klog_open();
        openlog("procd", LOG_PID, LOG_DAEMON);
 }
        klog_open();
        openlog("procd", LOG_PID, LOG_DAEMON);
 }
+
+void log_shutdown(void)
+{
+       ustream_free(&slog.stream);
+       ustream_free(&klog.stream);
+       close(slog.fd.fd);
+       close(klog.fd.fd);
+}
index 1918028..b2471eb 100644 (file)
--- a/syslog.h
+++ b/syslog.h
@@ -31,6 +31,7 @@ struct log_head {
 };
 
 void log_init(void);
 };
 
 void log_init(void);
+void log_shutdown(void);
 
 typedef void (*log_list_cb)(struct log_head *h);
 struct log_head* log_list(int count, struct log_head *h);
 
 typedef void (*log_list_cb)(struct log_head *h);
 struct log_head* log_list(int count, struct log_head *h);
index 658dd5e..8dbc7d0 100644 (file)
--- a/system.c
+++ b/system.c
@@ -24,6 +24,7 @@
 
 #include "procd.h"
 #include "watchdog.h"
 
 #include "procd.h"
 #include "watchdog.h"
+#include "hotplug.h"
 
 #define HOSTNAME_PATH  "/proc/sys/kernel/hostname"
 
 
 #define HOSTNAME_PATH  "/proc/sys/kernel/hostname"
 
@@ -55,6 +56,17 @@ static int system_info(struct ubus_context *ctx, struct ubus_object *obj,
        return 0;
 }
 
        return 0;
 }
 
+static int system_upgrade(struct ubus_context *ctx, struct ubus_object *obj,
+                       struct ubus_request_data *req, const char *method,
+                       struct blob_attr *msg)
+{
+       procd_reconnect_ubus(0);
+       log_shutdown();
+       hotplug_shutdown();
+
+       return 0;
+}
+
 enum {
        WDT_FREQUENCY,
        WDT_TIMEOUT,
 enum {
        WDT_FREQUENCY,
        WDT_TIMEOUT,
@@ -120,6 +132,7 @@ static int watchdog_set(struct ubus_context *ctx, struct ubus_object *obj,
 
 static const struct ubus_method system_methods[] = {
        UBUS_METHOD_NOARG("info", system_info),
 
 static const struct ubus_method system_methods[] = {
        UBUS_METHOD_NOARG("info", system_info),
+       UBUS_METHOD_NOARG("upgrade", system_upgrade),
        UBUS_METHOD("watchdog", watchdog_set, watchdog_policy),
 };
 
        UBUS_METHOD("watchdog", watchdog_set, watchdog_policy),
 };
 
diff --git a/ubus.c b/ubus.c
index e87543a..216cc16 100644 (file)
--- a/ubus.c
+++ b/ubus.c
@@ -23,6 +23,7 @@ char *ubus_socket = NULL;
 static struct ubus_context *ctx;
 static struct uloop_process ubus_proc;
 static bool ubus_connected = false;
 static struct ubus_context *ctx;
 static struct uloop_process ubus_proc;
 static bool ubus_connected = false;
+static int reconnect = 1;
 
 static void procd_ubus_connection_lost(struct ubus_context *old_ctx);
 
 
 static void procd_ubus_connection_lost(struct ubus_context *old_ctx);
 
@@ -84,6 +85,9 @@ static void procd_ubus_try_connect(void)
 
 static void procd_ubus_connection_lost(struct ubus_context *old_ctx)
 {
 
 static void procd_ubus_connection_lost(struct ubus_context *old_ctx)
 {
+       if (!reconnect)
+               return;
+
        procd_ubus_try_connect();
        while (!ubus_connected) {
                procd_restart_ubus();
        procd_ubus_try_connect();
        while (!ubus_connected) {
                procd_restart_ubus();
@@ -101,3 +105,8 @@ void procd_connect_ubus(void)
        procd_ubus_connection_lost(NULL);
 }
 
        procd_ubus_connection_lost(NULL);
 }
 
+void procd_reconnect_ubus(int _reconnect)
+{
+       reconnect = _reconnect;
+}
+