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 | |
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 | |
Eric Andersen | 32e95f9 | 2000-09-23 19:55:59 +0000 | [diff] [blame] | 20 | //if ((argc > 2) || ((argv == 2) && (**(argv + 1) == '-'))) |
| 21 | if (argc > 2) |
Matt Kraai | 3bd8bd8 | 2000-07-14 23:28:47 +0000 | [diff] [blame] | 22 | usage(deallocvt_usage); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 23 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 24 | fd = get_console_fd("/dev/console"); |
| 25 | |
| 26 | if (argc == 1) { |
Eric Andersen | 32e95f9 | 2000-09-23 19:55:59 +0000 | [diff] [blame] | 27 | printf("erik: A\n"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 28 | /* deallocate all unused consoles */ |
| 29 | if (ioctl(fd, VT_DISALLOCATE, 0)) { |
| 30 | perror("VT_DISALLOCATE"); |
Eric Andersen | b610615 | 2000-06-19 17:25:40 +0000 | [diff] [blame] | 31 | exit( FALSE); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 32 | } |
| 33 | } else |
Eric Andersen | 32e95f9 | 2000-09-23 19:55:59 +0000 | [diff] [blame] | 34 | printf("erik: B\n"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 35 | for (i = 1; i < argc; i++) { |
| 36 | num = atoi(argv[i]); |
| 37 | if (num == 0) |
Matt Kraai | d537a95 | 2000-07-14 01:51:25 +0000 | [diff] [blame] | 38 | errorMsg("0: illegal VT number\n"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 39 | else if (num == 1) |
Matt Kraai | d537a95 | 2000-07-14 01:51:25 +0000 | [diff] [blame] | 40 | errorMsg("VT 1 cannot be deallocated\n"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 41 | else if (ioctl(fd, VT_DISALLOCATE, num)) { |
| 42 | perror("VT_DISALLOCATE"); |
Eric Andersen | 32e95f9 | 2000-09-23 19:55:59 +0000 | [diff] [blame] | 43 | fatalError("could not deallocate console %d\n", num); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 44 | } |
| 45 | } |
Eric Andersen | 32e95f9 | 2000-09-23 19:55:59 +0000 | [diff] [blame] | 46 | printf("erik: C\n"); |
Eric Andersen | b610615 | 2000-06-19 17:25:40 +0000 | [diff] [blame] | 47 | return( TRUE); |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 48 | } |