blob: 0cad7717b644ce7cb7aa432d21ab6152f9fada24 [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Eric Andersen0460ff21999-10-25 23:32:44 +00002/*
3 * disalloc.c - aeb - 940501 - Disallocate virtual terminal(s)
4 * Renamed deallocvt.
5 */
Eric Andersen6b6b3f61999-10-28 16:06:25 +00006#include "internal.h"
Eric Andersen0460ff21999-10-25 23:32:44 +00007#include <stdlib.h>
Eric Andersenbd22ed82000-07-08 18:55:24 +00008#include <stdio.h>
Eric Andersen0460ff21999-10-25 23:32:44 +00009#include <fcntl.h>
10#include <sys/types.h>
11#include <sys/ioctl.h>
Eric Andersenbd22ed82000-07-08 18:55:24 +000012
13/* From <linux/vt.h> */
14#define VT_DISALLOCATE 0x5608 /* free memory associated to vt */
15
Eric Andersen0460ff21999-10-25 23:32:44 +000016
Eric Andersen0460ff21999-10-25 23:32:44 +000017char *progname;
18
Erik Andersene49d5ec2000-02-08 19:58:47 +000019int deallocvt_main(int argc, char *argv[])
20{
21 int fd, num, i;
Eric Andersen0460ff21999-10-25 23:32:44 +000022
Erik Andersene49d5ec2000-02-08 19:58:47 +000023 if ((argc != 2) || (**(argv + 1) == '-')) {
24 usage
Erik Andersen59b9e872000-05-10 05:05:45 +000025 ("deallocvt N\n"
26#ifndef BB_FEATURE_TRIVIAL_HELP
27 "\nDeallocate unused virtual terminal /dev/ttyN\n"
28#endif
29 );
Eric Andersen0460ff21999-10-25 23:32:44 +000030 }
Erik Andersene49d5ec2000-02-08 19:58:47 +000031
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");
Eric Andersenb6106152000-06-19 17:25:40 +000040 exit( FALSE);
Erik Andersene49d5ec2000-02-08 19:58:47 +000041 }
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);
Eric Andersenb6106152000-06-19 17:25:40 +000054 exit( FALSE);
Erik Andersene49d5ec2000-02-08 19:58:47 +000055 }
56 }
Eric Andersenb6106152000-06-19 17:25:40 +000057 return( TRUE);
Eric Andersen0460ff21999-10-25 23:32:44 +000058}