blob: a5b5a03f01d1e8185bd5a00dc8c202e18f513401 [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 Andersena1b35c42000-09-22 00:40:39 +000020 if ((argc > 2) || ((argv == 2) && (**(argv + 1) == '-')))
Matt Kraai3bd8bd82000-07-14 23:28:47 +000021 usage(deallocvt_usage);
Erik Andersene49d5ec2000-02-08 19:58:47 +000022
Erik Andersene49d5ec2000-02-08 19:58:47 +000023 fd = get_console_fd("/dev/console");
24
25 if (argc == 1) {
26 /* deallocate all unused consoles */
27 if (ioctl(fd, VT_DISALLOCATE, 0)) {
28 perror("VT_DISALLOCATE");
Eric Andersenb6106152000-06-19 17:25:40 +000029 exit( FALSE);
Erik Andersene49d5ec2000-02-08 19:58:47 +000030 }
31 } else
32 for (i = 1; i < argc; i++) {
33 num = atoi(argv[i]);
34 if (num == 0)
Matt Kraaid537a952000-07-14 01:51:25 +000035 errorMsg("0: illegal VT number\n");
Erik Andersene49d5ec2000-02-08 19:58:47 +000036 else if (num == 1)
Matt Kraaid537a952000-07-14 01:51:25 +000037 errorMsg("VT 1 cannot be deallocated\n");
Erik Andersene49d5ec2000-02-08 19:58:47 +000038 else if (ioctl(fd, VT_DISALLOCATE, num)) {
39 perror("VT_DISALLOCATE");
Matt Kraaid537a952000-07-14 01:51:25 +000040 errorMsg("could not deallocate console %d\n", num);
Eric Andersenb6106152000-06-19 17:25:40 +000041 exit( FALSE);
Erik Andersene49d5ec2000-02-08 19:58:47 +000042 }
43 }
Eric Andersenb6106152000-06-19 17:25:40 +000044 return( TRUE);
Eric Andersen0460ff21999-10-25 23:32:44 +000045}