blob: 635022a57e4354f16c75b485cf3cc2281497567e [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Eric Andersen0460ff21999-10-25 23:32:44 +00002/*
3 * chvt.c - aeb - 940227 - Change virtual terminal
4 *
5 * busyboxed by Erik Andersen
6 */
7#include "internal.h"
8#include <sys/types.h>
9#include <sys/ioctl.h>
10#include <linux/vt.h>
11#include <stdio.h>
12#include <stdlib.h>
13#include <fcntl.h>
14
15extern int getfd(void);
16
Erik Andersene49d5ec2000-02-08 19:58:47 +000017int chvt_main(int argc, char **argv)
Eric Andersen0460ff21999-10-25 23:32:44 +000018{
Erik Andersene49d5ec2000-02-08 19:58:47 +000019 int fd, num;
Eric Andersen0460ff21999-10-25 23:32:44 +000020
Erik Andersene49d5ec2000-02-08 19:58:47 +000021 if ((argc != 2) || (**(argv + 1) == '-')) {
22 usage
23 ("chvt N\n\nChange foreground virtual terminal to /dev/ttyN\n");
24 }
25 fd = get_console_fd("/dev/console");
26 num = atoi(argv[1]);
27 if (ioctl(fd, VT_ACTIVATE, num)) {
28 perror("VT_ACTIVATE");
29 exit(FALSE);
30 }
31 if (ioctl(fd, VT_WAITACTIVE, num)) {
32 perror("VT_WAITACTIVE");
33 exit(FALSE);
34 }
35 exit(TRUE);
Eric Andersen0460ff21999-10-25 23:32:44 +000036}
Erik Andersen029011b2000-03-04 21:19:32 +000037
38
39/*
40Local Variables:
41c-file-style: "linux"
42c-basic-offset: 4
43tab-width: 4
44End:
45*/