mirror of
https://github.com/troglobit/finit.git
synced 2026-11-08 16:11:10 +00:00
Convert built-in watchdog to a standalone mini watchdogd
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
43942ab513
commit
3a1ad67e92
4 files changed
+55
-36
No files matched your search
+5
-3
@@ -218,9 +218,11 @@ AM_CONDITIONAL(INETD, [test "x$enable_inetd" = "xyes"])
|
|||||||
AM_CONDITIONAL(WATCHDOGD, [test "x$enable_watchdog" = "xyes"])
|
AM_CONDITIONAL(WATCHDOGD, [test "x$enable_watchdog" = "xyes"])
|
||||||
|
|
||||||
# Override default libdir, used for plugins and rescue.conf
|
# Override default libdir, used for plugins and rescue.conf
|
||||||
#pkglibdir=$libdir/finit
|
pkglibdir=$libdir/finit
|
||||||
#AC_SUBST(pkglibdir)
|
AC_SUBST(pkglibexecdir)
|
||||||
#AC_EXPAND_DIR(pkglibdir, "$libdir/finit")
|
AC_EXPAND_DIR(pkglibexecdir, "$libexecdir/finit")
|
||||||
|
AC_DEFINE_UNQUOTED(FINIT_LIBPATH_, "$pkglibexecdir", [Finit libexec path])
|
||||||
|
|
||||||
AC_EXPAND_DIR(plugin_path, "$libdir/finit/plugins")
|
AC_EXPAND_DIR(plugin_path, "$libdir/finit/plugins")
|
||||||
AC_SUBST(plugin_path)
|
AC_SUBST(plugin_path)
|
||||||
AC_DEFINE_UNQUOTED(PLUGIN_PATH, "$plugin_path", [Finit plugin path])
|
AC_DEFINE_UNQUOTED(PLUGIN_PATH, "$plugin_path", [Finit plugin path])
|
||||||
|
|||||||
+9
-3
@@ -10,6 +10,9 @@ endif
|
|||||||
|
|
||||||
bin_PROGRAMS = logit
|
bin_PROGRAMS = logit
|
||||||
sbin_PROGRAMS = finit initctl reboot
|
sbin_PROGRAMS = finit initctl reboot
|
||||||
|
if WATCHDOGD
|
||||||
|
pkglibexec_PROGRAMS = watchdogd
|
||||||
|
endif
|
||||||
|
|
||||||
logit_SOURCES = logit.c
|
logit_SOURCES = logit.c
|
||||||
logit_CFLAGS = -W -Wall -Wextra -Wno-unused-parameter -std=gnu99
|
logit_CFLAGS = -W -Wall -Wextra -Wno-unused-parameter -std=gnu99
|
||||||
@@ -36,9 +39,6 @@ pkginclude_HEADERS = cond.h finit.h helpers.h inetd.h log.h plugin.h svc.h
|
|||||||
if INETD
|
if INETD
|
||||||
finit_SOURCES += inetd.c inetd.h
|
finit_SOURCES += inetd.c inetd.h
|
||||||
endif
|
endif
|
||||||
if WATCHDOGD
|
|
||||||
finit_SOURCES += watchdog.c watchdog.h
|
|
||||||
endif
|
|
||||||
|
|
||||||
finit_CFLAGS = -W -Wall -Wextra -Wno-unused-parameter -std=gnu99
|
finit_CFLAGS = -W -Wall -Wextra -Wno-unused-parameter -std=gnu99
|
||||||
finit_CFLAGS += $(lite_CFLAGS) $(uev_CFLAGS)
|
finit_CFLAGS += $(lite_CFLAGS) $(uev_CFLAGS)
|
||||||
@@ -63,6 +63,12 @@ reboot_LDADD = $(lite_LIBS)
|
|||||||
INIT_LNKS = telinit init
|
INIT_LNKS = telinit init
|
||||||
REBOOT_LNKS = shutdown halt poweroff suspend
|
REBOOT_LNKS = shutdown halt poweroff suspend
|
||||||
|
|
||||||
|
if WATCHDOGD
|
||||||
|
watchdogd_SOURCES = watchdog.c watchdog.h
|
||||||
|
watchdogd_CFLAGS = -W -Wall -Wextra -Wno-unused-parameter -std=gnu99
|
||||||
|
#log.c log.h
|
||||||
|
endif
|
||||||
|
|
||||||
# Hook in install to add finit and reboot symlink(s)
|
# Hook in install to add finit and reboot symlink(s)
|
||||||
install-exec-hook:
|
install-exec-hook:
|
||||||
@$(INSTALL_DATA) $(srcdir)/rescue.conf $(DESTDIR)$(pkglibdir)
|
@$(INSTALL_DATA) $(srcdir)/rescue.conf $(DESTDIR)$(pkglibdir)
|
||||||
|
|||||||
+9
-3
@@ -47,7 +47,6 @@
|
|||||||
#include "tty.h"
|
#include "tty.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "utmp-api.h"
|
#include "utmp-api.h"
|
||||||
#include "watchdog.h"
|
|
||||||
|
|
||||||
int wdogpid = 0; /* No watchdog by default */
|
int wdogpid = 0; /* No watchdog by default */
|
||||||
int runlevel = 0; /* Bootstrap 'S' */
|
int runlevel = 0; /* Bootstrap 'S' */
|
||||||
@@ -214,12 +213,18 @@ static void emergency_shell(void)
|
|||||||
*/
|
*/
|
||||||
static void finalize(void)
|
static void finalize(void)
|
||||||
{
|
{
|
||||||
|
svc_t *svc;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Run startup scripts in the runparts directory, if any.
|
* Run startup scripts in the runparts directory, if any.
|
||||||
*/
|
*/
|
||||||
if (runparts && fisdir(runparts) && !rescue)
|
if (runparts && fisdir(runparts) && !rescue)
|
||||||
run_parts(runparts, NULL);
|
run_parts(runparts, NULL);
|
||||||
|
|
||||||
|
svc = svc_find(FINIT_LIBPATH_ "watchdogd", 1);
|
||||||
|
if (svc && !wdogpid)
|
||||||
|
wdogpid = svc->pid;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start all tasks/services in the configured runlevel
|
* Start all tasks/services in the configured runlevel
|
||||||
*/
|
*/
|
||||||
@@ -412,9 +417,10 @@ int main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start built-in watchdog as soon as possible, if enabled
|
* Start bundled watchdogd as soon as possible, if enabled
|
||||||
*/
|
*/
|
||||||
wdogpid = watchdog(argv[0]);
|
if (which(FINIT_LIBPATH_ "/watchdogd"))
|
||||||
|
service_register(SVC_TYPE_SERVICE, FINIT_LIBPATH_ "/watchdogd", global_rlimit, NULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Mount filesystems
|
* Mount filesystems
|
||||||
|
|||||||
+32
-27
@@ -21,12 +21,18 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <syslog.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <linux/watchdog.h>
|
#include <linux/watchdog.h>
|
||||||
|
|
||||||
#include "finit.h"
|
|
||||||
#include "log.h"
|
|
||||||
#include "watchdog.h"
|
#include "watchdog.h"
|
||||||
|
|
||||||
int running = 1;
|
int running = 1;
|
||||||
@@ -51,6 +57,9 @@ static int init(char *progname, char *devnode)
|
|||||||
signal(SIGTERM, sighandler);
|
signal(SIGTERM, sighandler);
|
||||||
signal(SIGPWR, sighandler);
|
signal(SIGPWR, sighandler);
|
||||||
|
|
||||||
|
openlog(&progname[1], LOG_CONS | LOG_PID, LOG_DAEMON);
|
||||||
|
syslog(LOG_INFO, "Finit v%s basic watchdogd starting ...", VERSION);
|
||||||
|
|
||||||
fd = open(devnode, O_WRONLY);
|
fd = open(devnode, O_WRONLY);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
return -1;
|
return -1;
|
||||||
@@ -78,6 +87,7 @@ static int loop(int fd, int timeout)
|
|||||||
|
|
||||||
/* External watchdogd wants to take over ... */
|
/* External watchdogd wants to take over ... */
|
||||||
if (handover) {
|
if (handover) {
|
||||||
|
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);
|
return !write(fd, "V", 1);
|
||||||
}
|
}
|
||||||
@@ -85,35 +95,30 @@ static int loop(int fd, int timeout)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int watchdog(char *progname)
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int pid;
|
int fd, ret;
|
||||||
|
|
||||||
pid = fork();
|
fd = init(argv[0], WDT_DEVNODE);
|
||||||
if (pid == 0) {
|
if (fd == -1) {
|
||||||
int fd, ret;
|
if (ENOENT != errno)
|
||||||
|
syslog(LOG_CRIT, "Failed connecting to watchdog %s", WDT_DEVNODE);
|
||||||
fd = init(progname, WDT_DEVNODE);
|
return 1;
|
||||||
if (fd == -1) {
|
|
||||||
if (ENOENT != errno)
|
|
||||||
_pe("Failed connecting to watchdog %s", WDT_DEVNODE);
|
|
||||||
_exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = loop(fd, WDT_TIMEOUT);
|
|
||||||
while (!handover) {
|
|
||||||
/* Waiting for SIGTERM ... */
|
|
||||||
sleep(1);
|
|
||||||
|
|
||||||
/* Set lowest possible timeout on SIGTERM */
|
|
||||||
ioctl(fd, WDIOC_SETTIMEOUT, &shutdown);
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
_exit(ret);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return pid;
|
ret = loop(fd, WDT_TIMEOUT);
|
||||||
|
while (!handover) {
|
||||||
|
syslog(LOG_ALERT, "System going down ...");
|
||||||
|
|
||||||
|
/* Waiting for SIGTERM ... */
|
||||||
|
sleep(1);
|
||||||
|
|
||||||
|
/* Set lowest possible timeout on SIGTERM */
|
||||||
|
ioctl(fd, WDIOC_SETTIMEOUT, &shutdown);
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user