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 | |
| 14 | extern int getfd(void); |
| 15 | char *progname; |
| 16 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 17 | int deallocvt_main(int argc, char *argv[]) |
| 18 | { |
| 19 | int fd, num, i; |
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) == '-')) { |
| 22 | usage |
| 23 | ("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n"); |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 24 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 25 | |
| 26 | progname = argv[0]; |
| 27 | |
| 28 | fd = get_console_fd("/dev/console"); |
| 29 | |
| 30 | if (argc == 1) { |
| 31 | /* deallocate all unused consoles */ |
| 32 | if (ioctl(fd, VT_DISALLOCATE, 0)) { |
| 33 | perror("VT_DISALLOCATE"); |
| 34 | exit(1); |
| 35 | } |
| 36 | } else |
| 37 | for (i = 1; i < argc; i++) { |
| 38 | num = atoi(argv[i]); |
| 39 | if (num == 0) |
| 40 | fprintf(stderr, "%s: 0: illegal VT number\n", progname); |
| 41 | else if (num == 1) |
| 42 | fprintf(stderr, "%s: VT 1 cannot be deallocated\n", |
| 43 | progname); |
| 44 | else if (ioctl(fd, VT_DISALLOCATE, num)) { |
| 45 | perror("VT_DISALLOCATE"); |
| 46 | fprintf(stderr, "%s: could not deallocate console %d\n", |
| 47 | progname, num); |
| 48 | exit(1); |
| 49 | } |
| 50 | } |
| 51 | exit(0); |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 52 | } |