diff options
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/watchdog.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/miscutils/watchdog.c b/miscutils/watchdog.c index 9dbefb985..ed9026d9e 100644 --- a/miscutils/watchdog.c +++ b/miscutils/watchdog.c | |||
| @@ -13,13 +13,12 @@ | |||
| 13 | #define OPT_FOREGROUND 0x01 | 13 | #define OPT_FOREGROUND 0x01 |
| 14 | #define OPT_TIMER 0x02 | 14 | #define OPT_TIMER 0x02 |
| 15 | 15 | ||
| 16 | /* Watchdog file descriptor */ | 16 | static void watchdog_shutdown(int ATTRIBUTE_UNUSED sig) ATTRIBUTE_NORETURN; |
| 17 | static int fd; | 17 | static void watchdog_shutdown(int ATTRIBUTE_UNUSED sig) |
| 18 | |||
| 19 | static void watchdog_shutdown(int ATTRIBUTE_UNUSED unused) | ||
| 20 | { | 18 | { |
| 21 | write(fd, "V", 1); /* Magic, see watchdog-api.txt in kernel */ | 19 | write(3, "V", 1); /* Magic, see watchdog-api.txt in kernel */ |
| 22 | close(fd); | 20 | if (ENABLE_FEATURE_CLEAN_UP) |
| 21 | close(3); | ||
| 23 | exit(0); | 22 | exit(0); |
| 24 | } | 23 | } |
| 25 | 24 | ||
| @@ -49,18 +48,19 @@ int watchdog_main(int argc, char **argv) | |||
| 49 | signal(SIGHUP, watchdog_shutdown); | 48 | signal(SIGHUP, watchdog_shutdown); |
| 50 | signal(SIGINT, watchdog_shutdown); | 49 | signal(SIGINT, watchdog_shutdown); |
| 51 | 50 | ||
| 52 | fd = xopen(argv[argc - 1], O_WRONLY); | 51 | /* Use known fd # - avoid needing global 'int fd' */ |
| 52 | dup2(xopen(argv[argc - 1], O_WRONLY), 3); | ||
| 53 | 53 | ||
| 54 | while (1) { | 54 | while (1) { |
| 55 | /* | 55 | /* |
| 56 | * Make sure we clear the counter before sleeping, as the counter value | 56 | * Make sure we clear the counter before sleeping, as the counter value |
| 57 | * is undefined at this point -- PFM | 57 | * is undefined at this point -- PFM |
| 58 | */ | 58 | */ |
| 59 | write(fd, "\0", 1); | 59 | write(3, "", 1); |
| 60 | sleep(timer_duration); | 60 | sleep(timer_duration); |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | watchdog_shutdown(0); | 63 | watchdog_shutdown(0); |
| 64 | 64 | ||
| 65 | return EXIT_SUCCESS; | 65 | /* return EXIT_SUCCESS; */ |
| 66 | } | 66 | } |
