From: Devendra Naga Date: Thu, 17 May 2012 09:37:48 +0000 (+0530) Subject: Documentation/watchdog: Fix the file descriptor leak when no cmdline arg given X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=cad19fa66469d2a745fae0c168833d5d33d64489;p=openwrt%2Fstaging%2Fblogic.git 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 Signed-off-by: Wim Van Sebroeck --- 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 @@ #include #include #include +#include #include #include #include @@ -29,6 +30,14 @@ static void keep_alive(void) * The main program. Run the program with "-d" to disable the card, * or "-e" to enable the card. */ + +void term(int sig) +{ + close(fd); + fprintf(stderr, "Stopping watchdog ticks...\n"); + exit(0); +} + int main(int argc, char *argv[]) { int flags; @@ -65,6 +74,8 @@ int main(int argc, char *argv[]) fflush(stderr); } + signal(SIGINT, term); + while(1) { keep_alive(); sleep(1);