|
Packit Service |
50ad14 |
/*
|
|
Packit Service |
50ad14 |
* fgconsole.c - aeb - 960123 - Print foreground console
|
|
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 <sys/ioctl.h>
|
|
Packit Service |
50ad14 |
#include <getopt.h>
|
|
Packit Service |
50ad14 |
#include <linux/vt.h>
|
|
Packit Service |
50ad14 |
#include <linux/serial.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 |
static void __attribute__((noreturn))
|
|
Packit Service |
50ad14 |
usage(void)
|
|
Packit Service |
50ad14 |
{
|
|
Packit Service |
50ad14 |
fprintf(stderr, _("%s version %s\n"
|
|
Packit Service |
50ad14 |
"\n"
|
|
Packit Service |
50ad14 |
"Usage: %s [options]\n"
|
|
Packit Service |
50ad14 |
"\n"
|
|
Packit Service |
50ad14 |
"Valid options are:\n"
|
|
Packit Service |
50ad14 |
"\n"
|
|
Packit Service |
50ad14 |
" -h --help display this help text\n"
|
|
Packit Service |
50ad14 |
" -V --version display program version\n"
|
|
Packit Service |
50ad14 |
" -n --next-available display number of next unallocated VT\n"),
|
|
Packit Service |
50ad14 |
progname, PACKAGE_VERSION, progname);
|
|
Packit Service |
50ad14 |
exit(EXIT_FAILURE);
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
int main(int argc, char **argv)
|
|
Packit Service |
50ad14 |
{
|
|
Packit Service |
50ad14 |
struct vt_stat vtstat;
|
|
Packit Service |
50ad14 |
int fd, vtno = -1, c, show_vt = 0;
|
|
Packit Service |
50ad14 |
struct serial_struct sr;
|
|
Packit Service |
50ad14 |
const struct option long_opts[] = {
|
|
Packit Service |
50ad14 |
{ "help", no_argument, NULL, 'h' },
|
|
Packit Service |
50ad14 |
{ "version", no_argument, NULL, 'V' },
|
|
Packit Service |
50ad14 |
{ "next-available", no_argument, NULL, 'n' },
|
|
Packit Service |
50ad14 |
{ NULL, 0, NULL, 0 }
|
|
Packit Service |
50ad14 |
};
|
|
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 |
set_progname(argv[0]);
|
|
Packit Service |
50ad14 |
while ((c = getopt_long(argc, argv, "Vhn", long_opts, NULL)) != EOF) {
|
|
Packit Service |
50ad14 |
switch (c) {
|
|
Packit Service |
50ad14 |
case 'h':
|
|
Packit Service |
50ad14 |
usage();
|
|
Packit Service |
50ad14 |
exit(0);
|
|
Packit Service |
50ad14 |
case 'n':
|
|
Packit Service |
50ad14 |
show_vt = 1;
|
|
Packit Service |
50ad14 |
break;
|
|
Packit Service |
50ad14 |
case 'V':
|
|
Packit Service |
50ad14 |
print_version_and_exit();
|
|
Packit Service |
50ad14 |
break;
|
|
Packit Service |
50ad14 |
case '?':
|
|
Packit Service |
50ad14 |
usage();
|
|
Packit Service |
50ad14 |
exit(1);
|
|
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 (show_vt) {
|
|
Packit Service |
50ad14 |
if ((ioctl(fd, VT_OPENQRY, &vtno) < 0) || vtno == -1) {
|
|
Packit Service |
50ad14 |
kbd_error(2, errno, _("Couldn't read VTNO: "));
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
printf("%d\n", vtno);
|
|
Packit Service |
50ad14 |
return EXIT_SUCCESS;
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
if (ioctl(fd, TIOCGSERIAL, &sr) == 0) {
|
|
Packit Service |
50ad14 |
printf("serial\n");
|
|
Packit Service |
50ad14 |
return EXIT_SUCCESS;
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
if (ioctl(fd, VT_GETSTATE, &vtstat)) {
|
|
Packit Service |
50ad14 |
kbd_error(EXIT_FAILURE, errno, "fgconsole: VT_GETSTATE");
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
printf("%d\n", vtstat.v_active);
|
|
Packit Service |
50ad14 |
return EXIT_SUCCESS;
|
|
Packit Service |
50ad14 |
}
|