• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* chvt.c - switch virtual terminals
2  *
3  * Copyright (C) 2008 David Anders <danders@amltd.com>
4 
5 USE_CHVT(NEWTOY(chvt, "<1", TOYFLAG_USR|TOYFLAG_BIN))
6 
7 config CHVT
8   bool "chvt"
9   default y
10   help
11     usage: chvt N
12 
13     Change to virtual terminal number N. (This only works in text mode.)
14 
15     Virtual terminals are the Linux VGA text mode displays, ordinarily
16     switched between via alt-F1, alt-F2, etc. Use ctrl-alt-F1 to switch
17     from X to a virtual terminal, and alt-F6 (or F7, or F8) to get back.
18 */
19 
20 #include "toys.h"
21 
chvt_main(void)22 void chvt_main(void)
23 {
24   int vtnum, fd = fd;
25   char *consoles[]={"/dev/console", "/dev/vc/0", "/dev/tty", NULL}, **cc;
26 
27   vtnum=atoi(*toys.optargs);
28   for (cc = consoles; *cc; cc++)
29     if (-1 != (fd = open(*cc, O_RDWR))) break;
30 
31   // These numbers are VT_ACTIVATE and VT_WAITACTIVE from linux/vt.h
32   if (!*cc || fd < 0 || ioctl(fd, 0x5606, vtnum) || ioctl(fd, 0x5607, vtnum))
33     perror_exit(0);
34 }
35