mirror of
https://github.com/troglobit/finit.git
synced 2026-11-09 16:21:24 +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
+12
-9
@@ -57,10 +57,6 @@ AC_ARG_ENABLE(auto_reload,
|
|||||||
AS_HELP_STRING([--enable-auto-reload], [Automatic reload on any .conf change]),,[
|
AS_HELP_STRING([--enable-auto-reload], [Automatic reload on any .conf change]),,[
|
||||||
enable_auto_reload=no])
|
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,
|
AC_ARG_ENABLE(redirect,
|
||||||
AS_HELP_STRING([--enable-redirect], [Redirect service output to /dev/null, default: no]),,[
|
AS_HELP_STRING([--enable-redirect], [Redirect service output to /dev/null, default: no]),,[
|
||||||
enable_redirect_output=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]),
|
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])
|
[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 ###########################################################################
|
### Enable features ###########################################################################
|
||||||
|
|
||||||
# Create config.h from selected features and fallback defaults
|
# 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"], [
|
AS_IF([test "x$enable_auto_reload" = "xyes"], [
|
||||||
AC_DEFINE(AUTO_RELOAD, 1, [Finit automatically does `initctl reload` on any .conf change])])
|
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"], [
|
AS_IF([test "x$enable_redirect" = "xyes"], [
|
||||||
AC_DEFINE(REDIRECT_OUTPUT, 1, [Enable redirection of service output to /dev/null])])
|
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_EXPAND_DIR(random_path, "$random_seed")
|
||||||
AC_DEFINE_UNQUOTED(RANDOMSEED, "$random_path", [Improve random at boot by seeding it with sth from before.])])
|
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
|
# Control build with automake flags
|
||||||
AM_CONDITIONAL(STATIC, [test "x$enable_static" = "xyes"])
|
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(LOGIT, [test "x$enable_logit" = "xyes"])
|
||||||
AM_CONDITIONAL(DOC, [test "x$enable_doc" = "xyes"])
|
AM_CONDITIONAL(DOC, [test "x$enable_doc" = "xyes"])
|
||||||
AM_CONDITIONAL(CONTRIB, [test "x$enable_contrib" = "xyes"])
|
AM_CONDITIONAL(CONTRIB, [test "x$enable_contrib" = "xyes"])
|
||||||
@@ -246,7 +249,7 @@ Behavior:
|
|||||||
Optional features:
|
Optional features:
|
||||||
Install doc/..........: $enable_doc
|
Install doc/..........: $enable_doc
|
||||||
Install contrib/......: $enable_contrib
|
Install contrib/......: $enable_contrib
|
||||||
Built-in watchdogd....: $enable_watchdog
|
Built-in watchdogd....: $with_watchdog $watchdog
|
||||||
Built-in logrotate....: $enable_logrotate
|
Built-in logrotate....: $enable_logrotate
|
||||||
Scripting tool logit..: $enable_logit
|
Scripting tool logit..: $enable_logit
|
||||||
Emergency shell.......: $enable_emergency_shell
|
Emergency shell.......: $enable_emergency_shell
|
||||||
|
|||||||
+14
-9
@@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sysexits.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@@ -58,7 +60,7 @@ static int init(char *progname, char *devnode)
|
|||||||
signal(SIGPWR, sighandler);
|
signal(SIGPWR, sighandler);
|
||||||
|
|
||||||
openlog(&progname[1], LOG_CONS | LOG_PID, LOG_DAEMON);
|
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);
|
fd = open(devnode, O_WRONLY);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
@@ -89,24 +91,25 @@ static int loop(int fd, int timeout)
|
|||||||
if (handover) {
|
if (handover) {
|
||||||
syslog(LOG_INFO, "Handing over %s and exiting ...", WDT_DEVNODE);
|
syslog(LOG_INFO, "Handing over %s and exiting ...", WDT_DEVNODE);
|
||||||
ioctl(fd, WDIOC_KEEPALIVE, &dummy);
|
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 main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int fd, ret;
|
int fd, rc = EX_OK;
|
||||||
|
|
||||||
fd = init(argv[0], WDT_DEVNODE);
|
fd = init(argv[0], WDT_DEVNODE);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
if (ENOENT != errno)
|
syslog(LOG_CRIT, "Failed connecting to %s: %s", WDT_DEVNODE, strerror(errno));
|
||||||
syslog(LOG_CRIT, "Failed connecting to watchdog %s", WDT_DEVNODE);
|
rc = EX_OSFILE;
|
||||||
return 1;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = loop(fd, WDT_TIMEOUT);
|
rc = loop(fd, WDT_TIMEOUT);
|
||||||
while (!handover) {
|
while (!handover) {
|
||||||
syslog(LOG_ALERT, "System going down ...");
|
syslog(LOG_ALERT, "System going down ...");
|
||||||
|
|
||||||
@@ -117,8 +120,10 @@ int main(int argc, char *argv[])
|
|||||||
ioctl(fd, WDIOC_SETTIMEOUT, &shutdown);
|
ioctl(fd, WDIOC_SETTIMEOUT, &shutdown);
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
done:
|
||||||
|
closelog();
|
||||||
|
|
||||||
return ret;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -23,7 +23,9 @@
|
|||||||
|
|
||||||
#include "config.h" /* Generated by configure script */
|
#include "config.h" /* Generated by configure script */
|
||||||
|
|
||||||
|
#ifndef WDT_DEVNODE
|
||||||
#define WDT_DEVNODE "/dev/watchdog"
|
#define WDT_DEVNODE "/dev/watchdog"
|
||||||
|
#endif
|
||||||
#define WDT_TIMEOUT 30
|
#define WDT_TIMEOUT 30
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user