aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-09-07 23:22:08 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-09-07 23:22:08 +0000
commit8d89bed8401bfbca9c5ef18f201439b3502e733b (patch)
treeb5db7bd373d32b4891610cd2c58f6307d4808447 /miscutils
parentee9deb863e089e1b607cc5771123257c3223bea0 (diff)
downloadbusybox-w32-8d89bed8401bfbca9c5ef18f201439b3502e733b.tar.gz
busybox-w32-8d89bed8401bfbca9c5ef18f201439b3502e733b.tar.bz2
busybox-w32-8d89bed8401bfbca9c5ef18f201439b3502e733b.zip
watchdog: add -T option
function old new delta watchdog_main 159 219 +60 mdev: support match by major,minor. See bug 4714. +100 bytes.
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/watchdog.c59
1 files changed, 33 insertions, 26 deletions
diff --git a/miscutils/watchdog.c b/miscutils/watchdog.c
index 9b1a110ea..e102a598a 100644
--- a/miscutils/watchdog.c
+++ b/miscutils/watchdog.c
@@ -4,14 +4,17 @@
4 * 4 *
5 * Copyright (C) 2003 Paul Mundt <lethal@linux-sh.org> 5 * Copyright (C) 2003 Paul Mundt <lethal@linux-sh.org>
6 * Copyright (C) 2006 Bernhard Fischer <busybox@busybox.net> 6 * Copyright (C) 2006 Bernhard Fischer <busybox@busybox.net>
7 * Copyright (C) 2008 Darius Augulis <augulis.darius@gmail.com>
7 * 8 *
8 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. 9 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
9 */ 10 */
10 11
11#include "libbb.h" 12#include "libbb.h"
13#include "linux/watchdog.h"
12 14
13#define OPT_FOREGROUND 0x01 15#define OPT_FOREGROUND (1 << 0)
14#define OPT_TIMER 0x02 16#define OPT_STIMER (1 << 1)
17#define OPT_HTIMER (1 << 2)
15 18
16static void watchdog_shutdown(int sig UNUSED_PARAM) 19static void watchdog_shutdown(int sig UNUSED_PARAM)
17{ 20{
@@ -26,38 +29,42 @@ static void watchdog_shutdown(int sig UNUSED_PARAM)
26int watchdog_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 29int watchdog_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
27int watchdog_main(int argc, char **argv) 30int watchdog_main(int argc, char **argv)
28{ 31{
29 unsigned opts; 32 static const struct suffix_mult suffixes[] = {
30 unsigned timer_duration = 30000; /* Userspace timer duration, in milliseconds */ 33 { "ms", 1 },
31 char *t_arg; 34 { "", 1000 },
35 { }
36 };
32 37
33 opt_complementary = "=1"; /* must have 1 argument */ 38 unsigned opts;
34 opts = getopt32(argv, "Ft:", &t_arg); 39 unsigned stimer_duration; /* how often to restart */
40 unsigned htimer_duration = 60000; /* reboots after N ms if not restarted */
41 char *st_arg;
42 char *ht_arg;
35 43
36 if (opts & OPT_TIMER) { 44 opt_complementary = "=1"; /* must have exactly 1 argument */
37 static const struct suffix_mult suffixes[] = { 45 opts = getopt32(argv, "Ft:T:", &st_arg, &ht_arg);
38 { "ms", 1 },
39 { "", 1000 },
40 { }
41 };
42 timer_duration = xatou_sfx(t_arg, suffixes);
43 }
44 46
45 if (!(opts & OPT_FOREGROUND)) { 47 if (opts & OPT_HTIMER)
46 bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv); 48 htimer_duration = xatou_sfx(ht_arg, suffixes);
47 } 49 stimer_duration = htimer_duration / 2;
50 if (opts & OPT_STIMER)
51 stimer_duration = xatou_sfx(st_arg, suffixes);
48 52
49 bb_signals(BB_FATAL_SIGS, watchdog_shutdown); 53 bb_signals(BB_FATAL_SIGS, watchdog_shutdown);
50 54
51 /* Use known fd # - avoid needing global 'int fd' */ 55 /* Use known fd # - avoid needing global 'int fd' */
52 xmove_fd(xopen(argv[argc - 1], O_WRONLY), 3); 56 xmove_fd(xopen(argv[argc - 1], O_WRONLY), 3);
53 57
54// TODO? 58 ioctl_or_warn(3, WDIOC_SETTIMEOUT, &htimer_duration);
55// if (!(opts & OPT_TIMER)) { 59#if 0
56// if (ioctl(fd, WDIOC_GETTIMEOUT, &timer_duration) == 0) 60 ioctl_or_warn(3, WDIOC_GETTIMEOUT, &htimer_duration);
57// timer_duration *= 500; 61 printf("watchdog: SW timer is %dms, HW timer is %dms\n",
58// else 62 stimer_duration, htimer_duration * 1000);
59// timer_duration = 30000; 63#endif
60// } 64
65 if (!(opts & OPT_FOREGROUND)) {
66 bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
67 }
61 68
62 while (1) { 69 while (1) {
63 /* 70 /*
@@ -65,7 +72,7 @@ int watchdog_main(int argc, char **argv)
65 * is undefined at this point -- PFM 72 * is undefined at this point -- PFM
66 */ 73 */
67 write(3, "", 1); /* write zero byte */ 74 write(3, "", 1); /* write zero byte */
68 usleep(timer_duration * 1000L); 75 usleep(stimer_duration * 1000L);
69 } 76 }
70 return EXIT_SUCCESS; /* - not reached, but gcc 4.2.1 is too dumb! */ 77 return EXIT_SUCCESS; /* - not reached, but gcc 4.2.1 is too dumb! */
71} 78}