blob: 11e1078b7773999d8786fc015fadadfe59088366 [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 */
Mark Whitley827e45c2001-03-09 23:59:51 +00007
8/* getopt not needed */
9
Eric Andersen0460ff21999-10-25 23:32:44 +000010#include <stdio.h>
11#include <stdlib.h>
12#include <fcntl.h>
Eric Andersenbd22ed82000-07-08 18:55:24 +000013#include <sys/types.h>
14#include <sys/ioctl.h>
Eric Andersencbe31da2001-02-20 06:14:08 +000015#include "busybox.h"
Eric Andersenbd22ed82000-07-08 18:55:24 +000016
17/* From <linux/vt.h> */
Mark Whitley59ab0252001-01-23 22:30:04 +000018static const int VT_ACTIVATE = 0x5606; /* make vt active */
19static const int VT_WAITACTIVE = 0x5607; /* wait for vt active */
Eric Andersenbd22ed82000-07-08 18:55:24 +000020
Erik Andersene49d5ec2000-02-08 19:58:47 +000021int chvt_main(int argc, char **argv)
Eric Andersen0460ff21999-10-25 23:32:44 +000022{
Erik Andersene49d5ec2000-02-08 19:58:47 +000023 int fd, num;
Eric Andersen0460ff21999-10-25 23:32:44 +000024
Matt Kraai3bd8bd82000-07-14 23:28:47 +000025 if ((argc != 2) || (**(argv + 1) == '-'))
Manuel Novoa III cad53642003-03-19 09:13:01 +000026 bb_show_usage();
Eric Andersenc38678d2002-09-16 06:22:25 +000027 fd = get_console_fd();
Erik Andersene49d5ec2000-02-08 19:58:47 +000028 num = atoi(argv[1]);
Matt Kraaiaefe5622000-12-14 05:44:36 +000029 if (ioctl(fd, VT_ACTIVATE, num))
Manuel Novoa III cad53642003-03-19 09:13:01 +000030 bb_perror_msg_and_die("VT_ACTIVATE");
Matt Kraaiaefe5622000-12-14 05:44:36 +000031 if (ioctl(fd, VT_WAITACTIVE, num))
Manuel Novoa III cad53642003-03-19 09:13:01 +000032 bb_perror_msg_and_die("VT_WAITACTIVE");
Matt Kraai3e856ce2000-12-01 02:55:13 +000033 return EXIT_SUCCESS;
Eric Andersen0460ff21999-10-25 23:32:44 +000034}
Erik Andersen029011b2000-03-04 21:19:32 +000035
36
37/*
38Local Variables:
39c-file-style: "linux"
40c-basic-offset: 4
41tab-width: 4
42End:
43*/