blob: 141062edc6e1416f12ede66badaffb4b4cb1b11d [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>
8#include <fcntl.h>
9#include <sys/types.h>
10#include <sys/ioctl.h>
11#include <linux/vt.h>
12#include <stdio.h>
13
14extern int getfd(void);
15char *progname;
16
Erik Andersene49d5ec2000-02-08 19:58:47 +000017int deallocvt_main(int argc, char *argv[])
18{
19 int fd, num, i;
Eric Andersen0460ff21999-10-25 23:32:44 +000020
Erik Andersene49d5ec2000-02-08 19:58:47 +000021 if ((argc != 2) || (**(argv + 1) == '-')) {
22 usage
23 ("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n");
Eric Andersen0460ff21999-10-25 23:32:44 +000024 }
Erik Andersene49d5ec2000-02-08 19:58:47 +000025
26 progname = argv[0];
27
28 fd = get_console_fd("/dev/console");
29
30 if (argc == 1) {
31 /* deallocate all unused consoles */
32 if (ioctl(fd, VT_DISALLOCATE, 0)) {
33 perror("VT_DISALLOCATE");
34 exit(1);
35 }
36 } else
37 for (i = 1; i < argc; i++) {
38 num = atoi(argv[i]);
39 if (num == 0)
40 fprintf(stderr, "%s: 0: illegal VT number\n", progname);
41 else if (num == 1)
42 fprintf(stderr, "%s: VT 1 cannot be deallocated\n",
43 progname);
44 else if (ioctl(fd, VT_DISALLOCATE, num)) {
45 perror("VT_DISALLOCATE");
46 fprintf(stderr, "%s: could not deallocate console %d\n",
47 progname, num);
48 exit(1);
49 }
50 }
51 exit(0);
Eric Andersen0460ff21999-10-25 23:32:44 +000052}