Replaced projects with products/projects.
[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 <stdio.h>
9 #include <fcntl.h>
10 #include <sys/types.h>
11 #include <sys/ioctl.h>
12
13 /* From <linux/vt.h> */
14 #define VT_DISALLOCATE  0x5608  /* free memory associated to vt */
15
16
17 char *progname;
18
19 int deallocvt_main(int argc, char *argv[])
20 {
21         int fd, num, i;
22
23         if ((argc != 2) || (**(argv + 1) == '-')) {
24                 usage
25                         ("deallocvt N\n"
26 #ifndef BB_FEATURE_TRIVIAL_HELP
27                          "\nDeallocate unused virtual terminal /dev/ttyN\n"
28 #endif
29                          );
30         }
31
32         progname = argv[0];
33
34         fd = get_console_fd("/dev/console");
35
36         if (argc == 1) {
37                 /* deallocate all unused consoles */
38                 if (ioctl(fd, VT_DISALLOCATE, 0)) {
39                         perror("VT_DISALLOCATE");
40                         exit( FALSE);
41                 }
42         } else
43                 for (i = 1; i < argc; i++) {
44                         num = atoi(argv[i]);
45                         if (num == 0)
46                                 fprintf(stderr, "%s: 0: illegal VT number\n", progname);
47                         else if (num == 1)
48                                 fprintf(stderr, "%s: VT 1 cannot be deallocated\n",
49                                                 progname);
50                         else if (ioctl(fd, VT_DISALLOCATE, num)) {
51                                 perror("VT_DISALLOCATE");
52                                 fprintf(stderr, "%s: could not deallocate console %d\n",
53                                                 progname, num);
54                                 exit( FALSE);
55                         }
56                 }
57         return( TRUE);
58 }