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