fgconsole: new applet by Grigory Batalov <bga@altlinux.org>
authorGrigory Batalov <bga@altlinux.org>
Sun, 23 May 2010 21:22:10 +0000 (23:22 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sun, 23 May 2010 21:22:10 +0000 (23:22 +0200)
function                                             old     new   delta
fgconsole_main                                         -      51     +51
applet_names                                        2227    2237     +10
applet_main                                         1304    1308      +4
applet_nameofs                                       652     654      +2
applet_install_loc                                   163     164      +1
packed_usage                                       27079   27073      -6
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 4/1 up/down: 68/-6)              Total: 62 bytes

Signed-off-by: Grigory Batalov <bga@altlinux.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
console-tools/Config.in
console-tools/Kbuild
console-tools/fgconsole.c [new file with mode: 0644]
include/applets.h
include/usage.h
scripts/defconfig

index 195685b97d0a39b9f655c1c6e4e1d8747fca9f85..a7e99593645e0eaaa981293a92bf252c81895f1d 100644 (file)
@@ -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
index df5ffdb964f4329b6a5143667cff40e4867433bd..ad8b8ce774e4e754cd9b040655e7efcc4f6d9b69 100644 (file)
@@ -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 (file)
index 0000000..75fd98f
--- /dev/null
@@ -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;
+}
index ff8799c636f591cb684513bb814687d2eb0e943b..33c3c25556771b19dc334e76a35a54722defc53a 100644 (file)
@@ -157,6 +157,7 @@ IF_FBSPLASH(APPLET(fbsplash, _BB_DIR_SBIN, _BB_SUID_DROP))
 IF_FDFLUSH(APPLET_ODDNAME(fdflush, freeramdisk, _BB_DIR_BIN, _BB_SUID_DROP, fdflush))
 IF_FDFORMAT(APPLET(fdformat, _BB_DIR_USR_BIN, _BB_SUID_DROP))
 IF_FDISK(APPLET(fdisk, _BB_DIR_SBIN, _BB_SUID_DROP))
+IF_FGCONSOLE(APPLET(fgconsole, _BB_DIR_USR_BIN, _BB_SUID_DROP))
 IF_FEATURE_GREP_FGREP_ALIAS(APPLET_ODDNAME(fgrep, grep, _BB_DIR_BIN, _BB_SUID_DROP, fgrep))
 IF_FIND(APPLET_NOEXEC(find, find, _BB_DIR_USR_BIN, _BB_SUID_DROP, find))
 IF_FINDFS(APPLET(findfs, _BB_DIR_SBIN, _BB_SUID_MAYBE))
index d53b867310879e078a14a4d509e66397df487658..8b8bd2c78b42d1490c95bb0279f7ac020958c8f0 100644 (file)
      "\n       -r      Repetitions" \
      "\n       -n      Start new tone" \
 
+#define blkid_trivial_usage \
+       ""
+#define blkid_full_usage "\n\n" \
+       "Print UUIDs of all filesystems"
+
 #define bootchartd_trivial_usage \
        "start [PROG ARGS]|stop|init"
 #define bootchartd_full_usage "\n\n" \
      "\n       -H HEADS" \
      "\n       -S SECTORS" \
 
-#define blkid_trivial_usage \
-       ""
-#define blkid_full_usage "\n\n" \
-       "Print UUIDs of all filesystems"
+#define fgconsole_trivial_usage \
+       ""
+#define fgconsole_full_usage "\n\n" \
+       "Get active console"
 
 #define findfs_trivial_usage \
        "LABEL=label or UUID=uuid"
index 0a748febc88c39c488039d50863917ca80e1b8dc..8b88f79b33e7308d18d2dc5ddf635a08e3434b0f 100644 (file)
@@ -287,6 +287,7 @@ CONFIG_FEATURE_MD5_SHA1_SUM_CHECK=y
 # Console Utilities
 #
 CONFIG_CHVT=y
+CONFIG_FGCONSOLE=n
 CONFIG_CLEAR=y
 CONFIG_DEALLOCVT=y
 CONFIG_DUMPKMAP=y