blob: fad7a2bb211567a80f83e88cbe624af550516610 [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 Andersen3570a342000-09-25 21:45:58 +00006#include "busybox.h"
Eric Andersen0460ff21999-10-25 23:32:44 +00007#include <stdlib.h>
Eric Andersenbd22ed82000-07-08 18:55:24 +00008#include <stdio.h>
Eric Andersen0460ff21999-10-25 23:32:44 +00009#include <fcntl.h>
10#include <sys/types.h>
11#include <sys/ioctl.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{
18 int fd, num, i;
Eric Andersen0460ff21999-10-25 23:32:44 +000019
Eric Andersen32e95f92000-09-23 19:55:59 +000020 //if ((argc > 2) || ((argv == 2) && (**(argv + 1) == '-')))
21 if (argc > 2)
Matt Kraai3bd8bd82000-07-14 23:28:47 +000022 usage(deallocvt_usage);
Erik Andersene49d5ec2000-02-08 19:58:47 +000023
Erik Andersene49d5ec2000-02-08 19:58:47 +000024 fd = get_console_fd("/dev/console");
25
26 if (argc == 1) {
27 /* deallocate all unused consoles */
Matt Kraaia9819b22000-12-22 01:48:07 +000028 if (ioctl(fd, VT_DISALLOCATE, 0))
29 perror_msg_and_die("VT_DISALLOCATE");
Mark Whitley6f6aa9b2000-12-13 23:23:30 +000030 } else {
Erik Andersene49d5ec2000-02-08 19:58:47 +000031 for (i = 1; i < argc; i++) {
32 num = atoi(argv[i]);
33 if (num == 0)
Mark Whitleyf57c9442000-12-07 19:56:48 +000034 error_msg("0: illegal VT number\n");
Erik Andersene49d5ec2000-02-08 19:58:47 +000035 else if (num == 1)
Mark Whitleyf57c9442000-12-07 19:56:48 +000036 error_msg("VT 1 cannot be deallocated\n");
Matt Kraaia9819b22000-12-22 01:48:07 +000037 else if (ioctl(fd, VT_DISALLOCATE, num))
38 perror_msg_and_die("VT_DISALLOCATE");
Erik Andersene49d5ec2000-02-08 19:58:47 +000039 }
Mark Whitley6f6aa9b2000-12-13 23:23:30 +000040 }
41
Matt Kraai3e856ce2000-12-01 02:55:13 +000042 return EXIT_SUCCESS;
Eric Andersen0460ff21999-10-25 23:32:44 +000043}