diff options
author | Devendra Naga <devendra.aaru@gmail.com> | 2012-05-17 05:37:48 -0400 |
---|---|---|
committer | Wim Van Sebroeck <wim@iguana.be> | 2012-05-23 10:27:48 -0400 |
commit | cad19fa66469d2a745fae0c168833d5d33d64489 (patch) | |
tree | 0621fd18462f9308fc0c66543d05b756a3d51557 /Documentation/watchdog | |
parent | 3c2a6186c1a69d647e3a48ad3f7f9078c451111e (diff) |
Documentation/watchdog: Fix the file descriptor leak when no cmdline arg given
we start a infinite loop when user gives ./watchdog-test, and when user
ctrl + c's the program, we just exit immeadiately with out closing the
filedescriptor of the watchdog device. a signal handler is used to
do the job of closing the filedescriptor and exiting the program.
Signed-off-by: Devendra Naga <devendra.aaru@gmail.com>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
Diffstat (limited to 'Documentation/watchdog')
-rw-r--r-- | Documentation/watchdog/src/watchdog-test.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Documentation/watchdog/src/watchdog-test.c b/Documentation/watchdog/src/watchdog-test.c index 23084f221279..73ff5cc93e05 100644 --- a/Documentation/watchdog/src/watchdog-test.c +++ b/Documentation/watchdog/src/watchdog-test.c | |||
@@ -7,6 +7,7 @@ | |||
7 | #include <string.h> | 7 | #include <string.h> |
8 | #include <unistd.h> | 8 | #include <unistd.h> |
9 | #include <fcntl.h> | 9 | #include <fcntl.h> |
10 | #include <signal.h> | ||
10 | #include <sys/ioctl.h> | 11 | #include <sys/ioctl.h> |
11 | #include <linux/types.h> | 12 | #include <linux/types.h> |
12 | #include <linux/watchdog.h> | 13 | #include <linux/watchdog.h> |
@@ -29,6 +30,14 @@ static void keep_alive(void) | |||
29 | * The main program. Run the program with "-d" to disable the card, | 30 | * The main program. Run the program with "-d" to disable the card, |
30 | * or "-e" to enable the card. | 31 | * or "-e" to enable the card. |
31 | */ | 32 | */ |
33 | |||
34 | void term(int sig) | ||
35 | { | ||
36 | close(fd); | ||
37 | fprintf(stderr, "Stopping watchdog ticks...\n"); | ||
38 | exit(0); | ||
39 | } | ||
40 | |||
32 | int main(int argc, char *argv[]) | 41 | int main(int argc, char *argv[]) |
33 | { | 42 | { |
34 | int flags; | 43 | int flags; |
@@ -65,6 +74,8 @@ int main(int argc, char *argv[]) | |||
65 | fflush(stderr); | 74 | fflush(stderr); |
66 | } | 75 | } |
67 | 76 | ||
77 | signal(SIGINT, term); | ||
78 | |||
68 | while(1) { | 79 | while(1) { |
69 | keep_alive(); | 80 | keep_alive(); |
70 | sleep(1); | 81 | sleep(1); |