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 | */ |
Eric Andersen | 3570a34 | 2000-09-25 21:45:58 +0000 | [diff] [blame] | 7 | #include "busybox.h" |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 8 | #include <stdio.h> |
| 9 | #include <stdlib.h> |
| 10 | #include <fcntl.h> |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 11 | #include <sys/types.h> |
| 12 | #include <sys/ioctl.h> |
| 13 | |
| 14 | /* From <linux/vt.h> */ |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame^] | 15 | static const int VT_ACTIVATE = 0x5606; /* make vt active */ |
| 16 | static const int VT_WAITACTIVE = 0x5607; /* wait for vt active */ |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 17 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 18 | int chvt_main(int argc, char **argv) |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 19 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 20 | int fd, num; |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 21 | |
Matt Kraai | 3bd8bd8 | 2000-07-14 23:28:47 +0000 | [diff] [blame] | 22 | if ((argc != 2) || (**(argv + 1) == '-')) |
| 23 | usage (chvt_usage); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 24 | fd = get_console_fd("/dev/console"); |
| 25 | num = atoi(argv[1]); |
Matt Kraai | aefe562 | 2000-12-14 05:44:36 +0000 | [diff] [blame] | 26 | if (ioctl(fd, VT_ACTIVATE, num)) |
| 27 | perror_msg_and_die("VT_ACTIVATE"); |
| 28 | if (ioctl(fd, VT_WAITACTIVE, num)) |
| 29 | perror_msg_and_die("VT_WAITACTIVE"); |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 30 | return EXIT_SUCCESS; |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 31 | } |
Erik Andersen | 029011b | 2000-03-04 21:19:32 +0000 | [diff] [blame] | 32 | |
| 33 | |
| 34 | /* |
| 35 | Local Variables: |
| 36 | c-file-style: "linux" |
| 37 | c-basic-offset: 4 |
| 38 | tab-width: 4 |
| 39 | End: |
| 40 | */ |