blob: bb9632fdec3e8ff278520864f182fb71dfe1cdca [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
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) {
Eric Andersen32e95f92000-09-23 19:55:59 +000027printf("erik: A\n");
Erik Andersene49d5ec2000-02-08 19:58:47 +000028 /* deallocate all unused consoles */
29 if (ioctl(fd, VT_DISALLOCATE, 0)) {
30 perror("VT_DISALLOCATE");
Eric Andersenb6106152000-06-19 17:25:40 +000031 exit( FALSE);
Erik Andersene49d5ec2000-02-08 19:58:47 +000032 }
33 } else
Eric Andersen32e95f92000-09-23 19:55:59 +000034printf("erik: B\n");
Erik Andersene49d5ec2000-02-08 19:58:47 +000035 for (i = 1; i < argc; i++) {
36 num = atoi(argv[i]);
37 if (num == 0)
Matt Kraaid537a952000-07-14 01:51:25 +000038 errorMsg("0: illegal VT number\n");
Erik Andersene49d5ec2000-02-08 19:58:47 +000039 else if (num == 1)
Matt Kraaid537a952000-07-14 01:51:25 +000040 errorMsg("VT 1 cannot be deallocated\n");
Erik Andersene49d5ec2000-02-08 19:58:47 +000041 else if (ioctl(fd, VT_DISALLOCATE, num)) {
42 perror("VT_DISALLOCATE");
Eric Andersen32e95f92000-09-23 19:55:59 +000043 fatalError("could not deallocate console %d\n", num);
Erik Andersene49d5ec2000-02-08 19:58:47 +000044 }
45 }
Eric Andersen32e95f92000-09-23 19:55:59 +000046printf("erik: C\n");
Eric Andersenb6106152000-06-19 17:25:40 +000047 return( TRUE);
Eric Andersen0460ff21999-10-25 23:32:44 +000048}