linux-watchdog.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Devendra Naga <devendra.aaru@gmail.com>
To: Wim Van Sebroeck <wim@iguana.be>, Rob Landley <rob@landley.net>,
	Devendra Naga <devendra.aaru@gmail.com>,
	linux-watchdog@vger.kernel.org, linux-doc@vger.kernel.org
Subject: [PATCH] Documentation/watchdog: Fix the file descriptor leak when no cmdline arg given
Date: Thu, 17 May 2012 15:07:48 +0530	[thread overview]
Message-ID: <1337247468-28125-1-git-send-email-devendra.aaru@gmail.com> (raw)

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>
---
 Documentation/watchdog/src/watchdog-test.c |   11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/Documentation/watchdog/src/watchdog-test.c b/Documentation/watchdog/src/watchdog-test.c
index 23084f2..73ff5cc 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);
-- 
1.7.9.5


             reply	other threads:[~2012-05-17  9:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-17  9:37 Devendra Naga [this message]
  -- strict thread matches above, loose matches on Subject: below --
2012-05-17  9:36 [PATCH] Documentation/watchdog: Fix the file descriptor leak when no cmdline arg given Devendra Naga
2012-05-17 14:13 ` Rob Landley
2012-05-17 14:33   ` devendra.aaru

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1337247468-28125-1-git-send-email-devendra.aaru@gmail.com \
    --to=devendra.aaru@gmail.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=rob@landley.net \
    --cc=wim@iguana.be \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).