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 | * disalloc.c - aeb - 940501 - Disallocate virtual terminal(s) |
| 4 | * Renamed deallocvt. |
| 5 | */ |
Eric Andersen | 6b6b3f6 | 1999-10-28 16:06:25 +0000 | [diff] [blame] | 6 | #include "internal.h" |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 7 | #include <stdlib.h> |
| 8 | #include <fcntl.h> |
| 9 | #include <sys/types.h> |
| 10 | #include <sys/ioctl.h> |
| 11 | #include <linux/vt.h> |
| 12 | #include <stdio.h> |
| 13 | |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 14 | char *progname; |
| 15 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 16 | int deallocvt_main(int argc, char *argv[]) |
| 17 | { |
| 18 | int fd, num, i; |
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 | if ((argc != 2) || (**(argv + 1) == '-')) { |
| 21 | usage |
Erik Andersen | 59b9e87 | 2000-05-10 05:05:45 +0000 | [diff] [blame] | 22 | ("deallocvt N\n" |
| 23 | #ifndef BB_FEATURE_TRIVIAL_HELP |
| 24 | "\nDeallocate unused virtual terminal /dev/ttyN\n" |
| 25 | #endif |
| 26 | ); |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 27 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 28 | |
| 29 | progname = argv[0]; |
| 30 | |
| 31 | fd = get_console_fd("/dev/console"); |
| 32 | |
| 33 | if (argc == 1) { |
| 34 | /* deallocate all unused consoles */ |
| 35 | if (ioctl(fd, VT_DISALLOCATE, 0)) { |
| 36 | perror("VT_DISALLOCATE"); |
Eric Andersen | b610615 | 2000-06-19 17:25:40 +0000 | [diff] [blame] | 37 | exit( FALSE); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 38 | } |
| 39 | } else |
| 40 | for (i = 1; i < argc; i++) { |
| 41 | num = atoi(argv[i]); |
| 42 | if (num == 0) |
| 43 | fprintf(stderr, "%s: 0: illegal VT number\n", progname); |
| 44 | else if (num == 1) |
| 45 | fprintf(stderr, "%s: VT 1 cannot be deallocated\n", |
| 46 | progname); |
| 47 | else if (ioctl(fd, VT_DISALLOCATE, num)) { |
| 48 | perror("VT_DISALLOCATE"); |
| 49 | fprintf(stderr, "%s: could not deallocate console %d\n", |
| 50 | progname, num); |
Eric Andersen | b610615 | 2000-06-19 17:25:40 +0000 | [diff] [blame] | 51 | exit( FALSE); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 52 | } |
| 53 | } |
Eric Andersen | b610615 | 2000-06-19 17:25:40 +0000 | [diff] [blame] | 54 | return( TRUE); |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 55 | } |