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 | 28672dd | 2003-10-22 10:30:53 +0000 | [diff] [blame] | 5 | * 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 Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 20 | */ |
Mark Whitley | 827e45c | 2001-03-09 23:59:51 +0000 | [diff] [blame] | 21 | |
Eric Andersen | 28672dd | 2003-10-22 10:30:53 +0000 | [diff] [blame] | 22 | /* no options, no getopt */ |
Mark Whitley | 827e45c | 2001-03-09 23:59:51 +0000 | [diff] [blame] | 23 | |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <fcntl.h> |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 27 | #include <sys/types.h> |
| 28 | #include <sys/ioctl.h> |
Eric Andersen | cbe31da | 2001-02-20 06:14:08 +0000 | [diff] [blame] | 29 | #include "busybox.h" |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 30 | |
| 31 | /* From <linux/vt.h> */ |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 32 | static const int VT_ACTIVATE = 0x5606; /* make vt active */ |
| 33 | static const int VT_WAITACTIVE = 0x5607; /* wait for vt active */ |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 34 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 35 | int chvt_main(int argc, char **argv) |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 36 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 37 | int fd, num; |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 38 | |
Glenn L McGrath | 6a78631 | 2004-01-14 07:34:37 +0000 | [diff] [blame] | 39 | if (argc != 2) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 40 | bb_show_usage(); |
Eric Andersen | 28672dd | 2003-10-22 10:30:53 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Eric Andersen | c38678d | 2002-09-16 06:22:25 +0000 | [diff] [blame] | 43 | fd = get_console_fd(); |
Glenn L McGrath | 6a78631 | 2004-01-14 07:34:37 +0000 | [diff] [blame] | 44 | num = bb_xgetlarg(argv[1], 10, 0, INT_MAX); |
Eric Andersen | 28672dd | 2003-10-22 10:30:53 +0000 | [diff] [blame] | 45 | if (ioctl(fd, VT_ACTIVATE, num)) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 46 | bb_perror_msg_and_die("VT_ACTIVATE"); |
Eric Andersen | 28672dd | 2003-10-22 10:30:53 +0000 | [diff] [blame] | 47 | } |
| 48 | if (ioctl(fd, VT_WAITACTIVE, num)) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 49 | bb_perror_msg_and_die("VT_WAITACTIVE"); |
Eric Andersen | 28672dd | 2003-10-22 10:30:53 +0000 | [diff] [blame] | 50 | } |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 51 | return EXIT_SUCCESS; |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 52 | } |
Erik Andersen | 029011b | 2000-03-04 21:19:32 +0000 | [diff] [blame] | 53 | |
| 54 | |
| 55 | /* |
| 56 | Local Variables: |
| 57 | c-file-style: "linux" |
| 58 | c-basic-offset: 4 |
| 59 | tab-width: 4 |
| 60 | End: |
| 61 | */ |