blob: 6cd54653cab6b5905a7d62eb7ea7edc492620f18 [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Eric Andersen0460ff21999-10-25 23:32:44 +00002/*
Eric Andersen7f6295f2003-10-22 10:34:15 +00003 * Disallocate virtual terminal(s)
4 *
5 * Copyright (C) 2003 by Tito Ragusa <farmatito@tiscali.it>
Eric Andersenc7bda1c2004-03-15 08:29:22 +00006 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
Eric Andersen7f6295f2003-10-22 10:34:15 +00007 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02008 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Eric Andersen0460ff21999-10-25 23:32:44 +00009 */
Denys Vlasenko6d932992016-11-23 10:39:27 +010010//config:config DEALLOCVT
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020011//config: bool "deallocvt (1.9 kb)"
Denys Vlasenko6d932992016-11-23 10:39:27 +010012//config: default y
Denys Vlasenko6d932992016-11-23 10:39:27 +010013//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020014//config: This program deallocates unused virtual consoles.
Eric Andersen7f6295f2003-10-22 10:34:15 +000015
Denys Vlasenkoff53bee2017-08-05 02:02:31 +020016//applet:IF_DEALLOCVT(APPLET_NOEXEC(deallocvt, deallocvt, BB_DIR_USR_BIN, BB_SUID_DROP, deallocvt))
Denys Vlasenko6d932992016-11-23 10:39:27 +010017
18//kbuild:lib-$(CONFIG_DEALLOCVT) += deallocvt.o
Eric Andersen7f6295f2003-10-22 10:34:15 +000019
Pere Orga55068c42011-03-27 23:42:28 +020020//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 Vlasenkob6adbf12007-05-26 19:00:18 +000025#include "libbb.h"
Eric Andersenbd22ed82000-07-08 18:55:24 +000026
27/* From <linux/vt.h> */
Rob Landleybc68cd12006-03-10 19:22:06 +000028enum { VT_DISALLOCATE = 0x5608 }; /* free memory associated to vt */
Eric Andersenbd22ed82000-07-08 18:55:24 +000029
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000030int deallocvt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000031int deallocvt_main(int argc UNUSED_PARAM, char **argv)
Erik Andersene49d5ec2000-02-08 19:58:47 +000032{
Glenn L McGrath17b4a202004-01-15 11:50:19 +000033 /* num = 0 deallocate all unused consoles */
34 int num = 0;
Eric Andersen0460ff21999-10-25 23:32:44 +000035
Denis Vlasenko1d426652008-03-17 09:09:09 +000036 if (argv[1]) {
37 if (argv[2])
38 bb_show_usage();
Denis Vlasenko6ee023c2007-08-23 10:52:52 +000039 num = xatou_range(argv[1], 1, 63);
Mark Whitley6f6aa9b2000-12-13 23:23:30 +000040 }
Glenn L McGrath17b4a202004-01-15 11:50:19 +000041
Denis Vlasenko968dbf92007-10-29 19:52:21 +000042 /* double cast suppresses "cast to ptr from int of different size" */
Denis Vlasenko2afd5ab2008-08-05 23:32:27 +000043 xioctl(get_console_fd_or_die(), VT_DISALLOCATE, (void *)(ptrdiff_t)num);
Glenn L McGrath17b4a202004-01-15 11:50:19 +000044 return EXIT_SUCCESS;
Eric Andersen0460ff21999-10-25 23:32:44 +000045}