2013-08-15 11:54:40 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#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 */
|
|
|
|
|
2013-08-29 23:28:17 +00:00
|
|
|
static char *vts[] = {
|
2013-08-15 11:54:40 +00:00
|
|
|
"/proc/self/fd/0",
|
|
|
|
"/dev/console",
|
|
|
|
"/dev/tty",
|
|
|
|
"/dev/tty0",
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
eprintf("usage: chvt N\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if(argc!=2 || strspn(argv[1], "1234567890") != strlen(argv[1]))
|
|
|
|
usage();
|
|
|
|
|
|
|
|
n = atoi(argv[1]);
|
|
|
|
for(i = 0; i < LEN(vts); i++) {
|
|
|
|
fd = open(vts[i], O_RDONLY);
|
|
|
|
if(fd < 1)
|
|
|
|
continue;
|
|
|
|
c = 0;
|
|
|
|
if(ioctl(fd, KDGKBTYPE, &c) == 0)
|
|
|
|
goto VTfound;
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
2014-04-11 22:45:49 +00:00
|
|
|
eprintf("couldn't find a console.\n");
|
2013-08-15 11:54:40 +00:00
|
|
|
VTfound:
|
|
|
|
if(ioctl(fd, VT_ACTIVATE, n) == -1)
|
2014-04-11 22:45:49 +00:00
|
|
|
eprintf("VT_ACTIVATE %d:", n);
|
2013-08-15 11:54:40 +00:00
|
|
|
if(ioctl(fd, VT_WAITACTIVE, n) == -1)
|
2014-04-11 22:45:49 +00:00
|
|
|
eprintf("VT_WAITACTIVE %d:", n);
|
2013-08-15 11:54:40 +00:00
|
|
|
close(fd);
|
|
|
|
|
2013-10-07 18:11:40 +00:00
|
|
|
return EXIT_SUCCESS;
|
2013-08-15 11:54:40 +00:00
|
|
|
}
|