blob: b2e8e2bef3c4afadead4b983218bc522ec5a5a34 [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 *
"Robert P. J. Day"801ab142006-07-12 07:56:04 +00008 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Eric Andersen0460ff21999-10-25 23:32:44 +00009 */
Eric Andersen7f6295f2003-10-22 10:34:15 +000010
11/* no options, no getopt */
12
Eric Andersen0460ff21999-10-25 23:32:44 +000013#include <stdlib.h>
Eric Andersenbd22ed82000-07-08 18:55:24 +000014#include <stdio.h>
Eric Andersen0460ff21999-10-25 23:32:44 +000015#include <fcntl.h>
16#include <sys/types.h>
17#include <sys/ioctl.h>
Eric Andersencbe31da2001-02-20 06:14:08 +000018#include "busybox.h"
Eric Andersenbd22ed82000-07-08 18:55:24 +000019
20/* From <linux/vt.h> */
Rob Landleybc68cd12006-03-10 19:22:06 +000021enum { VT_DISALLOCATE = 0x5608 }; /* free memory associated to vt */
Eric Andersenbd22ed82000-07-08 18:55:24 +000022
Erik Andersene49d5ec2000-02-08 19:58:47 +000023int deallocvt_main(int argc, char *argv[])
24{
Glenn L McGrath17b4a202004-01-15 11:50:19 +000025 /* num = 0 deallocate all unused consoles */
26 int num = 0;
Eric Andersen0460ff21999-10-25 23:32:44 +000027
Rob Landleyead19302006-03-10 23:16:25 +000028 switch (argc) {
Glenn L McGrath17b4a202004-01-15 11:50:19 +000029 case 2:
Rob Landleyead19302006-03-10 23:16:25 +000030 if ((num = bb_xgetlarg(argv[1], 10, 0, INT_MAX)) == 0) {
Glenn L McGrath17b4a202004-01-15 11:50:19 +000031 bb_error_msg_and_die("0: illegal VT number");
Rob Landleyead19302006-03-10 23:16:25 +000032 }
Rob Landley9f0e00f2005-09-08 03:27:06 +000033 /* Fallthrough */
Eric Andersena860bec2003-04-27 10:42:31 +000034 case 1:
Eric Andersena860bec2003-04-27 10:42:31 +000035 break;
36 default:
Glenn L McGrath17b4a202004-01-15 11:50:19 +000037 bb_show_usage();
Mark Whitley6f6aa9b2000-12-13 23:23:30 +000038 }
Glenn L McGrath17b4a202004-01-15 11:50:19 +000039
Rob Landleyead19302006-03-10 23:16:25 +000040 if (-1 == ioctl(get_console_fd(), VT_DISALLOCATE, num)) {
Glenn L McGrath17b4a202004-01-15 11:50:19 +000041 bb_perror_msg_and_die("VT_DISALLOCATE");
42 }
43 return EXIT_SUCCESS;
Eric Andersen0460ff21999-10-25 23:32:44 +000044}