blob: cba5b4014dd73a4ee24bb108d6dc5bd4e48cdbbb [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 Andersenc7bda1c2004-03-15 08:29:22 +00005 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
Eric Andersen28672dd2003-10-22 10:30:53 +00006 *
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> */
Rob Landleybc68cd12006-03-10 19:22:06 +000032enum {
33 VT_ACTIVATE = 0x5606, /* make vt active */
34 VT_WAITACTIVE = 0x5607 /* wait for vt active */
35};
Eric Andersenbd22ed82000-07-08 18:55:24 +000036
Erik Andersene49d5ec2000-02-08 19:58:47 +000037int chvt_main(int argc, char **argv)
Eric Andersen0460ff21999-10-25 23:32:44 +000038{
Erik Andersene49d5ec2000-02-08 19:58:47 +000039 int fd, num;
Eric Andersen0460ff21999-10-25 23:32:44 +000040
Glenn L McGrath6a786312004-01-14 07:34:37 +000041 if (argc != 2) {
Manuel Novoa III cad53642003-03-19 09:13:01 +000042 bb_show_usage();
Eric Andersen28672dd2003-10-22 10:30:53 +000043 }
44
Eric Andersenc38678d2002-09-16 06:22:25 +000045 fd = get_console_fd();
Glenn L McGrath6a786312004-01-14 07:34:37 +000046 num = bb_xgetlarg(argv[1], 10, 0, INT_MAX);
Rob Landleyead19302006-03-10 23:16:25 +000047 if ((-1 == ioctl(fd, VT_ACTIVATE, num))
48 || (-1 == ioctl(fd, VT_WAITACTIVE, num))) {
Rob Landley9f0e00f2005-09-08 03:27:06 +000049 bb_perror_msg_and_die("ioctl");
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*/