Grigory Batalov | ad7a5d4 | 2010-05-23 23:22:10 +0200 | [diff] [blame] | 1 | /* 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 Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Grigory Batalov | ad7a5d4 | 2010-05-23 23:22:10 +0200 | [diff] [blame] | 8 | */ |
Denys Vlasenko | 6d93299 | 2016-11-23 10:39:27 +0100 | [diff] [blame] | 9 | //config:config FGCONSOLE |
| 10 | //config: bool "fgconsole" |
| 11 | //config: default y |
| 12 | //config: select PLATFORM_LINUX |
| 13 | //config: help |
| 14 | //config: This program prints active (foreground) console number. |
| 15 | |
| 16 | //applet:IF_FGCONSOLE(APPLET(fgconsole, BB_DIR_USR_BIN, BB_SUID_DROP)) |
| 17 | |
| 18 | //kbuild:lib-$(CONFIG_FGCONSOLE) += fgconsole.o |
Grigory Batalov | ad7a5d4 | 2010-05-23 23:22:10 +0200 | [diff] [blame] | 19 | |
Pere Orga | 55068c4 | 2011-03-27 23:42:28 +0200 | [diff] [blame] | 20 | //usage:#define fgconsole_trivial_usage |
| 21 | //usage: "" |
| 22 | //usage:#define fgconsole_full_usage "\n\n" |
| 23 | //usage: "Get active console" |
| 24 | |
Grigory Batalov | ad7a5d4 | 2010-05-23 23:22:10 +0200 | [diff] [blame] | 25 | #include "libbb.h" |
| 26 | |
| 27 | /* From <linux/vt.h> */ |
| 28 | struct vt_stat { |
| 29 | unsigned short v_active; /* active vt */ |
| 30 | unsigned short v_signal; /* signal to send */ |
| 31 | unsigned short v_state; /* vt bitmask */ |
| 32 | }; |
| 33 | enum { VT_GETSTATE = 0x5603 }; /* get global vt state info */ |
| 34 | |
| 35 | int fgconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 36 | int fgconsole_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) |
| 37 | { |
| 38 | struct vt_stat vtstat; |
| 39 | |
| 40 | vtstat.v_active = 0; |
| 41 | xioctl(get_console_fd_or_die(), VT_GETSTATE, &vtstat); |
| 42 | printf("%d\n", vtstat.v_active); |
| 43 | |
| 44 | return EXIT_SUCCESS; |
| 45 | } |