diff --git a/configure.ac b/configure.ac index 4df69904..483f1f5c 100644 --- a/configure.ac +++ b/configure.ac @@ -57,10 +57,6 @@ AC_ARG_ENABLE(auto_reload, AS_HELP_STRING([--enable-auto-reload], [Automatic reload on any .conf change]),,[ enable_auto_reload=no]) -AC_ARG_ENABLE(watchdog, - AS_HELP_STRING([--enable-watchdog], [Enable built-in watchdog, uses /dev/watchdog]),,[ - enable_watchdog=no]) - AC_ARG_ENABLE(redirect, AS_HELP_STRING([--enable-redirect], [Redirect service output to /dev/null, default: no]),,[ enable_redirect_output=no]) @@ -124,6 +120,10 @@ AC_ARG_WITH(random-seed, AS_HELP_STRING([--with-random-seed=FILE], [Save a random seed for /dev/urandom across reboots, default /var/lib/misc/random-seed]), [random_seed=$withval], [random_seed=yes]) +AC_ARG_WITH(watchdog, + AS_HELP_STRING([--with-watchdog=[DEV]], [Enable built-in watchdog, default: /dev/watchdog]), + [watchdog=$withval],[watchdog=]) + ### Enable features ########################################################################### # Create config.h from selected features and fallback defaults @@ -133,9 +133,6 @@ AS_IF([test "x$enable_emergency_shell" = "xyes"], [ AS_IF([test "x$enable_auto_reload" = "xyes"], [ AC_DEFINE(AUTO_RELOAD, 1, [Finit automatically does `initctl reload` on any .conf change])]) -AS_IF([test "x$enable_watchdog" = "xyes"], [ - AC_DEFINE(BUILTIN_WATCHDOG, 1, [Enable built-in watchdog, kicks on /dev/watchdog])]) - AS_IF([test "x$enable_redirect" = "xyes"], [ AC_DEFINE(REDIRECT_OUTPUT, 1, [Enable redirection of service output to /dev/null])]) @@ -197,9 +194,15 @@ AS_IF([test "x$with_random_seed" != "xno"], [ AC_EXPAND_DIR(random_path, "$random_seed") AC_DEFINE_UNQUOTED(RANDOMSEED, "$random_path", [Improve random at boot by seeding it with sth from before.])]) +AS_IF([test "x$with_watchdog" != "xno"], [ + AS_IF([test "x$watchdog" = "xyes"], [ + watchdog=/dev/watchdog]) + with_watchdog=yes + AC_DEFINE_UNQUOTED(WDT_DEVNODE, "$watchdog", [Built-in watchdog device node])]) + # Control build with automake flags AM_CONDITIONAL(STATIC, [test "x$enable_static" = "xyes"]) -AM_CONDITIONAL(WATCHDOGD, [test "x$enable_watchdog" = "xyes"]) +AM_CONDITIONAL(WATCHDOGD, [test "x$with_watchdog" != "xno"]) AM_CONDITIONAL(LOGIT, [test "x$enable_logit" = "xyes"]) AM_CONDITIONAL(DOC, [test "x$enable_doc" = "xyes"]) AM_CONDITIONAL(CONTRIB, [test "x$enable_contrib" = "xyes"]) @@ -246,7 +249,7 @@ Behavior: Optional features: Install doc/..........: $enable_doc Install contrib/......: $enable_contrib - Built-in watchdogd....: $enable_watchdog + Built-in watchdogd....: $with_watchdog $watchdog Built-in logrotate....: $enable_logrotate Scripting tool logit..: $enable_logit Emergency shell.......: $enable_emergency_shell diff --git a/src/watchdog.c b/src/watchdog.c index 4d5bd928..f02b8ed8 100644 --- a/src/watchdog.c +++ b/src/watchdog.c @@ -23,6 +23,8 @@ #include #include +#include +#include #include #include #include @@ -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; } /** diff --git a/src/watchdog.h b/src/watchdog.h index 468dca6d..f948806d 100644 --- a/src/watchdog.h +++ b/src/watchdog.h @@ -23,7 +23,9 @@ #include "config.h" /* Generated by configure script */ +#ifndef WDT_DEVNODE #define WDT_DEVNODE "/dev/watchdog" +#endif #define WDT_TIMEOUT 30 /**