aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-09-05 12:13:51 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-09-05 12:13:51 +0000
commit3638cc44629703585f29f4b7125da1e7b3a1aedc (patch)
tree52dbab8d922a2144715cd01497f48ced362a6bee
parent211f7f88ae67e875bed50409b2edbb6d740fc648 (diff)
downloadbusybox-w32-3638cc44629703585f29f4b7125da1e7b3a1aedc.tar.gz
busybox-w32-3638cc44629703585f29f4b7125da1e7b3a1aedc.tar.bz2
busybox-w32-3638cc44629703585f29f4b7125da1e7b3a1aedc.zip
watchdog: allow millisecond spec (-t 250ms)
function old new delta packed_usage 23069 23113 +44 static.suffixes - 24 +24 watchdog_main 147 160 +13 static.V - 1 +1 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 2/0 up/down: 82/0) Total: 82 bytes
-rw-r--r--include/usage.h12
-rw-r--r--miscutils/watchdog.c24
2 files changed, 22 insertions, 14 deletions
diff --git a/include/usage.h b/include/usage.h
index e062c0c02..6a88b6cf1 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -3843,7 +3843,7 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
3843#define watch_full_usage \ 3843#define watch_full_usage \
3844 "Execute a program periodically" \ 3844 "Execute a program periodically" \
3845 "\n\nOptions:\n" \ 3845 "\n\nOptions:\n" \
3846 " -n Loop period in seconds - default is 2\n" \ 3846 " -n Loop period in seconds (default 2)\n" \
3847 " -t Don't print header" 3847 " -t Don't print header"
3848#define watch_example_usage \ 3848#define watch_example_usage \
3849 "$ watch date\n" \ 3849 "$ watch date\n" \
@@ -3852,12 +3852,14 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
3852 "Mon Dec 17 10:31:44 GMT 2000" 3852 "Mon Dec 17 10:31:44 GMT 2000"
3853 3853
3854#define watchdog_trivial_usage \ 3854#define watchdog_trivial_usage \
3855 "[-t seconds] [-F] DEV" 3855 "[-t N[ms]] [-F] DEV"
3856#define watchdog_full_usage \ 3856#define watchdog_full_usage \
3857 "Periodically write to watchdog device DEV" \ 3857 "Periodically write to watchdog device DEV" \
3858 "\n\nOptions:\n" \ 3858 "\n\nOptions:" \
3859 " -t Timer period in seconds - default is 30\n" \ 3859 "\n -t N Timer period (default 30)" \
3860 " -F Stay in the foreground and don't fork" 3860 "\n -F Stay in the foreground and don't fork" \
3861 "\n" \
3862 "\nUse -t 500ms to specify period in milliseconds"
3861 3863
3862#define wc_trivial_usage \ 3864#define wc_trivial_usage \
3863 "[OPTION]... [FILE]..." 3865 "[OPTION]... [FILE]..."
diff --git a/miscutils/watchdog.c b/miscutils/watchdog.c
index aa367d5ab..14bd44f48 100644
--- a/miscutils/watchdog.c
+++ b/miscutils/watchdog.c
@@ -16,7 +16,9 @@
16static void watchdog_shutdown(int ATTRIBUTE_UNUSED sig) ATTRIBUTE_NORETURN; 16static void watchdog_shutdown(int ATTRIBUTE_UNUSED sig) ATTRIBUTE_NORETURN;
17static void watchdog_shutdown(int ATTRIBUTE_UNUSED sig) 17static void watchdog_shutdown(int ATTRIBUTE_UNUSED sig)
18{ 18{
19 write(3, "V", 1); /* Magic, see watchdog-api.txt in kernel */ 19 static const char V = 'V';
20
21 write(3, &V, 1); /* Magic, see watchdog-api.txt in kernel */
20 if (ENABLE_FEATURE_CLEAN_UP) 22 if (ENABLE_FEATURE_CLEAN_UP)
21 close(3); 23 close(3);
22 exit(0); 24 exit(0);
@@ -26,14 +28,20 @@ int watchdog_main(int argc, char **argv);
26int watchdog_main(int argc, char **argv) 28int watchdog_main(int argc, char **argv)
27{ 29{
28 unsigned opts; 30 unsigned opts;
29 unsigned timer_duration = 30; /* Userspace timer duration, in seconds */ 31 unsigned timer_duration = 30000; /* Userspace timer duration, in milliseconds */
30 char *t_arg; 32 char *t_arg;
31 33
32 opt_complementary = "=1"; /* must have 1 argument */ 34 opt_complementary = "=1"; /* must have 1 argument */
33 opts = getopt32(argv, "Ft:", &t_arg); 35 opts = getopt32(argv, "Ft:", &t_arg);
34 36
35 if (opts & OPT_TIMER) 37 if (opts & OPT_TIMER) {
36 timer_duration = xatou(t_arg); 38 static const struct suffix_mult suffixes[] = {
39 { "ms", 1 },
40 { "", 1000 },
41 { }
42 };
43 timer_duration = xatou_sfx(t_arg, suffixes);
44 }
37 45
38 if (!(opts & OPT_FOREGROUND)) { 46 if (!(opts & OPT_FOREGROUND)) {
39 bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv); 47 bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
@@ -50,10 +58,8 @@ int watchdog_main(int argc, char **argv)
50 * Make sure we clear the counter before sleeping, as the counter value 58 * Make sure we clear the counter before sleeping, as the counter value
51 * is undefined at this point -- PFM 59 * is undefined at this point -- PFM
52 */ 60 */
53 write(3, "", 1); 61 write(3, "", 1); /* write zero byte */
54 sleep(timer_duration); 62 usleep(timer_duration * 1000L);
55 } 63 }
56 64 return EXIT_SUCCESS; /* - not reached, but gcc 4.2.1 is too dumb! */
57 watchdog_shutdown(0);
58 /* return EXIT_SUCCESS; */
59} 65}