2010-05-24 02:52:10 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
|
|
|
* Mini fgconsole implementation for busybox
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 by Grigory Batalov <bga@altlinux.org>
|
|
|
|
*
|
2010-08-16 23:44:46 +05:30
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2010-05-24 02:52:10 +05:30
|
|
|
*/
|
2016-11-23 15:09:27 +05:30
|
|
|
//config:config FGCONSOLE
|
2017-07-19 01:31:24 +05:30
|
|
|
//config: bool "fgconsole (1.6 kb)"
|
2016-11-23 15:09:27 +05:30
|
|
|
//config: default y
|
|
|
|
//config: select PLATFORM_LINUX
|
|
|
|
//config: help
|
2017-07-21 13:20:55 +05:30
|
|
|
//config: This program prints active (foreground) console number.
|
2016-11-23 15:09:27 +05:30
|
|
|
|
|
|
|
//applet:IF_FGCONSOLE(APPLET(fgconsole, BB_DIR_USR_BIN, BB_SUID_DROP))
|
|
|
|
|
|
|
|
//kbuild:lib-$(CONFIG_FGCONSOLE) += fgconsole.o
|
2010-05-24 02:52:10 +05:30
|
|
|
|
2011-03-28 03:12:28 +05:30
|
|
|
//usage:#define fgconsole_trivial_usage
|
|
|
|
//usage: ""
|
|
|
|
//usage:#define fgconsole_full_usage "\n\n"
|
|
|
|
//usage: "Get active console"
|
|
|
|
|
2010-05-24 02:52:10 +05:30
|
|
|
#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;
|
|
|
|
}
|