Use global applet_name instead of local versions.
[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 int deallocvt_main(int argc, char *argv[])
18 {
19         int fd, num, i;
20
21         if ((argc != 2) || (**(argv + 1) == '-')) {
22                 usage
23                         ("deallocvt N\n"
24 #ifndef BB_FEATURE_TRIVIAL_HELP
25                          "\nDeallocate unused virtual terminal /dev/ttyN\n"
26 #endif
27                          );
28         }
29
30         fd = get_console_fd("/dev/console");
31
32         if (argc == 1) {
33                 /* deallocate all unused consoles */
34                 if (ioctl(fd, VT_DISALLOCATE, 0)) {
35                         perror("VT_DISALLOCATE");
36                         exit( FALSE);
37                 }
38         } else
39                 for (i = 1; i < argc; i++) {
40                         num = atoi(argv[i]);
41                         if (num == 0)
42                                 fprintf(stderr, "%s: 0: illegal VT number\n", applet_name);
43                         else if (num == 1)
44                                 fprintf(stderr, "%s: VT 1 cannot be deallocated\n",
45                                                 applet_name);
46                         else if (ioctl(fd, VT_DISALLOCATE, num)) {
47                                 perror("VT_DISALLOCATE");
48                                 fprintf(stderr, "%s: could not deallocate console %d\n",
49                                                 applet_name, num);
50                                 exit( FALSE);
51                         }
52                 }
53         return( TRUE);
54 }