Commit cad19fa6 authored by Devendra Naga's avatar Devendra Naga Committed by Wim Van Sebroeck

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: default avatarDevendra Naga <devendra.aaru@gmail.com>
Signed-off-by: default avatarWim Van Sebroeck <wim@iguana.be>
parent 3c2a6186
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment