blob: 042de8649f2dff5ae20412417d5f54a1754850f1 [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 Andersen6b6b3f61999-10-28 16:06:25 +00006#include "internal.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> */
14#define VT_DISALLOCATE 0x5608 /* free memory associated to vt */
15
Matt Kraai3bd8bd82000-07-14 23:28:47 +000016const char deallocvt_usage[] =
17 "deallocvt N\n"
18#ifndef BB_FEATURE_TRIVIAL_HELP
19 "\nDeallocate unused virtual terminal /dev/ttyN\n"
20#endif
21 ;
Eric Andersen0460ff21999-10-25 23:32:44 +000022
Erik Andersene49d5ec2000-02-08 19:58:47 +000023int deallocvt_main(int argc, char *argv[])
24{
25 int fd, num, i;
Eric Andersen0460ff21999-10-25 23:32:44 +000026
Matt Kraai3bd8bd82000-07-14 23:28:47 +000027 if ((argc != 2) || (**(argv + 1) == '-'))
28 usage(deallocvt_usage);
Erik Andersene49d5ec2000-02-08 19:58:47 +000029
Erik Andersene49d5ec2000-02-08 19:58:47 +000030 fd = get_console_fd("/dev/console");
31
32 if (argc == 1) {
33 /* deallocate all unused consoles */
34 if (ioctl(fd, VT_DISALLOCATE, 0)) {
35 perror("VT_DISALLOCATE");
Eric Andersenb6106152000-06-19 17:25:40 +000036 exit( FALSE);
Erik Andersene49d5ec2000-02-08 19:58:47 +000037 }
38 } else
39 for (i = 1; i < argc; i++) {
40 num = atoi(argv[i]);
41 if (num == 0)
Matt Kraaid537a952000-07-14 01:51:25 +000042 errorMsg("0: illegal VT number\n");
Erik Andersene49d5ec2000-02-08 19:58:47 +000043 else if (num == 1)
Matt Kraaid537a952000-07-14 01:51:25 +000044 errorMsg("VT 1 cannot be deallocated\n");
Erik Andersene49d5ec2000-02-08 19:58:47 +000045 else if (ioctl(fd, VT_DISALLOCATE, num)) {
46 perror("VT_DISALLOCATE");
Matt Kraaid537a952000-07-14 01:51:25 +000047 errorMsg("could not deallocate console %d\n", num);
Eric Andersenb6106152000-06-19 17:25:40 +000048 exit( FALSE);
Erik Andersene49d5ec2000-02-08 19:58:47 +000049 }
50 }
Eric Andersenb6106152000-06-19 17:25:40 +000051 return( TRUE);
Eric Andersen0460ff21999-10-25 23:32:44 +000052}