blob: 853b2b48975f4387677660d8b986b51720fdebd1 [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 *
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 Andersenc7bda1c2004-03-15 08:29:22 +000012 *
Eric Andersen7f6295f2003-10-22 10:34:15 +000013 * 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 Andersen0460ff21999-10-25 23:32:44 +000021 */
Eric Andersen7f6295f2003-10-22 10:34:15 +000022
23/* no options, no getopt */
24
Eric Andersen0460ff21999-10-25 23:32:44 +000025#include <stdlib.h>
Eric Andersenbd22ed82000-07-08 18:55:24 +000026#include <stdio.h>
Eric Andersen0460ff21999-10-25 23:32:44 +000027#include <fcntl.h>
28#include <sys/types.h>
29#include <sys/ioctl.h>
Eric Andersencbe31da2001-02-20 06:14:08 +000030#include "busybox.h"
Eric Andersenbd22ed82000-07-08 18:55:24 +000031
32/* From <linux/vt.h> */
Rob Landleybc68cd12006-03-10 19:22:06 +000033enum { VT_DISALLOCATE = 0x5608 }; /* free memory associated to vt */
Eric Andersenbd22ed82000-07-08 18:55:24 +000034
Erik Andersene49d5ec2000-02-08 19:58:47 +000035int deallocvt_main(int argc, char *argv[])
36{
Glenn L McGrath17b4a202004-01-15 11:50:19 +000037 /* num = 0 deallocate all unused consoles */
38 int num = 0;
Eric Andersen0460ff21999-10-25 23:32:44 +000039
Rob Landleyead19302006-03-10 23:16:25 +000040 switch (argc) {
Glenn L McGrath17b4a202004-01-15 11:50:19 +000041 case 2:
Rob Landleyead19302006-03-10 23:16:25 +000042 if ((num = bb_xgetlarg(argv[1], 10, 0, INT_MAX)) == 0) {
Glenn L McGrath17b4a202004-01-15 11:50:19 +000043 bb_error_msg_and_die("0: illegal VT number");
Rob Landleyead19302006-03-10 23:16:25 +000044 }
Rob Landley9f0e00f2005-09-08 03:27:06 +000045 /* Fallthrough */
Eric Andersena860bec2003-04-27 10:42:31 +000046 case 1:
Eric Andersena860bec2003-04-27 10:42:31 +000047 break;
48 default:
Glenn L McGrath17b4a202004-01-15 11:50:19 +000049 bb_show_usage();
Mark Whitley6f6aa9b2000-12-13 23:23:30 +000050 }
Glenn L McGrath17b4a202004-01-15 11:50:19 +000051
Rob Landleyead19302006-03-10 23:16:25 +000052 if (-1 == ioctl(get_console_fd(), VT_DISALLOCATE, num)) {
Glenn L McGrath17b4a202004-01-15 11:50:19 +000053 bb_perror_msg_and_die("VT_DISALLOCATE");
54 }
55 return EXIT_SUCCESS;
Eric Andersen0460ff21999-10-25 23:32:44 +000056}