Apply a bandaid suggested by Jon McClintock <jonm@bluemug.com>, since deallocvt
[platform/upstream/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 <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 int deallocvt_main(int argc, char *argv[])
17 {
18         int fd, num, i;
19
20         if ((argc > 2) || ((argv == 2) && (**(argv + 1) == '-')))
21                 usage(deallocvt_usage);
22
23         fd = get_console_fd("/dev/console");
24
25         if (argc == 1) {
26                 /* deallocate all unused consoles */
27                 if (ioctl(fd, VT_DISALLOCATE, 0)) {
28                         perror("VT_DISALLOCATE");
29                         exit( FALSE);
30                 }
31         } else
32                 for (i = 1; i < argc; i++) {
33                         num = atoi(argv[i]);
34                         if (num == 0)
35                                 errorMsg("0: illegal VT number\n");
36                         else if (num == 1)
37                                 errorMsg("VT 1 cannot be deallocated\n");
38                         else if (ioctl(fd, VT_DISALLOCATE, num)) {
39                                 perror("VT_DISALLOCATE");
40                                 errorMsg("could not deallocate console %d\n", num);
41                                 exit( FALSE);
42                         }
43                 }
44         return( TRUE);
45 }