2 * fgconsole.c - aeb - 960123 - Print foreground console
13 #include <linux/serial.h>
15 #include "libcommon.h"
17 static void __attribute__((noreturn))
20 const char *progname = get_progname();
21 fprintf(stderr, _("%s version %s\n"
23 "Usage: %s [options]\n"
25 "Valid options are:\n"
27 " -h --help display this help text\n"
28 " -V --version display program version\n"
29 " -n --next-available display number of next unallocated VT\n"),
30 progname, PACKAGE_VERSION, progname);
34 int main(int argc, char **argv)
36 struct vt_stat vtstat;
37 int fd, vtno = -1, c, show_vt = 0;
38 struct serial_struct sr;
39 const struct option long_opts[] = {
40 { "help", no_argument, NULL, 'h' },
41 { "version", no_argument, NULL, 'V' },
42 { "next-available", no_argument, NULL, 'n' },
46 set_progname(argv[0]);
49 while ((c = getopt_long(argc, argv, "Vhn", long_opts, NULL)) != EOF) {
55 print_version_and_exit();
66 if ((fd = getfd(NULL)) < 0)
67 kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
70 if ((ioctl(fd, VT_OPENQRY, &vtno) < 0) || vtno == -1) {
71 kbd_error(2, errno, _("Couldn't read VTNO: "));
77 if (ioctl(fd, TIOCGSERIAL, &sr) == 0) {
82 if (ioctl(fd, VT_GETSTATE, &vtstat)) {
83 kbd_error(EXIT_FAILURE, errno, "fgconsole: VT_GETSTATE");
85 printf("%d\n", vtstat.v_active);