Note how to find list of BusyBox libc dependancies, the ide being to
[oweals/busybox.git] / console-tools / 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\nDeallocate unused virtual terminal /dev/ttyN\n");
23         }
24
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);
51 }