summaryrefslogtreecommitdiff
path: root/console-tools
diff options
context:
space:
mode:
Diffstat (limited to 'console-tools')
-rw-r--r--console-tools/Config.in6
-rw-r--r--console-tools/Kbuild1
-rw-r--r--console-tools/fgconsole.c30
3 files changed, 37 insertions, 0 deletions
diff --git a/console-tools/Config.in b/console-tools/Config.in
index 195685b..a7e9959 100644
--- a/console-tools/Config.in
+++ b/console-tools/Config.in
@@ -12,6 +12,12 @@ config CHVT
This program is used to change to another terminal.
Example: chvt 4 (change to terminal /dev/tty4)
+config FGCONSOLE
+ bool "fgconsole"
+ default n
+ help
+ This program prints active (foreground) console number.
+
config CLEAR
bool "clear"
default n
diff --git a/console-tools/Kbuild b/console-tools/Kbuild
index df5ffdb..ad8b8ce 100644
--- a/console-tools/Kbuild
+++ b/console-tools/Kbuild
@@ -6,6 +6,7 @@
lib-y:=
lib-$(CONFIG_CHVT) += chvt.o
+lib-$(CONFIG_FGCONSOLE) += fgconsole.o
lib-$(CONFIG_CLEAR) += clear.o
lib-$(CONFIG_DEALLOCVT) += deallocvt.o
lib-$(CONFIG_DUMPKMAP) += dumpkmap.o
diff --git a/console-tools/fgconsole.c b/console-tools/fgconsole.c
new file mode 100644
index 0000000..75fd98f
--- /dev/null
+++ b/console-tools/fgconsole.c
@@ -0,0 +1,30 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Mini fgconsole implementation for busybox
+ *
+ * Copyright (C) 2010 by Grigory Batalov <bga@altlinux.org>
+ *
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
+ */
+
+#include "libbb.h"
+
+/* From <linux/vt.h> */
+struct vt_stat {
+ unsigned short v_active; /* active vt */
+ unsigned short v_signal; /* signal to send */
+ unsigned short v_state; /* vt bitmask */
+};
+enum { VT_GETSTATE = 0x5603 }; /* get global vt state info */
+
+int fgconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int fgconsole_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
+{
+ struct vt_stat vtstat;
+
+ vtstat.v_active = 0;
+ xioctl(get_console_fd_or_die(), VT_GETSTATE, &vtstat);
+ printf("%d\n", vtstat.v_active);
+
+ return EXIT_SUCCESS;
+}