blob: 8ea062cde55c22e8ac2bc243751b1bc68c05f6be [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/*
Eric Andersen28672dd2003-10-22 10:30:53 +00003 * Mini chvt implementation for busybox
Eric Andersen0460ff21999-10-25 23:32:44 +00004 *
Eric Andersen28672dd2003-10-22 10:30:53 +00005 * Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Eric Andersen0460ff21999-10-25 23:32:44 +000020 */
Mark Whitley827e45c2001-03-09 23:59:51 +000021
Eric Andersen28672dd2003-10-22 10:30:53 +000022/* no options, no getopt */
Mark Whitley827e45c2001-03-09 23:59:51 +000023
Eric Andersen0460ff21999-10-25 23:32:44 +000024#include <stdio.h>
25#include <stdlib.h>
26#include <fcntl.h>
Eric Andersenbd22ed82000-07-08 18:55:24 +000027#include <sys/types.h>
28#include <sys/ioctl.h>
Eric Andersencbe31da2001-02-20 06:14:08 +000029#include "busybox.h"
Eric Andersenbd22ed82000-07-08 18:55:24 +000030
31/* From <linux/vt.h> */
Mark Whitley59ab0252001-01-23 22:30:04 +000032static const int VT_ACTIVATE = 0x5606; /* make vt active */
33static const int VT_WAITACTIVE = 0x5607; /* wait for vt active */
Eric Andersenbd22ed82000-07-08 18:55:24 +000034
Erik Andersene49d5ec2000-02-08 19:58:47 +000035int chvt_main(int argc, char **argv)
Eric Andersen0460ff21999-10-25 23:32:44 +000036{
Erik Andersene49d5ec2000-02-08 19:58:47 +000037 int fd, num;
Eric Andersen0460ff21999-10-25 23:32:44 +000038
Glenn L McGrath6a786312004-01-14 07:34:37 +000039 if (argc != 2) {
Manuel Novoa III cad53642003-03-19 09:13:01 +000040 bb_show_usage();
Eric Andersen28672dd2003-10-22 10:30:53 +000041 }
42
Eric Andersenc38678d2002-09-16 06:22:25 +000043 fd = get_console_fd();
Glenn L McGrath6a786312004-01-14 07:34:37 +000044 num = bb_xgetlarg(argv[1], 10, 0, INT_MAX);
Eric Andersen28672dd2003-10-22 10:30:53 +000045 if (ioctl(fd, VT_ACTIVATE, num)) {
Manuel Novoa III cad53642003-03-19 09:13:01 +000046 bb_perror_msg_and_die("VT_ACTIVATE");
Eric Andersen28672dd2003-10-22 10:30:53 +000047 }
48 if (ioctl(fd, VT_WAITACTIVE, num)) {
Manuel Novoa III cad53642003-03-19 09:13:01 +000049 bb_perror_msg_and_die("VT_WAITACTIVE");
Eric Andersen28672dd2003-10-22 10:30:53 +000050 }
Matt Kraai3e856ce2000-12-01 02:55:13 +000051 return EXIT_SUCCESS;
Eric Andersen0460ff21999-10-25 23:32:44 +000052}
Erik Andersen029011b2000-03-04 21:19:32 +000053
54
55/*
56Local Variables:
57c-file-style: "linux"
58c-basic-offset: 4
59tab-width: 4
60End:
61*/