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 | /* |
Eric Andersen | 7f6295f | 2003-10-22 10:34:15 +0000 | [diff] [blame] | 3 | * Disallocate virtual terminal(s) |
| 4 | * |
| 5 | * Copyright (C) 2003 by Tito Ragusa <farmatito@tiscali.it> |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame^] | 6 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> |
Eric Andersen | 7f6295f | 2003-10-22 10:34:15 +0000 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame^] | 12 | * |
Eric Andersen | 7f6295f | 2003-10-22 10:34:15 +0000 | [diff] [blame] | 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 21 | */ |
Eric Andersen | 7f6295f | 2003-10-22 10:34:15 +0000 | [diff] [blame] | 22 | |
| 23 | /* no options, no getopt */ |
| 24 | |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 25 | #include <stdlib.h> |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 26 | #include <stdio.h> |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 27 | #include <fcntl.h> |
| 28 | #include <sys/types.h> |
| 29 | #include <sys/ioctl.h> |
Eric Andersen | cbe31da | 2001-02-20 06:14:08 +0000 | [diff] [blame] | 30 | #include "busybox.h" |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 31 | |
| 32 | /* From <linux/vt.h> */ |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 33 | static const int VT_DISALLOCATE = 0x5608; /* free memory associated to vt */ |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 34 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 35 | int deallocvt_main(int argc, char *argv[]) |
| 36 | { |
Glenn L McGrath | 17b4a20 | 2004-01-15 11:50:19 +0000 | [diff] [blame] | 37 | /* num = 0 deallocate all unused consoles */ |
| 38 | int num = 0; |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 39 | |
Glenn L McGrath | 17b4a20 | 2004-01-15 11:50:19 +0000 | [diff] [blame] | 40 | switch(argc) |
| 41 | { |
| 42 | case 2: |
| 43 | if((num = bb_xgetlarg(argv[1], 10, 0, INT_MAX)) == 0) |
| 44 | bb_error_msg_and_die("0: illegal VT number"); |
| 45 | /* Falltrough */ |
Eric Andersen | a860bec | 2003-04-27 10:42:31 +0000 | [diff] [blame] | 46 | case 1: |
Eric Andersen | a860bec | 2003-04-27 10:42:31 +0000 | [diff] [blame] | 47 | break; |
| 48 | default: |
Glenn L McGrath | 17b4a20 | 2004-01-15 11:50:19 +0000 | [diff] [blame] | 49 | bb_show_usage(); |
Mark Whitley | 6f6aa9b | 2000-12-13 23:23:30 +0000 | [diff] [blame] | 50 | } |
Glenn L McGrath | 17b4a20 | 2004-01-15 11:50:19 +0000 | [diff] [blame] | 51 | |
| 52 | if (ioctl( get_console_fd(), VT_DISALLOCATE, num )) { |
| 53 | bb_perror_msg_and_die("VT_DISALLOCATE"); |
| 54 | } |
| 55 | return EXIT_SUCCESS; |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 56 | } |