blob: 9bfb68017d90f94ff54f3a51248b405f7f357eab [file] [log] [blame]
Grigory Batalovad7a5d42010-05-23 23:22:10 +02001/* vi: set sw=4 ts=4: */
2/*
3 * Mini fgconsole implementation for busybox
4 *
5 * Copyright (C) 2010 by Grigory Batalov <bga@altlinux.org>
6 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02007 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Grigory Batalovad7a5d42010-05-23 23:22:10 +02008 */
Denys Vlasenko6d932992016-11-23 10:39:27 +01009//config:config FGCONSOLE
Denys Vlasenkob097a842018-12-28 03:20:17 +010010//config: bool "fgconsole (1.5 kb)"
Denys Vlasenko6d932992016-11-23 10:39:27 +010011//config: default y
Denys Vlasenko6d932992016-11-23 10:39:27 +010012//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020013//config: This program prints active (foreground) console number.
Denys Vlasenko6d932992016-11-23 10:39:27 +010014
Denys Vlasenkoff53bee2017-08-05 02:02:31 +020015//applet:IF_FGCONSOLE(APPLET_NOEXEC(fgconsole, fgconsole, BB_DIR_USR_BIN, BB_SUID_DROP, fgconsole))
Denys Vlasenko6d932992016-11-23 10:39:27 +010016
17//kbuild:lib-$(CONFIG_FGCONSOLE) += fgconsole.o
Grigory Batalovad7a5d42010-05-23 23:22:10 +020018
Pere Orga55068c42011-03-27 23:42:28 +020019//usage:#define fgconsole_trivial_usage
20//usage: ""
21//usage:#define fgconsole_full_usage "\n\n"
22//usage: "Get active console"
23
Grigory Batalovad7a5d42010-05-23 23:22:10 +020024#include "libbb.h"
25
26/* From <linux/vt.h> */
27struct vt_stat {
28 unsigned short v_active; /* active vt */
29 unsigned short v_signal; /* signal to send */
30 unsigned short v_state; /* vt bitmask */
31};
32enum { VT_GETSTATE = 0x5603 }; /* get global vt state info */
33
34int fgconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
35int fgconsole_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
36{
37 struct vt_stat vtstat;
38
39 vtstat.v_active = 0;
40 xioctl(get_console_fd_or_die(), VT_GETSTATE, &vtstat);
41 printf("%d\n", vtstat.v_active);
42
43 return EXIT_SUCCESS;
44}