Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 2 | /* |
Eric Andersen | 28672dd | 2003-10-22 10:30:53 +0000 | [diff] [blame] | 3 | * Mini chvt implementation for busybox |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 4 | * |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> |
Eric Andersen | 28672dd | 2003-10-22 10:30:53 +0000 | [diff] [blame] | 6 | * |
Bernhard Reutner-Fischer | b1629b1 | 2006-05-19 19:29:19 +0000 | [diff] [blame^] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 8 | */ |
Mark Whitley | 827e45c | 2001-03-09 23:59:51 +0000 | [diff] [blame] | 9 | |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> |
| 12 | #include <fcntl.h> |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 13 | #include <sys/types.h> |
| 14 | #include <sys/ioctl.h> |
Eric Andersen | cbe31da | 2001-02-20 06:14:08 +0000 | [diff] [blame] | 15 | #include "busybox.h" |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 16 | |
| 17 | /* From <linux/vt.h> */ |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 18 | enum { |
| 19 | VT_ACTIVATE = 0x5606, /* make vt active */ |
| 20 | VT_WAITACTIVE = 0x5607 /* wait for vt active */ |
| 21 | }; |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 22 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 23 | int chvt_main(int argc, char **argv) |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 24 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 25 | int fd, num; |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 26 | |
Glenn L McGrath | 6a78631 | 2004-01-14 07:34:37 +0000 | [diff] [blame] | 27 | if (argc != 2) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 28 | bb_show_usage(); |
Eric Andersen | 28672dd | 2003-10-22 10:30:53 +0000 | [diff] [blame] | 29 | } |
| 30 | |
Eric Andersen | c38678d | 2002-09-16 06:22:25 +0000 | [diff] [blame] | 31 | fd = get_console_fd(); |
Glenn L McGrath | 6a78631 | 2004-01-14 07:34:37 +0000 | [diff] [blame] | 32 | num = bb_xgetlarg(argv[1], 10, 0, INT_MAX); |
Rob Landley | ead1930 | 2006-03-10 23:16:25 +0000 | [diff] [blame] | 33 | if ((-1 == ioctl(fd, VT_ACTIVATE, num)) |
| 34 | || (-1 == ioctl(fd, VT_WAITACTIVE, num))) { |
Rob Landley | 9f0e00f | 2005-09-08 03:27:06 +0000 | [diff] [blame] | 35 | bb_perror_msg_and_die("ioctl"); |
Eric Andersen | 28672dd | 2003-10-22 10:30:53 +0000 | [diff] [blame] | 36 | } |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 37 | return EXIT_SUCCESS; |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 38 | } |