@@ -90,7 +90,7 @@ fail:
static void
spawn_procd(struct uloop_process *proc, int ret)
{
- char *wdt_fd = watchdog_fd();
+ int wdt_fd = watchdog_fd();
char *argv[] = { "/sbin/procd", NULL};
char dbg[2];
@@ -104,8 +104,13 @@ spawn_procd(struct uloop_process *proc, int ret)
check_sysupgrade();
DEBUG(2, "Exec to real procd now\n");
- if (wdt_fd)
- setenv("WDTFD", wdt_fd, 1);
+
+ if (wdt_fd >= 0) {
+ char fd_buf[12];
+ snprintf(fd_buf, sizeof(fd_buf), "%d", wdt_fd);
+ setenv("WDTFD", fd_buf, 1);
+ }
+
check_dbglvl();
if (debug > 0) {
snprintf(dbg, 2, "%d", debug);
@@ -378,7 +378,7 @@ static int watchdog_set(struct ubus_context *ctx,
struct ubus_object *obj,
if (tb[WDT_STOP])
watchdog_set_stopped(blobmsg_get_bool(tb[WDT_STOP]));
- if (watchdog_fd() == NULL)
+ if (watchdog_fd() < 0)
status = "offline";
else if (watchdog_get_stopped())
status = "stopped";
@@ -29,7 +29,7 @@ void sysupgrade_exec_upgraded(const char *prefix, char
*path,
const char *backup, char *command,
struct blob_attr *options)
{
- char *wdt_fd = watchdog_fd();
+ int wdt_fd = watchdog_fd();
char *argv[] = { "/sbin/upgraded", NULL, NULL, NULL};
struct blob_attr *option;
int rem;
@@ -44,9 +44,11 @@ void sysupgrade_exec_upgraded(const char *prefix,
char *path,
argv[1] = path;
argv[2] = command;
- if (wdt_fd) {
+ if (wdt_fd >= 0) {
+ char fd_buf[12];
+ snprintf(fd_buf, sizeof(fd_buf), "%d", wdt_fd);
watchdog_set_cloexec(false);
- setenv("WDTFD", wdt_fd, 1);
+ setenv("WDTFD", fd_buf, 1);
}
if (backup)
@@ -146,16 +146,9 @@ int watchdog_frequency(int frequency)
return wdt_frequency;
}
-char* watchdog_fd(void)
+int watchdog_fd(void)
{
- static char fd_buf[12];
-
- if (wdt_fd < 0)
- return NULL;
-
- snprintf(fd_buf, sizeof(fd_buf), "%d", wdt_fd);
-
- return fd_buf;
+ return wdt_fd;
}
void watchdog_init(int preinit)
@@ -19,7 +19,7 @@
#ifndef DISABLE_INIT
void watchdog_init(int preinit);
-char* watchdog_fd(void);
+int watchdog_fd(void);
int watchdog_timeout(int timeout);
int watchdog_frequency(int frequency);
void watchdog_set_magicclose(bool val);
@@ -33,9 +33,9 @@ static inline void watchdog_init(int preinit)
{
}
-static inline char* watchdog_fd(void)
+static inline int watchdog_fd(void)
{
- return "";
+ return -1;
}
static inline int watchdog_timeout(int timeout)
This change improves the frequently called path of determining if the watchdog is alive when responding to ubus transactions at the expense of complicating the less frequently called code of transitioning to the upgraded binary, and transitioning from pre-init to procd. Signed-off-by: Michael Jones <mike@meshplusplus.com> --- initd/preinit.c | 11 ++++++++--- system.c | 2 +- sysupgrade.c | 8 +++++--- watchdog.c | 11 ++--------- watchdog.h | 6 +++--- 5 files changed, 19 insertions(+), 19 deletions(-)