f641be8d76a34101f16b4ed15f74aa528db17506
[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 <stdlib.h>
7 #include <stdio.h>
8 #include <fcntl.h>
9 #include <sys/types.h>
10 #include <sys/ioctl.h>
11 #include "busybox.h"
12
13 /* From <linux/vt.h> */
14 static const int VT_DISALLOCATE = 0x5608;  /* free memory associated to vt */
15
16 int deallocvt_main(int argc, char *argv[])
17 {
18         int fd, num=0;
19
20         if (argc > 2)
21                 bb_show_usage();
22
23         fd = get_console_fd();
24         
25         /*  num=0  deallocate all unused consoles */
26         if (argc == 1)
27                 goto disallocate_all;
28
29         num=bb_xgetlarg(argv[1], 10, 0, INT_MAX);
30
31         switch(num)
32         {
33                 case 0:
34                         bb_error_msg("0: illegal VT number");
35                         break;
36                 case 1:
37                         bb_error_msg("VT 1 cannot be deallocated");
38                         break;
39                 default:
40 disallocate_all:
41                         if (ioctl(fd, VT_DISALLOCATE, num))
42                                 bb_perror_msg_and_die("VT_DISALLOCATE");
43                         return EXIT_SUCCESS;
44         }
45         return EXIT_FAILURE;
46 }