More stuff.
[oweals/busybox.git] / deallocvt.c
1 /*
2  * disalloc.c - aeb - 940501 - Disallocate virtual terminal(s)
3  * Renamed deallocvt.
4  */
5 #include "internal.h"
6 #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
13 extern int getfd(void);
14 char *progname;
15
16 int
17 deallocvt_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 }