blob: 1e13ff69cef561b310453195fcb12c4b51a60d68 [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
Eric Andersend73dc5b1999-11-10 23:13:02 +000020 if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
21 usage ("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n");
22 }
23
Eric Andersen0460ff21999-10-25 23:32:44 +000024 progname = argv[0];
25
26 fd = get_console_fd("/dev/console");
27
28 if (argc == 1) {
29 /* deallocate all unused consoles */
30 if (ioctl(fd,VT_DISALLOCATE,0)) {
31 perror("VT_DISALLOCATE");
32 exit(1);
33 }
34 } else
35 for (i = 1; i < argc; i++) {
36 num = atoi(argv[i]);
37 if (num == 0)
38 fprintf(stderr, "%s: 0: illegal VT number\n", progname);
39 else if (num == 1)
40 fprintf(stderr, "%s: VT 1 cannot be deallocated\n", progname);
41 else
42 if (ioctl(fd,VT_DISALLOCATE,num)) {
43 perror("VT_DISALLOCATE");
44 fprintf(stderr, "%s: could not deallocate console %d\n",
45 progname, num);
46 exit(1);
47 }
48 }
49 exit(0);
50}