copyFile could call chmod on a symlink, changing the perms
[oweals/busybox.git] / deallocvt.c
1 /*
2  * disalloc.c - aeb - 940501 - Disallocate virtual terminal(s)
3  * Renamed deallocvt.
4  */
5 #include "internal.h"
6 #include <stdlib.h>
7 #include <fcntl.h>
8 #include <sys/types.h>
9 #include <sys/ioctl.h>
10 #include <linux/vt.h>
11 #include <stdio.h>
12
13 extern int getfd(void);
14 char *progname;
15
16 int
17 deallocvt_main(int argc, char *argv[]) {
18     int fd, num, i;
19
20     if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
21         usage ("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n");
22     }
23
24     progname = argv[0];
25
26     fd = get_console_fd("/dev/console");
27
28     if (argc == 1) {
29         /* deallocate all unused consoles */
30         if (ioctl(fd,VT_DISALLOCATE,0)) {
31             perror("VT_DISALLOCATE");
32             exit(1);
33         }
34     } else
35     for (i = 1; i < argc; i++) {
36         num = atoi(argv[i]);
37         if (num == 0)
38             fprintf(stderr, "%s: 0: illegal VT number\n", progname);
39         else if (num == 1)
40             fprintf(stderr, "%s: VT 1 cannot be deallocated\n", progname);
41         else
42         if (ioctl(fd,VT_DISALLOCATE,num)) {
43             perror("VT_DISALLOCATE");
44             fprintf(stderr, "%s: could not deallocate console %d\n",
45                     progname, num);
46             exit(1);
47         }
48     }
49     exit(0);
50 }