2000-02-09 03:58:47 +08:00
|
|
|
/* vi: set sw=4 ts=4: */
|
1999-10-26 07:32:44 +08:00
|
|
|
/*
|
|
|
|
* disalloc.c - aeb - 940501 - Disallocate virtual terminal(s)
|
|
|
|
* Renamed deallocvt.
|
|
|
|
*/
|
2000-09-26 05:45:58 +08:00
|
|
|
#include "busybox.h"
|
1999-10-26 07:32:44 +08:00
|
|
|
#include <stdlib.h>
|
2000-07-09 02:55:24 +08:00
|
|
|
#include <stdio.h>
|
1999-10-26 07:32:44 +08:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/ioctl.h>
|
2000-07-09 02:55:24 +08:00
|
|
|
|
|
|
|
/* From <linux/vt.h> */
|
2001-01-24 06:30:04 +08:00
|
|
|
static const int VT_DISALLOCATE = 0x5608; /* free memory associated to vt */
|
2000-07-09 02:55:24 +08:00
|
|
|
|
2000-02-09 03:58:47 +08:00
|
|
|
int deallocvt_main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int fd, num, i;
|
1999-10-26 07:32:44 +08:00
|
|
|
|
2000-09-24 03:55:59 +08:00
|
|
|
//if ((argc > 2) || ((argv == 2) && (**(argv + 1) == '-')))
|
|
|
|
if (argc > 2)
|
2000-07-15 07:28:47 +08:00
|
|
|
usage(deallocvt_usage);
|
1999-11-11 07:13:02 +08:00
|
|
|
|
2000-02-09 03:58:47 +08:00
|
|
|
fd = get_console_fd("/dev/console");
|
1999-10-26 07:32:44 +08:00
|
|
|
|
2000-02-09 03:58:47 +08:00
|
|
|
if (argc == 1) {
|
|
|
|
/* deallocate all unused consoles */
|
2000-12-22 09:48:07 +08:00
|
|
|
if (ioctl(fd, VT_DISALLOCATE, 0))
|
|
|
|
perror_msg_and_die("VT_DISALLOCATE");
|
2000-12-14 07:23:30 +08:00
|
|
|
} else {
|
2000-02-09 03:58:47 +08:00
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
num = atoi(argv[i]);
|
|
|
|
if (num == 0)
|
2000-12-08 03:56:48 +08:00
|
|
|
error_msg("0: illegal VT number\n");
|
2000-02-09 03:58:47 +08:00
|
|
|
else if (num == 1)
|
2000-12-08 03:56:48 +08:00
|
|
|
error_msg("VT 1 cannot be deallocated\n");
|
2000-12-22 09:48:07 +08:00
|
|
|
else if (ioctl(fd, VT_DISALLOCATE, num))
|
|
|
|
perror_msg_and_die("VT_DISALLOCATE");
|
2000-02-09 03:58:47 +08:00
|
|
|
}
|
2000-12-14 07:23:30 +08:00
|
|
|
}
|
|
|
|
|
2000-12-01 10:55:13 +08:00
|
|
|
return EXIT_SUCCESS;
|
1999-10-26 07:32:44 +08:00
|
|
|
}
|