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 | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 6 | #include <stdlib.h> |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 7 | #include <stdio.h> |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 8 | #include <fcntl.h> |
| 9 | #include <sys/types.h> |
| 10 | #include <sys/ioctl.h> |
Eric Andersen | cbe31da | 2001-02-20 06:14:08 +0000 | [diff] [blame] | 11 | #include "busybox.h" |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 12 | |
| 13 | /* From <linux/vt.h> */ |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 14 | static const int VT_DISALLOCATE = 0x5608; /* free memory associated to vt */ |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 15 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 16 | int deallocvt_main(int argc, char *argv[]) |
| 17 | { |
Eric Andersen | a860bec | 2003-04-27 10:42:31 +0000 | [diff] [blame] | 18 | int fd, num=0; |
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) |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 21 | bb_show_usage(); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 22 | |
Eric Andersen | c38678d | 2002-09-16 06:22:25 +0000 | [diff] [blame] | 23 | fd = get_console_fd(); |
Eric Andersen | a860bec | 2003-04-27 10:42:31 +0000 | [diff] [blame] | 24 | |
| 25 | /* num=0 deallocate all unused consoles */ |
| 26 | if (argc == 1) |
| 27 | goto disallocate_all; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 28 | |
Eric Andersen | a860bec | 2003-04-27 10:42:31 +0000 | [diff] [blame] | 29 | num=bb_xgetlarg(argv[1], 10, 0, INT_MAX); |
| 30 | |
| 31 | switch(num) |
| 32 | { |
| 33 | case 0: |
| 34 | bb_error_msg("0: illegal VT number"); |
| 35 | break; |
| 36 | case 1: |
| 37 | bb_error_msg("VT 1 cannot be deallocated"); |
| 38 | break; |
| 39 | default: |
| 40 | disallocate_all: |
| 41 | if (ioctl(fd, VT_DISALLOCATE, num)) |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 42 | bb_perror_msg_and_die("VT_DISALLOCATE"); |
Eric Andersen | a860bec | 2003-04-27 10:42:31 +0000 | [diff] [blame] | 43 | return EXIT_SUCCESS; |
Mark Whitley | 6f6aa9b | 2000-12-13 23:23:30 +0000 | [diff] [blame] | 44 | } |
Eric Andersen | a860bec | 2003-04-27 10:42:31 +0000 | [diff] [blame] | 45 | return EXIT_FAILURE; |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 46 | } |