Browse Source

fix behaviour during sysupgrade

Signed-off-by: John Crispin <blogic@openwrt.org>
John Crispin 11 years ago
parent
commit
32f1c6e467
7 changed files with 39 additions and 0 deletions
  1. 6 0
      hotplug.c
  2. 1 0
      hotplug.h
  3. 1 0
      procd.h
  4. 8 0
      syslog.c
  5. 1 0
      syslog.h
  6. 13 0
      system.c
  7. 9 0
      ubus.c

+ 6 - 0
hotplug.c

@@ -434,3 +434,9 @@ void hotplug(char *rules)
 	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);
+}

+ 1 - 0
hotplug.h

@@ -18,6 +18,7 @@
 #include <libubox/uloop.h>
 
 void hotplug(char *rules);
+void hotplug_shutdown(void);
 void hotplug_last_event(uloop_timeout_handler handler);
 
 #endif

+ 1 - 0
procd.h

@@ -47,6 +47,7 @@ extern unsigned int debug;
 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);

+ 8 - 0
syslog.c

@@ -276,3 +276,11 @@ void log_init(void)
 	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);
+}

+ 1 - 0
syslog.h

@@ -31,6 +31,7 @@ struct log_head {
 };
 
 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);

+ 13 - 0
system.c

@@ -24,6 +24,7 @@
 
 #include "procd.h"
 #include "watchdog.h"
+#include "hotplug.h"
 
 #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;
 }
 
+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,
@@ -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),
+	UBUS_METHOD_NOARG("upgrade", system_upgrade),
 	UBUS_METHOD("watchdog", watchdog_set, watchdog_policy),
 };
 

+ 9 - 0
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 int reconnect = 1;
 
 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)
 {
+	if (!reconnect)
+		return;
+
 	procd_ubus_try_connect();
 	while (!ubus_connected) {
 		procd_restart_ubus();
@@ -101,3 +105,8 @@ void procd_connect_ubus(void)
 	procd_ubus_connection_lost(NULL);
 }
 
+void procd_reconnect_ubus(int _reconnect)
+{
+	reconnect = _reconnect;
+}
+