blob: c715e67ded859d60783983cc2ce96c85ab6ab687 [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 */
Eric Andersen3570a342000-09-25 21:45:58 +00007#include "busybox.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> */
Mark Whitley59ab0252001-01-23 22:30:04 +000015static const int VT_ACTIVATE = 0x5606; /* make vt active */
16static const int VT_WAITACTIVE = 0x5607; /* wait for vt active */
Eric Andersenbd22ed82000-07-08 18:55:24 +000017
Erik Andersene49d5ec2000-02-08 19:58:47 +000018int chvt_main(int argc, char **argv)
Eric Andersen0460ff21999-10-25 23:32:44 +000019{
Erik Andersene49d5ec2000-02-08 19:58:47 +000020 int fd, num;
Eric Andersen0460ff21999-10-25 23:32:44 +000021
Matt Kraai3bd8bd82000-07-14 23:28:47 +000022 if ((argc != 2) || (**(argv + 1) == '-'))
23 usage (chvt_usage);
Erik Andersene49d5ec2000-02-08 19:58:47 +000024 fd = get_console_fd("/dev/console");
25 num = atoi(argv[1]);
Matt Kraaiaefe5622000-12-14 05:44:36 +000026 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");
Matt Kraai3e856ce2000-12-01 02:55:13 +000030 return EXIT_SUCCESS;
Eric Andersen0460ff21999-10-25 23:32:44 +000031}
Erik Andersen029011b2000-03-04 21:19:32 +000032
33
34/*
35Local Variables:
36c-file-style: "linux"
37c-basic-offset: 4
38tab-width: 4
39End:
40*/