blob: bbc5a9c31d1dd6bad85ca1575265bdbed4498044 [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 Andersencbe31da2001-02-20 06:14:08 +000010#include "busybox.h"
Eric Andersenbd22ed82000-07-08 18:55:24 +000011
12/* From <linux/vt.h> */
Rob Landleybc68cd12006-03-10 19:22:06 +000013enum {
14 VT_ACTIVATE = 0x5606, /* make vt active */
15 VT_WAITACTIVE = 0x5607 /* wait for vt active */
16};
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
Glenn L McGrath6a786312004-01-14 07:34:37 +000022 if (argc != 2) {
Manuel Novoa III cad53642003-03-19 09:13:01 +000023 bb_show_usage();
Eric Andersen28672dd2003-10-22 10:30:53 +000024 }
25
Eric Andersenc38678d2002-09-16 06:22:25 +000026 fd = get_console_fd();
Denis Vlasenko13858992006-10-08 12:49:22 +000027 num = xatoul_range(argv[1], 1, 63);
Rob Landleyead19302006-03-10 23:16:25 +000028 if ((-1 == ioctl(fd, VT_ACTIVATE, num))
29 || (-1 == ioctl(fd, VT_WAITACTIVE, num))) {
Rob Landley9f0e00f2005-09-08 03:27:06 +000030 bb_perror_msg_and_die("ioctl");
Eric Andersen28672dd2003-10-22 10:30:53 +000031 }
Matt Kraai3e856ce2000-12-01 02:55:13 +000032 return EXIT_SUCCESS;
Eric Andersen0460ff21999-10-25 23:32:44 +000033}