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) { |
| 27 | /* deallocate all unused consoles */ |
Matt Kraai | a9819b2 | 2000-12-22 01:48:07 +0000 | [diff] [blame^] | 28 | if (ioctl(fd, VT_DISALLOCATE, 0)) |
| 29 | perror_msg_and_die("VT_DISALLOCATE"); |
Mark Whitley | 6f6aa9b | 2000-12-13 23:23:30 +0000 | [diff] [blame] | 30 | } else { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 31 | for (i = 1; i < argc; i++) { |
| 32 | num = atoi(argv[i]); |
| 33 | if (num == 0) |
Mark Whitley | f57c944 | 2000-12-07 19:56:48 +0000 | [diff] [blame] | 34 | error_msg("0: illegal VT number\n"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 35 | else if (num == 1) |
Mark Whitley | f57c944 | 2000-12-07 19:56:48 +0000 | [diff] [blame] | 36 | error_msg("VT 1 cannot be deallocated\n"); |
Matt Kraai | a9819b2 | 2000-12-22 01:48:07 +0000 | [diff] [blame^] | 37 | else if (ioctl(fd, VT_DISALLOCATE, num)) |
| 38 | perror_msg_and_die("VT_DISALLOCATE"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 39 | } |
Mark Whitley | 6f6aa9b | 2000-12-13 23:23:30 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 42 | return EXIT_SUCCESS; |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 43 | } |