Don't exit from watchdogd on receiving a signal if we cannot stop the watchdog.

That'll require -KILL. This avoids resetting your system on one of the
watchdogs that you cannot disable.
This commit is contained in:
Nick Hibma
2006-12-15 22:47:36 +00:00
parent 9c65d944a0
commit 0f71a1cba6
+18 -11
View File
@@ -55,7 +55,7 @@ static void sighandler(int);
static void watchdog_loop(void); static void watchdog_loop(void);
static int watchdog_init(void); static int watchdog_init(void);
static int watchdog_onoff(int onoff); static int watchdog_onoff(int onoff);
static int watchdog_patpat(void); static int watchdog_patpat(u_int timeout);
static void usage(void); static void usage(void);
int debugging = 0; int debugging = 0;
@@ -121,7 +121,6 @@ main(int argc, char *argv[])
watchdog_loop(); watchdog_loop();
/* exiting */ /* exiting */
watchdog_onoff(0);
pidfile_remove(pfh); pidfile_remove(pfh);
return (EX_OK); return (EX_OK);
} else { } else {
@@ -129,7 +128,7 @@ main(int argc, char *argv[])
timeout |= WD_PASSIVE; timeout |= WD_PASSIVE;
else else
timeout |= WD_ACTIVE; timeout |= WD_ACTIVE;
if (watchdog_patpat() < 0) if (watchdog_patpat(timeout) < 0)
err(EX_OSERR, "patting the dog"); err(EX_OSERR, "patting the dog");
return (EX_OK); return (EX_OK);
} }
@@ -169,7 +168,7 @@ watchdog_loop(void)
struct stat sb; struct stat sb;
int failed; int failed;
while (end_program == 0) { while (end_program != 2) {
failed = 0; failed = 0;
if (test_cmd != NULL) if (test_cmd != NULL)
@@ -178,8 +177,17 @@ watchdog_loop(void)
failed = stat("/etc", &sb); failed = stat("/etc", &sb);
if (failed == 0) if (failed == 0)
watchdog_patpat(); watchdog_patpat(timeout|WD_ACTIVE);
sleep(nap); sleep(nap);
if (end_program != 0) {
if (watchdog_onoff(0) == 0) {
end_program = 2;
} else {
warnx("Could not stop the watchdog, not exitting");
end_program = 0;
}
}
} }
} }
@@ -188,10 +196,10 @@ watchdog_loop(void)
* to keep the watchdog from firing. * to keep the watchdog from firing.
*/ */
int int
watchdog_patpat(void) watchdog_patpat(u_int t)
{ {
return ioctl(fd, WDIOCPATPAT, &timeout); return ioctl(fd, WDIOCPATPAT, &t);
} }
/* /*
@@ -203,10 +211,9 @@ watchdog_onoff(int onoff)
{ {
if (onoff) if (onoff)
timeout |= WD_ACTIVE; return watchdog_patpat((timeout|WD_ACTIVE));
else else
timeout &= ~WD_ACTIVE; return watchdog_patpat(0);
return watchdog_patpat();
} }
/* /*
@@ -216,7 +223,7 @@ static void
usage() usage()
{ {
if (is_daemon) if (is_daemon)
fprintf(stderr, "usage: watchdogd [-d] [-e cmd] [-I file]\n"); fprintf(stderr, "usage: watchdogd [-d] [-e cmd] [-I file] [-s sleep] [-t timeout]\n");
else else
fprintf(stderr, "usage: watchdog [-d] [-t timeout]\n"); fprintf(stderr, "usage: watchdog [-d] [-t timeout]\n");
exit(EX_USAGE); exit(EX_USAGE);