2 * fgconsole.c - aeb - 960123 - Print foreground console
9 #include <linux/serial.h>
14 static void attr_noreturn
17 fprintf(stderr, _("%s version %s\n"
19 "Usage: %s [options]\n"
21 "Valid options are:\n"
23 " -h --help display this help text\n"
24 " -V --version display program version\n"
25 " -n --next-available display number of next unallocated VT\n"),
26 progname, PACKAGE_VERSION, progname);
31 main(int argc, char **argv){
32 struct vt_stat vtstat;
33 int fd, vtno = -1, c, show_vt = 0;
34 struct serial_struct sr;
35 const struct option long_opts[] = {
36 { "help", no_argument, NULL, 'h' },
37 { "version", no_argument, NULL, 'V' },
38 { "next-available", no_argument, NULL, 'n' },
39 { NULL, 0, NULL, 0 } };
42 setlocale(LC_ALL, "");
43 bindtextdomain(PACKAGE_NAME, LOCALEDIR);
44 textdomain(PACKAGE_NAME);
47 set_progname(argv[0]);
48 while (( c = getopt_long (argc, argv, "Vhn", long_opts, NULL)) != EOF) {
57 print_version_and_exit();
67 if ((ioctl(fd, VT_OPENQRY, &vtno) < 0) || vtno == -1) {
68 perror (_("Couldn't read VTNO: "));
71 printf ("%d\n", vtno);
75 if (ioctl(fd, TIOCGSERIAL, &sr) == 0) {
80 if (ioctl(fd, VT_GETSTATE, &vtstat))
82 perror("fgconsole: VT_GETSTATE");
85 printf("%d\n", vtstat.v_active);