aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-03-14 21:55:41 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-03-14 21:55:41 +0000
commit9cdc2646428b49f80afbd52673b386026c9ded4c (patch)
treeee4de7e566ac86b212648b69aa1bf57e6007761b
parent94506af280c97f96fc8563d7632cdddac88710a4 (diff)
downloadbusybox-w32-9cdc2646428b49f80afbd52673b386026c9ded4c.tar.gz
busybox-w32-9cdc2646428b49f80afbd52673b386026c9ded4c.tar.bz2
busybox-w32-9cdc2646428b49f80afbd52673b386026c9ded4c.zip
watchdog: don't use static variable
git-svn-id: svn://busybox.net/trunk/busybox@18107 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--miscutils/watchdog.c18
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 */ 16static void watchdog_shutdown(int ATTRIBUTE_UNUSED sig) ATTRIBUTE_NORETURN;
17static int fd; 17static void watchdog_shutdown(int ATTRIBUTE_UNUSED sig)
18
19static 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}