blob: c5c86b61331a66ce894054d30ccea5e844409ff7 [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"
Eric Andersen0460ff21999-10-25 23:32:44 +00008#include <stdio.h>
9#include <stdlib.h>
10#include <fcntl.h>
Eric Andersenbd22ed82000-07-08 18:55:24 +000011#include <sys/types.h>
12#include <sys/ioctl.h>
13
14/* From <linux/vt.h> */
15#define VT_ACTIVATE 0x5606 /* make vt active */
16#define VT_WAITACTIVE 0x5607 /* wait for vt active */
17
Eric Andersen0460ff21999-10-25 23:32:44 +000018
Erik Andersene49d5ec2000-02-08 19:58:47 +000019int chvt_main(int argc, char **argv)
Eric Andersen0460ff21999-10-25 23:32:44 +000020{
Erik Andersene49d5ec2000-02-08 19:58:47 +000021 int fd, num;
Eric Andersen0460ff21999-10-25 23:32:44 +000022
Erik Andersene49d5ec2000-02-08 19:58:47 +000023 if ((argc != 2) || (**(argv + 1) == '-')) {
Erik Andersen1d1d9502000-04-21 01:26:49 +000024 usage ("chvt N\n"
25#ifndef BB_FEATURE_TRIVIAL_HELP
26 "\nChanges the foreground virtual terminal to /dev/ttyN\n"
27#endif
28 );
Erik Andersene49d5ec2000-02-08 19:58:47 +000029 }
30 fd = get_console_fd("/dev/console");
31 num = atoi(argv[1]);
32 if (ioctl(fd, VT_ACTIVATE, num)) {
33 perror("VT_ACTIVATE");
34 exit(FALSE);
35 }
36 if (ioctl(fd, VT_WAITACTIVE, num)) {
37 perror("VT_WAITACTIVE");
38 exit(FALSE);
39 }
Eric Andersenb6106152000-06-19 17:25:40 +000040 return(TRUE);
Eric Andersen0460ff21999-10-25 23:32:44 +000041}
Erik Andersen029011b2000-03-04 21:19:32 +000042
43
44/*
45Local Variables:
46c-file-style: "linux"
47c-basic-offset: 4
48tab-width: 4
49End:
50*/