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 | */ |
| 7 | #include "internal.h" |
| 8 | #include <sys/types.h> |
| 9 | #include <sys/ioctl.h> |
| 10 | #include <linux/vt.h> |
| 11 | #include <stdio.h> |
| 12 | #include <stdlib.h> |
| 13 | #include <fcntl.h> |
| 14 | |
| 15 | extern int getfd(void); |
| 16 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 17 | int chvt_main(int argc, char **argv) |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 18 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 19 | int fd, num; |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 20 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 21 | if ((argc != 2) || (**(argv + 1) == '-')) { |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame^] | 22 | usage ("chvt N\n" |
| 23 | #ifndef BB_FEATURE_TRIVIAL_HELP |
| 24 | "\nChanges the foreground virtual terminal to /dev/ttyN\n" |
| 25 | #endif |
| 26 | ); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 27 | } |
| 28 | fd = get_console_fd("/dev/console"); |
| 29 | num = atoi(argv[1]); |
| 30 | if (ioctl(fd, VT_ACTIVATE, num)) { |
| 31 | perror("VT_ACTIVATE"); |
| 32 | exit(FALSE); |
| 33 | } |
| 34 | if (ioctl(fd, VT_WAITACTIVE, num)) { |
| 35 | perror("VT_WAITACTIVE"); |
| 36 | exit(FALSE); |
| 37 | } |
| 38 | exit(TRUE); |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 39 | } |
Erik Andersen | 029011b | 2000-03-04 21:19:32 +0000 | [diff] [blame] | 40 | |
| 41 | |
| 42 | /* |
| 43 | Local Variables: |
| 44 | c-file-style: "linux" |
| 45 | c-basic-offset: 4 |
| 46 | tab-width: 4 |
| 47 | End: |
| 48 | */ |