watchdog: fix running on new 4.1 kernel

This commit is contained in:
Benjamin Larsson 2018-06-15 15:47:30 +02:00
parent 082a0160a2
commit a6ac6ad76d

View file

@ -5,15 +5,22 @@
#include <unistd.h> #include <unistd.h>
const char *watchdog_file = "/proc/watchdog"; const char *watchdog_file = "/proc/watchdog";
const char *watchdog_file_nvram = "/proc/nvram/watchdog";
const char *init_string = "1 5000000 1 4"; const char *init_string = "1 5000000 1 4";
const char *kicker = "OK"; const char *kicker = "OK";
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int fd = open(watchdog_file, O_WRONLY); int ret = 0;
char *wdt_string_prt = watchdog_file;
int fd = open(wdt_string_prt, O_WRONLY);
if (fd < 0) { if (fd < 0) {
perror("Open watchdog file"); wdt_string_prt = watchdog_file_nvram;
exit(1); fd = open(wdt_string_prt, O_WRONLY);
if (fd < 0) {
perror("Open watchdog file");
exit(1);
}
} }
/* init */ /* init */
@ -23,14 +30,17 @@ int main(int argc, char **argv)
perror("Error init watchdog"); perror("Error init watchdog");
exit(1); exit(1);
} }
close(fd);
while (1) { while (1) {
fd = open(wdt_string_prt, O_WRONLY);
sleep(1); sleep(1);
res = write (fd, kicker, strlen(init_string) + 1); res = write (fd, kicker, strlen(init_string) + 1);
if (res < 0 ){ if (res < 0 ){
perror("Error kicking watchdog"); perror("Error kicking watchdog");
} }
close(fd);
} }
return 0; return 0;
} }