This patch, put together by Manuel Novoa III, is a merge of work
[platform/upstream/busybox.git] / console-tools / chvt.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * chvt.c - aeb - 940227 - Change virtual terminal
4  *
5  * busyboxed by Erik Andersen
6  */
7 #include "busybox.h"
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <fcntl.h>
11 #include <sys/types.h>
12 #include <sys/ioctl.h>
13
14 /* From <linux/vt.h> */
15 static const int VT_ACTIVATE = 0x5606;  /* make vt active */
16 static const int VT_WAITACTIVE = 0x5607;  /* wait for vt active */
17
18 int chvt_main(int argc, char **argv)
19 {
20         int fd, num;
21
22         if ((argc != 2) || (**(argv + 1) == '-'))
23                 show_usage();
24         fd = get_console_fd("/dev/console");
25         num = atoi(argv[1]);
26         if (ioctl(fd, VT_ACTIVATE, num))
27                 perror_msg_and_die("VT_ACTIVATE");
28         if (ioctl(fd, VT_WAITACTIVE, num))
29                 perror_msg_and_die("VT_WAITACTIVE");
30         return EXIT_SUCCESS;
31 }
32
33
34 /*
35 Local Variables:
36 c-file-style: "linux"
37 c-basic-offset: 4
38 tab-width: 4
39 End:
40 */