summaryrefslogtreecommitdiffstats
path: root/Documentation/watchdog
diff options
context:
space:
mode:
authorDevendra Naga <devendra.aaru@gmail.com>2012-05-17 15:07:48 +0530
committerWim Van Sebroeck <wim@iguana.be>2012-05-23 16:27:48 +0200
commitcad19fa66469d2a745fae0c168833d5d33d64489 (patch)
tree0621fd18462f9308fc0c66543d05b756a3d51557 /Documentation/watchdog
parent3c2a6186c1a69d647e3a48ad3f7f9078c451111e (diff)
downloadlinux-stable-cad19fa66469d2a745fae0c168833d5d33d64489.tar.gz
linux-stable-cad19fa66469d2a745fae0c168833d5d33d64489.tar.bz2
linux-stable-cad19fa66469d2a745fae0c168833d5d33d64489.zip
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.c11
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 @@
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
+#include <signal.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/watchdog.h>
@@ -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);