blob: ebdce7b24925bb7c5276ffa8ec23e8fff2973afd [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 Andersen3570a342000-09-25 21:45:58 +00006#include "busybox.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
Erik Andersene49d5ec2000-02-08 19:58:47 +000016int deallocvt_main(int argc, char *argv[])
17{
18 int fd, num, i;
Eric Andersen0460ff21999-10-25 23:32:44 +000019
Eric Andersen32e95f92000-09-23 19:55:59 +000020 //if ((argc > 2) || ((argv == 2) && (**(argv + 1) == '-')))
21 if (argc > 2)
Matt Kraai3bd8bd82000-07-14 23:28:47 +000022 usage(deallocvt_usage);
Erik Andersene49d5ec2000-02-08 19:58:47 +000023
Erik Andersene49d5ec2000-02-08 19:58:47 +000024 fd = get_console_fd("/dev/console");
25
26 if (argc == 1) {
Eric Andersen32e95f92000-09-23 19:55:59 +000027printf("erik: A\n");
Erik Andersene49d5ec2000-02-08 19:58:47 +000028 /* deallocate all unused consoles */
29 if (ioctl(fd, VT_DISALLOCATE, 0)) {
30 perror("VT_DISALLOCATE");
Matt Kraai3e856ce2000-12-01 02:55:13 +000031 return EXIT_FAILURE;
Erik Andersene49d5ec2000-02-08 19:58:47 +000032 }
33 } else
Eric Andersen32e95f92000-09-23 19:55:59 +000034printf("erik: B\n");
Erik Andersene49d5ec2000-02-08 19:58:47 +000035 for (i = 1; i < argc; i++) {
36 num = atoi(argv[i]);
37 if (num == 0)
Mark Whitleyf57c9442000-12-07 19:56:48 +000038 error_msg("0: illegal VT number\n");
Erik Andersene49d5ec2000-02-08 19:58:47 +000039 else if (num == 1)
Mark Whitleyf57c9442000-12-07 19:56:48 +000040 error_msg("VT 1 cannot be deallocated\n");
Erik Andersene49d5ec2000-02-08 19:58:47 +000041 else if (ioctl(fd, VT_DISALLOCATE, num)) {
42 perror("VT_DISALLOCATE");
Mark Whitleyf57c9442000-12-07 19:56:48 +000043 error_msg_and_die("could not deallocate console %d\n", num);
Erik Andersene49d5ec2000-02-08 19:58:47 +000044 }
45 }
Eric Andersen32e95f92000-09-23 19:55:59 +000046printf("erik: C\n");
Matt Kraai3e856ce2000-12-01 02:55:13 +000047 return EXIT_SUCCESS;
Eric Andersen0460ff21999-10-25 23:32:44 +000048}