Acknowledge contributions of Pavel Roskin, and fix doc building
[oweals/busybox.git] / deallocvt.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * disalloc.c - aeb - 940501 - Disallocate virtual terminal(s)
4  * Renamed deallocvt.
5  */
6 #include "internal.h"
7 #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
14 char *progname;
15
16 int deallocvt_main(int argc, char *argv[])
17 {
18         int fd, num, i;
19
20         if ((argc != 2) || (**(argv + 1) == '-')) {
21                 usage
22                         ("deallocvt N\n"
23 #ifndef BB_FEATURE_TRIVIAL_HELP
24                          "\nDeallocate unused virtual terminal /dev/ttyN\n"
25 #endif
26                          );
27         }
28
29         progname = argv[0];
30
31         fd = get_console_fd("/dev/console");
32
33         if (argc == 1) {
34                 /* deallocate all unused consoles */
35                 if (ioctl(fd, VT_DISALLOCATE, 0)) {
36                         perror("VT_DISALLOCATE");
37                         exit(1);
38                 }
39         } else
40                 for (i = 1; i < argc; i++) {
41                         num = atoi(argv[i]);
42                         if (num == 0)
43                                 fprintf(stderr, "%s: 0: illegal VT number\n", progname);
44                         else if (num == 1)
45                                 fprintf(stderr, "%s: VT 1 cannot be deallocated\n",
46                                                 progname);
47                         else if (ioctl(fd, VT_DISALLOCATE, num)) {
48                                 perror("VT_DISALLOCATE");
49                                 fprintf(stderr, "%s: could not deallocate console %d\n",
50                                                 progname, num);
51                                 exit(1);
52                         }
53                 }
54         exit(0);
55 }