|
Packit Service |
50ad14 |
/*
|
|
Packit Service |
50ad14 |
* disalloc.c - aeb - 940501 - Disallocate virtual terminal(s)
|
|
Packit Service |
50ad14 |
* Renamed deallocvt.
|
|
Packit Service |
50ad14 |
*/
|
|
Packit Service |
50ad14 |
#include "config.h"
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
#include <stdio.h>
|
|
Packit Service |
50ad14 |
#include <stdlib.h>
|
|
Packit Service |
50ad14 |
#include <errno.h>
|
|
Packit Service |
50ad14 |
#include <fcntl.h>
|
|
Packit Service |
50ad14 |
#include <ctype.h>
|
|
Packit Service |
50ad14 |
#include <sys/types.h>
|
|
Packit Service |
50ad14 |
#include <sys/ioctl.h>
|
|
Packit Service |
50ad14 |
#include <linux/vt.h>
|
|
Packit Service |
50ad14 |
#include "getfd.h"
|
|
Packit Service |
50ad14 |
#include "nls.h"
|
|
Packit Service |
50ad14 |
#include "version.h"
|
|
Packit Service |
50ad14 |
#include "kbd_error.h"
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
int main(int argc, char *argv[])
|
|
Packit Service |
50ad14 |
{
|
|
Packit Service |
50ad14 |
int fd, num, i;
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
if (argc < 1) /* unlikely */
|
|
Packit Service |
50ad14 |
return EXIT_FAILURE;
|
|
Packit Service |
50ad14 |
set_progname(argv[0]);
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
setlocale(LC_ALL, "");
|
|
Packit Service |
50ad14 |
bindtextdomain(PACKAGE_NAME, LOCALEDIR);
|
|
Packit Service |
50ad14 |
textdomain(PACKAGE_NAME);
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
if (argc == 2 && !strcmp(argv[1], "-V"))
|
|
Packit Service |
50ad14 |
print_version_and_exit();
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
for (i = 1; i < argc; i++) {
|
|
Packit Service |
50ad14 |
if (!isdigit(argv[i][0])) {
|
|
Packit Service |
50ad14 |
fprintf(stderr, _("%s: unknown option\n"), progname);
|
|
Packit Service |
50ad14 |
return EXIT_FAILURE;
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
if ((fd = getfd(NULL)) < 0)
|
|
Packit Service |
50ad14 |
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
if (argc == 1) {
|
|
Packit Service |
50ad14 |
/* deallocate all unused consoles */
|
|
Packit Service |
50ad14 |
if (ioctl(fd, VT_DISALLOCATE, 0)) {
|
|
Packit Service |
50ad14 |
kbd_error(EXIT_FAILURE, errno, "ioctl VT_DISALLOCATE");
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
} else
|
|
Packit Service |
50ad14 |
for (i = 1; i < argc; i++) {
|
|
Packit Service |
50ad14 |
num = atoi(argv[i]);
|
|
Packit Service |
50ad14 |
if (num == 0) {
|
|
Packit Service |
50ad14 |
kbd_error(EXIT_FAILURE, 0, _("0: illegal VT number\n"));
|
|
Packit Service |
50ad14 |
} else if (num == 1) {
|
|
Packit Service |
50ad14 |
kbd_error(EXIT_FAILURE, 0, _("VT 1 is the console and cannot be deallocated\n"));
|
|
Packit Service |
50ad14 |
} else if (ioctl(fd, VT_DISALLOCATE, num)) {
|
|
Packit Service |
50ad14 |
kbd_error(EXIT_FAILURE, errno, _("could not deallocate console %d: "
|
|
Packit Service |
50ad14 |
"ioctl VT_DISALLOCATE"),
|
|
Packit Service |
50ad14 |
num);
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
exit(EXIT_SUCCESS);
|
|
Packit Service |
50ad14 |
}
|