2014-06-30 15:50:29 +00:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
2014-06-30 18:03:41 +00:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2014-06-30 15:50:29 +00:00
|
|
|
#include <fcntl.h>
|
2015-09-07 10:21:26 +00:00
|
|
|
#include <limits.h>
|
2013-08-15 11:54:40 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2014-06-30 15:50:29 +00:00
|
|
|
#include <unistd.h>
|
2014-06-30 18:03:41 +00:00
|
|
|
|
2013-08-15 11:54:40 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
2013-08-19 15:27:21 +00:00
|
|
|
#define KDGKBTYPE 0x4B33 /* get keyboard type */
|
|
|
|
|
|
|
|
#define VT_ACTIVATE 0x5606 /* make vt active */
|
|
|
|
#define VT_WAITACTIVE 0x5607 /* wait for vt active */
|
|
|
|
|
2015-09-07 10:21:26 +00:00
|
|
|
static char *vt[] = {
|
2013-08-15 11:54:40 +00:00
|
|
|
"/proc/self/fd/0",
|
|
|
|
"/dev/console",
|
|
|
|
"/dev/tty",
|
|
|
|
"/dev/tty0",
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2015-09-07 10:21:26 +00:00
|
|
|
eprintf("usage: %s num\n", argv0);
|
2013-08-15 11:54:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2013-10-07 19:41:30 +00:00
|
|
|
main(int argc, char *argv[])
|
2013-08-15 11:54:40 +00:00
|
|
|
{
|
2014-02-14 13:52:04 +00:00
|
|
|
unsigned int n, i;
|
|
|
|
int fd;
|
2013-08-15 11:54:40 +00:00
|
|
|
char c;
|
|
|
|
|
2015-02-02 18:56:17 +00:00
|
|
|
ARGBEGIN {
|
2015-09-07 10:21:26 +00:00
|
|
|
default:
|
|
|
|
usage();
|
2015-02-02 18:56:17 +00:00
|
|
|
} ARGEND;
|
|
|
|
|
2015-09-07 10:21:26 +00:00
|
|
|
if (argc != 1)
|
2013-08-15 11:54:40 +00:00
|
|
|
usage();
|
|
|
|
|
2015-09-07 10:21:26 +00:00
|
|
|
n = estrtonum(argv[0], 0, UINT_MAX);
|
|
|
|
for (i = 0; i < LEN(vt); i++) {
|
|
|
|
if ((fd = open(vt[i], O_RDONLY)) < 0)
|
2013-08-15 11:54:40 +00:00
|
|
|
continue;
|
|
|
|
c = 0;
|
2014-06-30 15:50:29 +00:00
|
|
|
if (ioctl(fd, KDGKBTYPE, &c) == 0)
|
2015-09-07 10:21:26 +00:00
|
|
|
goto found;
|
|
|
|
if (close(fd) < 0)
|
|
|
|
eprintf("close %s:", vt[i]);
|
2013-08-15 11:54:40 +00:00
|
|
|
}
|
2015-09-07 10:21:26 +00:00
|
|
|
eprintf("no console found\n");
|
2013-08-15 11:54:40 +00:00
|
|
|
|
2015-09-07 10:21:26 +00:00
|
|
|
found:
|
2014-06-30 15:50:29 +00:00
|
|
|
if (ioctl(fd, VT_ACTIVATE, n) == -1)
|
2015-09-07 10:21:26 +00:00
|
|
|
eprintf("VT_ACTIVATE %u:", n);
|
2014-06-30 15:50:29 +00:00
|
|
|
if (ioctl(fd, VT_WAITACTIVE, n) == -1)
|
2015-09-07 10:21:26 +00:00
|
|
|
eprintf("VT_WAITACTIVE %u:", n);
|
|
|
|
if (close(fd) < 0)
|
|
|
|
eprintf("close %s:", vt[i]);
|
2013-08-15 11:54:40 +00:00
|
|
|
|
2014-10-02 22:45:25 +00:00
|
|
|
return 0;
|
2013-08-15 11:54:40 +00:00
|
|
|
}
|