1 /*
2 * open.c open a vt to run a new command (or shell).
3 *
4 * Copyright (c) 1994 by Jon Tombs <jon@gtex02.us.es>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12 #include "open.h"
13
14 const char *SWITCHTOversion = "switchto: 1.0 (c) Jon Tombs 1994";
15
16
17 int
main(int argc,char * argv[])18 main(int argc, char *argv[])
19 {
20
21 int fd;
22 int vtno = -1;
23
24
25 if (argc < 2)
26 usage(1);
27
28 vtno = (int) atol(argv[1]);
29
30 if (vtno < 0 || vtno > 63)
31 usage(2);
32
33 if ((fd = open("/dev/console",O_WRONLY,0)) < 0) {
34 perror("switchto: Can't open /dev/console\n");
35 return(3);
36 }
37
38
39 if (ioctl(fd, VT_ACTIVATE, vtno) < 0) {
40 fprintf(stderr, "switcho: Failed to select VT %d (%s)\n", vtno,
41 strerror(errno));
42 return(3);
43 }
44
45 /* wait to be really sure we have switched */
46 (void) ioctl(fd, VT_WAITACTIVE, vtno);
47
48 return 0;
49 }
50
51
usage(int stat)52 void usage(int stat)
53 {
54 fprintf(stderr,
55 "Usage: switchto vt_num\n");
56 exit (stat);
57 }
58
59
60