1 /* vi: set sw=4 ts=4: */
3 * Mini fgconsole implementation for busybox
5 * Copyright (C) 2010 by Grigory Batalov <bga@altlinux.org>
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
9 //config:config FGCONSOLE
10 //config: bool "fgconsole (1.6 kb)"
12 //config: select PLATFORM_LINUX
14 //config: This program prints active (foreground) console number.
16 //applet:IF_FGCONSOLE(APPLET(fgconsole, BB_DIR_USR_BIN, BB_SUID_DROP))
18 //kbuild:lib-$(CONFIG_FGCONSOLE) += fgconsole.o
20 //usage:#define fgconsole_trivial_usage
22 //usage:#define fgconsole_full_usage "\n\n"
23 //usage: "Get active console"
27 /* From <linux/vt.h> */
29 unsigned short v_active; /* active vt */
30 unsigned short v_signal; /* signal to send */
31 unsigned short v_state; /* vt bitmask */
33 enum { VT_GETSTATE = 0x5603 }; /* get global vt state info */
35 int fgconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
36 int fgconsole_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
38 struct vt_stat vtstat;
41 xioctl(get_console_fd_or_die(), VT_GETSTATE, &vtstat);
42 printf("%d\n", vtstat.v_active);