diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-09-05 12:13:51 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-09-05 12:13:51 +0000 |
commit | 3638cc44629703585f29f4b7125da1e7b3a1aedc (patch) | |
tree | 52dbab8d922a2144715cd01497f48ced362a6bee /miscutils/watchdog.c | |
parent | 211f7f88ae67e875bed50409b2edbb6d740fc648 (diff) | |
download | busybox-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
Diffstat (limited to 'miscutils/watchdog.c')
-rw-r--r-- | miscutils/watchdog.c | 24 |
1 files changed, 15 insertions, 9 deletions
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 @@ | |||
16 | static void watchdog_shutdown(int ATTRIBUTE_UNUSED sig) ATTRIBUTE_NORETURN; | 16 | static void watchdog_shutdown(int ATTRIBUTE_UNUSED sig) ATTRIBUTE_NORETURN; |
17 | static void watchdog_shutdown(int ATTRIBUTE_UNUSED sig) | 17 | static 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); | |||
26 | int watchdog_main(int argc, char **argv) | 28 | int 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 | } |