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 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 8 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 9 | */ |
Denys Vlasenko | 6d93299 | 2016-11-23 10:39:27 +0100 | [diff] [blame] | 10 | //config:config DEALLOCVT |
Denys Vlasenko | 4eed2c6 | 2017-07-18 22:01:24 +0200 | [diff] [blame] | 11 | //config: bool "deallocvt (1.9 kb)" |
Denys Vlasenko | 6d93299 | 2016-11-23 10:39:27 +0100 | [diff] [blame] | 12 | //config: default y |
Denys Vlasenko | 6d93299 | 2016-11-23 10:39:27 +0100 | [diff] [blame] | 13 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 14 | //config: This program deallocates unused virtual consoles. |
Eric Andersen | 7f6295f | 2003-10-22 10:34:15 +0000 | [diff] [blame] | 15 | |
Denys Vlasenko | ff53bee | 2017-08-05 02:02:31 +0200 | [diff] [blame] | 16 | //applet:IF_DEALLOCVT(APPLET_NOEXEC(deallocvt, deallocvt, BB_DIR_USR_BIN, BB_SUID_DROP, deallocvt)) |
Denys Vlasenko | 6d93299 | 2016-11-23 10:39:27 +0100 | [diff] [blame] | 17 | |
| 18 | //kbuild:lib-$(CONFIG_DEALLOCVT) += deallocvt.o |
Eric Andersen | 7f6295f | 2003-10-22 10:34:15 +0000 | [diff] [blame] | 19 | |
Pere Orga | 55068c4 | 2011-03-27 23:42:28 +0200 | [diff] [blame] | 20 | //usage:#define deallocvt_trivial_usage |
| 21 | //usage: "[N]" |
| 22 | //usage:#define deallocvt_full_usage "\n\n" |
| 23 | //usage: "Deallocate unused virtual terminal /dev/ttyN" |
| 24 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 25 | #include "libbb.h" |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 26 | |
| 27 | /* From <linux/vt.h> */ |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 28 | enum { VT_DISALLOCATE = 0x5608 }; /* free memory associated to vt */ |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 29 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 30 | int deallocvt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 31 | int deallocvt_main(int argc UNUSED_PARAM, char **argv) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 32 | { |
Glenn L McGrath | 17b4a20 | 2004-01-15 11:50:19 +0000 | [diff] [blame] | 33 | /* num = 0 deallocate all unused consoles */ |
| 34 | int num = 0; |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 35 | |
Denis Vlasenko | 1d42665 | 2008-03-17 09:09:09 +0000 | [diff] [blame] | 36 | if (argv[1]) { |
| 37 | if (argv[2]) |
| 38 | bb_show_usage(); |
Denis Vlasenko | 6ee023c | 2007-08-23 10:52:52 +0000 | [diff] [blame] | 39 | num = xatou_range(argv[1], 1, 63); |
Mark Whitley | 6f6aa9b | 2000-12-13 23:23:30 +0000 | [diff] [blame] | 40 | } |
Glenn L McGrath | 17b4a20 | 2004-01-15 11:50:19 +0000 | [diff] [blame] | 41 | |
Denis Vlasenko | 968dbf9 | 2007-10-29 19:52:21 +0000 | [diff] [blame] | 42 | /* double cast suppresses "cast to ptr from int of different size" */ |
Denis Vlasenko | 2afd5ab | 2008-08-05 23:32:27 +0000 | [diff] [blame] | 43 | xioctl(get_console_fd_or_die(), VT_DISALLOCATE, (void *)(ptrdiff_t)num); |
Glenn L McGrath | 17b4a20 | 2004-01-15 11:50:19 +0000 | [diff] [blame] | 44 | return EXIT_SUCCESS; |
Eric Andersen | 0460ff2 | 1999-10-25 23:32:44 +0000 | [diff] [blame] | 45 | } |