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