summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoachim Nilsson <troglobit@gmail.com>2019-05-26 12:31:02 (GMT)
committerJoachim Nilsson <troglobit@gmail.com>2019-05-26 12:31:02 (GMT)
commitdab49143303a011b277000808140e8c0ecabeb34 (patch)
treec1e52522aaebf93f73f7eeae60b5f6e2bb71c16a
parent3092f37033ecfb13f639695dd3d5f490b02a61e9 (diff)
No need to handover to Finit more than once
This fixes an annoying side effect when disabling and then re-enabling watchdogd using the API. When re-enabling the wdt_register() function may be called by wdt_init(), this will cause Finit to stop the current watchdog daemon (us), which is not what we want. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
-rw-r--r--src/finit.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/finit.c b/src/finit.c
index 4a1f848..6775b46 100644
--- a/src/finit.c
+++ b/src/finit.c
@@ -27,15 +27,21 @@
int wdt_register(void)
{
- int sd, rc = -1, retry = 3;
- size_t len;
- struct pollfd pfd;
- struct sockaddr_un sun;
+ static int already = 0;
struct init_request rq = {
.magic = INIT_MAGIC,
.cmd = INIT_CMD_WDOG_HELLO,
.runlevel = getpid(),
};
+ struct sockaddr_un sun;
+ struct pollfd pfd;
+ size_t len;
+ int sd, rc = -1, retry = 3;
+
+ if (already) {
+ DEBUG("No need to handover to Finit again.");
+ return 0;
+ }
sd = socket(AF_UNIX, SOCK_STREAM, 0);
if (-1 == sd)
@@ -72,6 +78,9 @@ int wdt_register(void)
if (rq.cmd == INIT_CMD_ACK)
rc = 0;
+
+ if (!rc)
+ already = 1;
err:
close(sd);