mirror of
https://github.com/troglobit/finit.git
synced 2026-10-17 10:49:34 +00:00
watchdog: Enable --with-watchdog[=DEV] and improve log messages
This patch changes the configure option to enable the built-in watchdog from --enable-watchdog to --with-watchdog[=DEV]. This is the convention for features that take arguments. Also, improve log messages to aid debugging when finit-watchdogd does not start properly. This means flushing logs to syslogd with closelog() Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
38f7d24a80
commit
06e456384c
3 files changed
+28
-18
No files matched your search
+14
-9
@@ -23,6 +23,8 @@
|
||||
|
||||
#include <config.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sysexits.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
@@ -58,7 +60,7 @@ static int init(char *progname, char *devnode)
|
||||
signal(SIGPWR, sighandler);
|
||||
|
||||
openlog(&progname[1], LOG_CONS | LOG_PID, LOG_DAEMON);
|
||||
syslog(LOG_INFO, "Finit v%s basic watchdogd starting ...", VERSION);
|
||||
syslog(LOG_INFO, "Finit v%s watchdog %s starting ...", VERSION, devnode);
|
||||
|
||||
fd = open(devnode, O_WRONLY);
|
||||
if (fd == -1)
|
||||
@@ -89,24 +91,25 @@ static int loop(int fd, int timeout)
|
||||
if (handover) {
|
||||
syslog(LOG_INFO, "Handing over %s and exiting ...", WDT_DEVNODE);
|
||||
ioctl(fd, WDIOC_KEEPALIVE, &dummy);
|
||||
return !write(fd, "V", 1);
|
||||
if (write(fd, "V", 1) == -1)
|
||||
return EX_IOERR;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return EX_OK;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int fd, ret;
|
||||
int fd, rc = EX_OK;
|
||||
|
||||
fd = init(argv[0], WDT_DEVNODE);
|
||||
if (fd == -1) {
|
||||
if (ENOENT != errno)
|
||||
syslog(LOG_CRIT, "Failed connecting to watchdog %s", WDT_DEVNODE);
|
||||
return 1;
|
||||
syslog(LOG_CRIT, "Failed connecting to %s: %s", WDT_DEVNODE, strerror(errno));
|
||||
rc = EX_OSFILE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
ret = loop(fd, WDT_TIMEOUT);
|
||||
rc = loop(fd, WDT_TIMEOUT);
|
||||
while (!handover) {
|
||||
syslog(LOG_ALERT, "System going down ...");
|
||||
|
||||
@@ -117,8 +120,10 @@ int main(int argc, char *argv[])
|
||||
ioctl(fd, WDIOC_SETTIMEOUT, &shutdown);
|
||||
}
|
||||
close(fd);
|
||||
done:
|
||||
closelog();
|
||||
|
||||
return ret;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,7 +23,9 @@
|
||||
|
||||
#include "config.h" /* Generated by configure script */
|
||||
|
||||
#ifndef WDT_DEVNODE
|
||||
#define WDT_DEVNODE "/dev/watchdog"
|
||||
#endif
|
||||
#define WDT_TIMEOUT 30
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user