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