diff options
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 | } |