blob: ae4dbb5a8cc93f4d288f9f983cf0b78d6fa88b28 [file] [log] [blame]
Eric Andersen0460ff21999-10-25 23:32:44 +00001/*
2 * disalloc.c - aeb - 940501 - Disallocate virtual terminal(s)
3 * Renamed deallocvt.
4 */
Eric Andersen6b6b3f61999-10-28 16:06:25 +00005#include "internal.h"
Eric Andersen0460ff21999-10-25 23:32:44 +00006#include <stdlib.h>
7#include <fcntl.h>
8#include <sys/types.h>
9#include <sys/ioctl.h>
10#include <linux/vt.h>
11#include <stdio.h>
12
13extern int getfd(void);
14char *progname;
15
16int
17deallocvt_main(int argc, char *argv[]) {
18 int fd, num, i;
19
20 if (argc < 1) /* unlikely */
21 exit(1);
22 progname = argv[0];
23
24 fd = get_console_fd("/dev/console");
25
26 if (argc == 1) {
27 /* deallocate all unused consoles */
28 if (ioctl(fd,VT_DISALLOCATE,0)) {
29 perror("VT_DISALLOCATE");
30 exit(1);
31 }
32 } else
33 for (i = 1; i < argc; i++) {
34 num = atoi(argv[i]);
35 if (num == 0)
36 fprintf(stderr, "%s: 0: illegal VT number\n", progname);
37 else if (num == 1)
38 fprintf(stderr, "%s: VT 1 cannot be deallocated\n", progname);
39 else
40 if (ioctl(fd,VT_DISALLOCATE,num)) {
41 perror("VT_DISALLOCATE");
42 fprintf(stderr, "%s: could not deallocate console %d\n",
43 progname, num);
44 exit(1);
45 }
46 }
47 exit(0);
48}