From: John Crispin Date: Thu, 18 Apr 2013 19:27:58 +0000 (+0200) Subject: fix behaviour during sysupgrade X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fprocd.git;a=commitdiff_plain;h=32f1c6e4679b6e0737616f3e58528531e826a3ce fix behaviour during sysupgrade Signed-off-by: John Crispin --- diff --git a/hotplug.c b/hotplug.c index ac54da4..f7e2ce9 100644 --- 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); } + +void hotplug_shutdown(void) +{ + uloop_fd_delete(&hotplug_fd); + close(hotplug_fd.fd); +} diff --git a/hotplug.h b/hotplug.h index 7018d23..e33afcb 100644 --- a/hotplug.h +++ b/hotplug.h @@ -18,6 +18,7 @@ #include void hotplug(char *rules); +void hotplug_shutdown(void); void hotplug_last_event(uloop_timeout_handler handler); #endif diff --git a/procd.h b/procd.h index a500f00..8c2892d 100644 --- a/procd.h +++ b/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); diff --git a/syslog.c b/syslog.c index 416740b..fa4a9b3 100644 --- a/syslog.c +++ b/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); +} diff --git a/syslog.h b/syslog.h index 1918028..b2471eb 100644 --- a/syslog.h +++ b/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); diff --git a/system.c b/system.c index 658dd5e..8dbc7d0 100644 --- a/system.c +++ b/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), }; diff --git a/ubus.c b/ubus.c index e87543a..216cc16 100644 --- 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 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; +} +