diff options
| author | Rasmus Villemoes <rasmus.villemoes@prevas.dk> | 2021-04-06 10:14:53 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-04-13 16:05:27 +0200 |
| commit | 50a37459ff991cab97e7326490d0637ff1106cc8 (patch) | |
| tree | 009f8b5a0bcb9bdd0d1e509c1ad55af31341c413 /miscutils | |
| parent | 9c210f0efb1959895df237a96210a73253b5b9ed (diff) | |
| download | busybox-w32-50a37459ff991cab97e7326490d0637ff1106cc8.tar.gz busybox-w32-50a37459ff991cab97e7326490d0637ff1106cc8.tar.bz2 busybox-w32-50a37459ff991cab97e7326490d0637ff1106cc8.zip | |
watchdog: make open-write-close-open functionality a config knob
The behaviour introduced by commit 31c765081dc4 ("watchdog: stop
watchdog first on startup") causes warnings in the kernel log when the
nowayout feature is enabled:
[ 16.212184] watchdog: watchdog0: nowayout prevents watchdog being stopped!
[ 16.212196] watchdog: watchdog0: watchdog did not stop!
The latter may also appear by itself in case the watchdog is of the
type that cannot be stopped once started (e.g. the common
always-running gpio_wdt kind).
These warnings can be somewhat ominous and distracting, so allow
configuring whether to use this open-write-close-open sequence rather
than just open. Also saves a bit of .text when disabled:
function old new delta
shutdown_on_signal 31 58 +27
watchdog_main 339 306 -33
shutdown_watchdog 34 - -34
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/1 up/down: 27/-67) Total: -40 bytes
Make it default n:
- It's a workaround for one specific type of watchdog (and
that seems to be a defect in the kernel driver)
- Even when not enabled in busybox config, it can easily be
implemented outside busybox
- Code size
- Commit 31c765081dc4 should be considered a regression for all the
boards that now end up with KERN_CRIT warnings in dmesg.
- The author of that commit said "This use case is evidently rare, so
if it is indeed causing problems for other people I'd OK then I
understand whatever needs to be done." in the v1 thread.
Cc: Matt Spinler <mspinler@linux.vnet.ibm.com>
Cc: deweloper@wp.pl
Cc: tito <farmatito@tiscali.it>
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/watchdog.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/miscutils/watchdog.c b/miscutils/watchdog.c index 0ed10bcf1..44649cae6 100644 --- a/miscutils/watchdog.c +++ b/miscutils/watchdog.c | |||
| @@ -18,6 +18,21 @@ | |||
| 18 | //config: watchdog applet ever fails to write the magic character within a | 18 | //config: watchdog applet ever fails to write the magic character within a |
| 19 | //config: certain amount of time, the watchdog device assumes the system has | 19 | //config: certain amount of time, the watchdog device assumes the system has |
| 20 | //config: hung, and will cause the hardware to reboot. | 20 | //config: hung, and will cause the hardware to reboot. |
| 21 | //config: | ||
| 22 | //config:config FEATURE_WATCHDOG_OPEN_TWICE | ||
| 23 | //config: bool "Open watchdog device twice, closing it gracefully in between" | ||
| 24 | //config: depends on WATCHDOG | ||
| 25 | //config: default n # this behavior was essentially a hack for a broken driver | ||
| 26 | //config: help | ||
| 27 | //config: When enabled, the watchdog device is opened and then immediately | ||
| 28 | //config: magic-closed, before being opened a second time. This may be necessary | ||
| 29 | //config: for some watchdog devices, but can cause spurious warnings in the | ||
| 30 | //config: kernel log if the nowayout feature is enabled. Also, if this workaround | ||
| 31 | //config: is really needed for you machine to work properly, consider whether | ||
| 32 | //config: it should be fixed in the kernel driver instead. Even when disabled, | ||
| 33 | //config: the behaviour is easily emulated with a "printf 'V' > /dev/watchdog" | ||
| 34 | //config: immediately before starting the busybox watchdog daemon. Say n unless | ||
| 35 | //config: you know that you absolutely need this. | ||
| 21 | 36 | ||
| 22 | //applet:IF_WATCHDOG(APPLET(watchdog, BB_DIR_SBIN, BB_SUID_DROP)) | 37 | //applet:IF_WATCHDOG(APPLET(watchdog, BB_DIR_SBIN, BB_SUID_DROP)) |
| 23 | 38 | ||
| @@ -50,10 +65,6 @@ | |||
| 50 | # define WDIOS_ENABLECARD 2 | 65 | # define WDIOS_ENABLECARD 2 |
| 51 | #endif | 66 | #endif |
| 52 | 67 | ||
| 53 | #define OPT_FOREGROUND (1 << 0) | ||
| 54 | #define OPT_STIMER (1 << 1) | ||
| 55 | #define OPT_HTIMER (1 << 2) | ||
| 56 | |||
| 57 | static void shutdown_watchdog(void) | 68 | static void shutdown_watchdog(void) |
| 58 | { | 69 | { |
| 59 | static const char V = 'V'; | 70 | static const char V = 'V'; |
| @@ -73,6 +84,7 @@ static void watchdog_open(const char* device) | |||
| 73 | /* Use known fd # - avoid needing global 'int fd' */ | 84 | /* Use known fd # - avoid needing global 'int fd' */ |
| 74 | xmove_fd(xopen(device, O_WRONLY), 3); | 85 | xmove_fd(xopen(device, O_WRONLY), 3); |
| 75 | 86 | ||
| 87 | #if ENABLE_FEATURE_WATCHDOG_OPEN_TWICE | ||
| 76 | /* If the watchdog driver can do something other than cause a reboot | 88 | /* If the watchdog driver can do something other than cause a reboot |
| 77 | * on a timeout, then it's possible this program may be starting from | 89 | * on a timeout, then it's possible this program may be starting from |
| 78 | * a state when the watchdog hadn't been previously stopped with | 90 | * a state when the watchdog hadn't been previously stopped with |
| @@ -82,6 +94,7 @@ static void watchdog_open(const char* device) | |||
| 82 | shutdown_watchdog(); | 94 | shutdown_watchdog(); |
| 83 | 95 | ||
| 84 | xmove_fd(xopen(device, O_WRONLY), 3); | 96 | xmove_fd(xopen(device, O_WRONLY), 3); |
| 97 | #endif | ||
| 85 | } | 98 | } |
| 86 | 99 | ||
| 87 | int watchdog_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 100 | int watchdog_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| @@ -100,6 +113,9 @@ int watchdog_main(int argc UNUSED_PARAM, char **argv) | |||
| 100 | char *st_arg; | 113 | char *st_arg; |
| 101 | char *ht_arg; | 114 | char *ht_arg; |
| 102 | 115 | ||
| 116 | #define OPT_FOREGROUND (1 << 0) | ||
| 117 | #define OPT_STIMER (1 << 1) | ||
| 118 | #define OPT_HTIMER (1 << 2) | ||
| 103 | opts = getopt32(argv, "^" "Ft:T:" "\0" "=1"/*must have exactly 1 arg*/, | 119 | opts = getopt32(argv, "^" "Ft:T:" "\0" "=1"/*must have exactly 1 arg*/, |
| 104 | &st_arg, &ht_arg | 120 | &st_arg, &ht_arg |
| 105 | ); | 121 | ); |
| @@ -132,7 +148,7 @@ int watchdog_main(int argc UNUSED_PARAM, char **argv) | |||
| 132 | #if 0 | 148 | #if 0 |
| 133 | ioctl_or_warn(3, WDIOC_GETTIMEOUT, &htimer_duration); | 149 | ioctl_or_warn(3, WDIOC_GETTIMEOUT, &htimer_duration); |
| 134 | printf("watchdog: SW timer is %dms, HW timer is %ds\n", | 150 | printf("watchdog: SW timer is %dms, HW timer is %ds\n", |
| 135 | stimer_duration, htimer_duration * 1000); | 151 | stimer_duration, htimer_duration); |
| 136 | #endif | 152 | #endif |
| 137 | 153 | ||
| 138 | write_pidfile_std_path_and_ext("watchdog"); | 154 | write_pidfile_std_path_and_ext("watchdog"); |
