aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--miscutils/watchdog.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/miscutils/watchdog.c b/miscutils/watchdog.c
index 95e2f1a53..d379a97f4 100644
--- a/miscutils/watchdog.c
+++ b/miscutils/watchdog.c
@@ -35,8 +35,21 @@
35//usage: "\nUse 500ms to specify period in milliseconds" 35//usage: "\nUse 500ms to specify period in milliseconds"
36 36
37#include "libbb.h" 37#include "libbb.h"
38#include "linux/types.h" /* for __u32 */ 38#include <linux/types.h> /* for __u32 */
39#include "linux/watchdog.h" 39#include <linux/watchdog.h>
40
41#ifndef WDIOC_SETOPTIONS
42# define WDIOC_SETOPTIONS 0x5704
43#endif
44#ifndef WDIOC_SETTIMEOUT
45# define WDIOC_SETTIMEOUT 0x5706
46#endif
47#ifndef WDIOC_GETTIMEOUT
48# define WDIOC_GETTIMEOUT 0x5707
49#endif
50#ifndef WDIOS_ENABLECARD
51# define WDIOS_ENABLECARD 2
52#endif
40 53
41#define OPT_FOREGROUND (1 << 0) 54#define OPT_FOREGROUND (1 << 0)
42#define OPT_STIMER (1 << 1) 55#define OPT_STIMER (1 << 1)
@@ -73,8 +86,9 @@ static void watchdog_open(const char* device)
73} 86}
74 87
75int watchdog_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 88int watchdog_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
76int watchdog_main(int argc, char **argv) 89int watchdog_main(int argc UNUSED_PARAM, char **argv)
77{ 90{
91 static const int enable = WDIOS_ENABLECARD;
78 static const struct suffix_mult suffixes[] = { 92 static const struct suffix_mult suffixes[] = {
79 { "ms", 1 }, 93 { "ms", 1 },
80 { "", 1000 }, 94 { "", 1000 },
@@ -99,6 +113,8 @@ int watchdog_main(int argc, char **argv)
99 if (!(opts & OPT_FOREGROUND)) 113 if (!(opts & OPT_FOREGROUND))
100 bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv); 114 bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
101 115
116 /* maybe bb_logenv_override(); here for LOGGING=syslog to work? */
117
102 if (opts & OPT_HTIMER) 118 if (opts & OPT_HTIMER)
103 htimer_duration = xatou_sfx(ht_arg, suffixes); 119 htimer_duration = xatou_sfx(ht_arg, suffixes);
104 stimer_duration = htimer_duration / 2; 120 stimer_duration = htimer_duration / 2;
@@ -107,22 +123,12 @@ int watchdog_main(int argc, char **argv)
107 123
108 bb_signals(BB_FATAL_SIGS, shutdown_on_signal); 124 bb_signals(BB_FATAL_SIGS, shutdown_on_signal);
109 125
110 watchdog_open(argv[argc - 1]); 126 watchdog_open(argv[optind]);
111 127
112 /* WDIOC_SETTIMEOUT takes seconds, not milliseconds */ 128 /* WDIOC_SETTIMEOUT takes seconds, not milliseconds */
113 htimer_duration = htimer_duration / 1000; 129 htimer_duration = htimer_duration / 1000;
114#ifndef WDIOC_SETTIMEOUT 130 ioctl_or_warn(3, WDIOC_SETOPTIONS, (void*) &enable);
115# error WDIOC_SETTIMEOUT is not defined, cannot compile watchdog applet
116#else
117# if defined WDIOC_SETOPTIONS && defined WDIOS_ENABLECARD
118 {
119 static const int enable = WDIOS_ENABLECARD;
120 ioctl_or_warn(3, WDIOC_SETOPTIONS, (void*) &enable);
121 }
122# endif
123 ioctl_or_warn(3, WDIOC_SETTIMEOUT, &htimer_duration); 131 ioctl_or_warn(3, WDIOC_SETTIMEOUT, &htimer_duration);
124#endif
125
126#if 0 132#if 0
127 ioctl_or_warn(3, WDIOC_GETTIMEOUT, &htimer_duration); 133 ioctl_or_warn(3, WDIOC_GETTIMEOUT, &htimer_duration);
128 printf("watchdog: SW timer is %dms, HW timer is %ds\n", 134 printf("watchdog: SW timer is %dms, HW timer is %ds\n",