RFC: watchdog

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

As far as I know, there is no enough popular tool to inspect the
current status of /dev/watchdog. watchdog device provides ioctl
commands to return timeout value and timeleft value. The tool
I assume is reports the values for given device.

/sys/class/watchdog is provided. However, whether it
is available or not is up to kernel build-configuration.

How do you think about adding such tool to util-linux?
Do you think such command should be in a separate project?
If the answer is yes, what command name do you prefer to for
the command? ("watchdog" is not good name).

If the answer is no, could you tell me a project or person
I should talk to about this command?

I attached a prototype.

Masatake YAMATO

/* catdog.c
 * No copyright is claimed.  This code is in the public domain; do with
 * it what you wish. */

#include <stdio.h>
#include <stdlib.h>
#include <error.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/watchdog.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

static void
usage(char *program, int status, FILE *fp)
{
	fprintf(fp, "Usage: ");
	fprintf(fp, "	%s DEVICE", program);
	exit(status);
}

int
main(int argc, char **argv)
{
	if (argc < 2)
		usage(argv[0], 1, stderr);
	int fd;

	if (strcmp(argv[1], "-h") == 0
	    || strcmp(argv[1], "-?") == 0
	    || strcmp(argv[1], "--help") == 0)
		usage(argv[0], 0, stdout);

	/* TODO: Check the major number */
	fd = open(argv[1], O_RDONLY);
	if (fd < 0)
		error(1, errno, "cannot open the watchdog device: %s", argv[1]);

	int p = 0;
	unsigned int q;
	if (ioctl(fd, WDIOC_GETSTATUS, &q) < 0)
		perror ("Error in GETSTATUS");
	else
		printf("BOOTSTATUS: %u\n", q);

	if (ioctl(fd, WDIOC_GETBOOTSTATUS, &p) < 0)
		perror ("Error in GETBOOTSTATUS");
	else
		printf("BOOTSTATUS: %d\n", p);	

	if (ioctl(fd, WDIOC_GETTIMEOUT, &p) < 0)
		perror ("Error in GETTIMEOUT");
	else
		printf("TIMEOUT: %d\n", p);

	if (ioctl(fd, WDIOC_GETTIMELEFT, &p) < 0)
		perror ("Error in GETTIMELEFT");
	else
		printf("TIMELEFT: %d\n", p);

	return 0;
}
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux