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 | 3570a34 | 2000-09-25 21:45:58 +0000 | [diff] [blame] | 6 | #include "busybox.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"); |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 31 | return EXIT_FAILURE; |
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) |
Mark Whitley | f57c944 | 2000-12-07 19:56:48 +0000 | [diff] [blame] | 38 | error_msg("0: illegal VT number\n"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 39 | else if (num == 1) |
Mark Whitley | f57c944 | 2000-12-07 19:56:48 +0000 | [diff] [blame] | 40 | error_msg("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"); |
Mark Whitley | f57c944 | 2000-12-07 19:56:48 +0000 | [diff] [blame] | 43 | error_msg_and_die("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"); |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 47 | return EXIT_SUCCESS; |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 48 | } |