blob: aff66e007019632ec6be03cde4992fcceb5e1495 [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 *
Bernhard Reutner-Fischerb1629b12006-05-19 19:29:19 +00007 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Eric Andersen0460ff21999-10-25 23:32:44 +00008 */
Mark Whitley827e45c2001-03-09 23:59:51 +00009
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> */
Rob Landleybc68cd12006-03-10 19:22:06 +000018enum {
19 VT_ACTIVATE = 0x5606, /* make vt active */
20 VT_WAITACTIVE = 0x5607 /* wait for vt active */
21};
Eric Andersenbd22ed82000-07-08 18:55:24 +000022
Erik Andersene49d5ec2000-02-08 19:58:47 +000023int chvt_main(int argc, char **argv)
Eric Andersen0460ff21999-10-25 23:32:44 +000024{
Erik Andersene49d5ec2000-02-08 19:58:47 +000025 int fd, num;
Eric Andersen0460ff21999-10-25 23:32:44 +000026
Glenn L McGrath6a786312004-01-14 07:34:37 +000027 if (argc != 2) {
Manuel Novoa III cad53642003-03-19 09:13:01 +000028 bb_show_usage();
Eric Andersen28672dd2003-10-22 10:30:53 +000029 }
30
Eric Andersenc38678d2002-09-16 06:22:25 +000031 fd = get_console_fd();
Glenn L McGrath6a786312004-01-14 07:34:37 +000032 num = bb_xgetlarg(argv[1], 10, 0, INT_MAX);
Rob Landleyead19302006-03-10 23:16:25 +000033 if ((-1 == ioctl(fd, VT_ACTIVATE, num))
34 || (-1 == ioctl(fd, VT_WAITACTIVE, num))) {
Rob Landley9f0e00f2005-09-08 03:27:06 +000035 bb_perror_msg_and_die("ioctl");
Eric Andersen28672dd2003-10-22 10:30:53 +000036 }
Matt Kraai3e856ce2000-12-01 02:55:13 +000037 return EXIT_SUCCESS;
Eric Andersen0460ff21999-10-25 23:32:44 +000038}