/*
 * kbdprobe.c - DF-4297 helper: probe whether /dev/kbdN is openable.
 * O_NONBLOCK open + read must fail with EWOULDBLOCK (genkbdread
 * kbd.c:745-748) if the keyboard is free; EBUSY means still mux-held.
 */
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

int
main(int argc, char **argv)
{
	char b[4];
	int fd, n, err;

	if (argc != 2)
		return (2);
	fd = open(argv[1], O_RDONLY | O_NONBLOCK);
	if (fd < 0) {
		printf("%s: open: %s\n", argv[1], strerror(errno));
		return (1);
	}
	n = read(fd, b, sizeof(b));
	err = errno;
	printf("%s: open OK, read -> %d errno=%d (%s)\n", argv[1], n, err,
	       strerror(err));
	close(fd);
	return (0);
}
