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 | /* |
| 3 | * chvt.c - aeb - 940227 - Change virtual terminal |
| 4 | * |
| 5 | * busyboxed by Erik Andersen |
| 6 | */ |
Mark Whitley | 827e45c | 2001-03-09 23:59:51 +0000 | [diff] [blame] | 7 | |
| 8 | /* getopt not needed */ |
| 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> */ |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 18 | static const int VT_ACTIVATE = 0x5606; /* make vt active */ |
| 19 | static const int VT_WAITACTIVE = 0x5607; /* wait for vt active */ |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 20 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 21 | int chvt_main(int argc, char **argv) |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 22 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 23 | int fd, num; |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 24 | |
Matt Kraai | 3bd8bd8 | 2000-07-14 23:28:47 +0000 | [diff] [blame] | 25 | if ((argc != 2) || (**(argv + 1) == '-')) |
Eric Andersen | 67991cf | 2001-02-14 21:23:06 +0000 | [diff] [blame] | 26 | show_usage(); |
Eric Andersen | c38678d | 2002-09-16 06:22:25 +0000 | [diff] [blame] | 27 | fd = get_console_fd(); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 28 | num = atoi(argv[1]); |
Matt Kraai | aefe562 | 2000-12-14 05:44:36 +0000 | [diff] [blame] | 29 | if (ioctl(fd, VT_ACTIVATE, num)) |
| 30 | perror_msg_and_die("VT_ACTIVATE"); |
| 31 | if (ioctl(fd, VT_WAITACTIVE, num)) |
| 32 | perror_msg_and_die("VT_WAITACTIVE"); |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 33 | return EXIT_SUCCESS; |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 34 | } |
Erik Andersen | 029011b | 2000-03-04 21:19:32 +0000 | [diff] [blame] | 35 | |
| 36 | |
| 37 | /* |
| 38 | Local Variables: |
| 39 | c-file-style: "linux" |
| 40 | c-basic-offset: 4 |
| 41 | tab-width: 4 |
| 42 | End: |
| 43 | */ |