blob: f641be8d76a34101f16b4ed15f74aa528db17506 [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/*
3 * disalloc.c - aeb - 940501 - Disallocate virtual terminal(s)
4 * Renamed deallocvt.
5 */
Eric Andersen0460ff21999-10-25 23:32:44 +00006#include <stdlib.h>
Eric Andersenbd22ed82000-07-08 18:55:24 +00007#include <stdio.h>
Eric Andersen0460ff21999-10-25 23:32:44 +00008#include <fcntl.h>
9#include <sys/types.h>
10#include <sys/ioctl.h>
Eric Andersencbe31da2001-02-20 06:14:08 +000011#include "busybox.h"
Eric Andersenbd22ed82000-07-08 18:55:24 +000012
13/* From <linux/vt.h> */
Mark Whitley59ab0252001-01-23 22:30:04 +000014static const int VT_DISALLOCATE = 0x5608; /* free memory associated to vt */
Eric Andersenbd22ed82000-07-08 18:55:24 +000015
Erik Andersene49d5ec2000-02-08 19:58:47 +000016int deallocvt_main(int argc, char *argv[])
17{
Eric Andersena860bec2003-04-27 10:42:31 +000018 int fd, num=0;
Eric Andersen0460ff21999-10-25 23:32:44 +000019
Eric Andersen32e95f92000-09-23 19:55:59 +000020 if (argc > 2)
Manuel Novoa III cad53642003-03-19 09:13:01 +000021 bb_show_usage();
Erik Andersene49d5ec2000-02-08 19:58:47 +000022
Eric Andersenc38678d2002-09-16 06:22:25 +000023 fd = get_console_fd();
Eric Andersena860bec2003-04-27 10:42:31 +000024
25 /* num=0 deallocate all unused consoles */
26 if (argc == 1)
27 goto disallocate_all;
Erik Andersene49d5ec2000-02-08 19:58:47 +000028
Eric Andersena860bec2003-04-27 10:42:31 +000029 num=bb_xgetlarg(argv[1], 10, 0, INT_MAX);
30
31 switch(num)
32 {
33 case 0:
34 bb_error_msg("0: illegal VT number");
35 break;
36 case 1:
37 bb_error_msg("VT 1 cannot be deallocated");
38 break;
39 default:
40disallocate_all:
41 if (ioctl(fd, VT_DISALLOCATE, num))
Manuel Novoa III cad53642003-03-19 09:13:01 +000042 bb_perror_msg_and_die("VT_DISALLOCATE");
Eric Andersena860bec2003-04-27 10:42:31 +000043 return EXIT_SUCCESS;
Mark Whitley6f6aa9b2000-12-13 23:23:30 +000044 }
Eric Andersena860bec2003-04-27 10:42:31 +000045 return EXIT_FAILURE;
Eric Andersen0460ff21999-10-25 23:32:44 +000046}