#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h>

#include <fcntl.h>

#include <linux/watchdog.h>

int main(int argc, char *argv[]) {
	int wdt_fd = open("/dev/watchdog0", O_WRONLY);
	if (wdt_fd == -1)
		err(1, "failed to open watchdog-file");

	int interval = 0;

	ioctl(wdt_fd, WDIOC_GETTIMEOUT, &interval);
	printf("current timeout: %ds\n", interval);

	interval = 30;
	printf("setting a new timeout to: %ds\n", interval);
	ioctl(wdt_fd, WDIOC_SETTIMEOUT, &interval);

	write(wdt_fd, "t", 1);

	ioctl(wdt_fd, WDIOC_GETTIMEOUT, &interval);
	printf("current timeout: %ds\n", interval);

	close(wdt_fd);

	return EXIT_SUCCESS;
}
