Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Devendra Naga and committed by
Wim Van Sebroeck
cad19fa6 3c2a6186

+11
+11
Documentation/watchdog/src/watchdog-test.c
··· 7 7 #include <string.h> 8 8 #include <unistd.h> 9 9 #include <fcntl.h> 10 + #include <signal.h> 10 11 #include <sys/ioctl.h> 11 12 #include <linux/types.h> 12 13 #include <linux/watchdog.h> ··· 30 29 * The main program. Run the program with "-d" to disable the card, 31 30 * or "-e" to enable the card. 32 31 */ 32 + 33 + void term(int sig) 34 + { 35 + close(fd); 36 + fprintf(stderr, "Stopping watchdog ticks...\n"); 37 + exit(0); 38 + } 39 + 33 40 int main(int argc, char *argv[]) 34 41 { 35 42 int flags; ··· 73 64 fprintf(stderr, "Watchdog Ticking Away!\n"); 74 65 fflush(stderr); 75 66 } 67 + 68 + signal(SIGINT, term); 76 69 77 70 while(1) { 78 71 keep_alive();