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