⬢ DragonFlyBSD Kernel Audit
DF-5324 / kbdsetup.c
← back to finding ↓ download raw
/* kbdsetup.c - unclaim ukbd from kbdmux and bind syscons to it directly. */
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/kbio.h>
#include <sys/consio.h>

int
main(int argc, char **argv)
{
	keyboard_info_t ki;
	int fd, idx = argc > 1 ? atoi(argv[1]) : 2;

	fd = open("/dev/consolectl", O_RDWR);
	if (fd < 0) { perror("consolectl"); return 1; }

	/* 1. release ukbd0 from kbdmux0 (forwarded via syscons -> mux) */
	memset(&ki, 0, sizeof(ki));
	strcpy(ki.kb_name, "ukbd");
	ki.kb_unit = 0;
	if (ioctl(fd, KBRELKBD, &ki) < 0)
		perror("KBRELKBD");

	/* 2. bind syscons to the ukbd (kbd index given) */
	if (ioctl(fd, CONS_SETKBD, &idx) < 0)
		perror("CONS_SETKBD");
	else
		printf("bound kbd%d\n", idx);
	return 0;
}