Skip to content

Commit

Permalink
Documentation/watchdog: Fix the file descriptor leak when no cmdline …
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
Devendra Naga authored and Wim Van Sebroeck committed May 23, 2012
1 parent 3c2a618 commit cad19fa
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Documentation/watchdog/src/watchdog-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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;
Expand Down Expand Up @@ -65,6 +74,8 @@ int main(int argc, char *argv[])
fflush(stderr);
}

signal(SIGINT, term);

while(1) {
keep_alive();
sleep(1);
Expand Down

0 comments on commit cad19fa

Please sign in to comment.