summaryrefslogtreecommitdiffhomepage
path: root/console-tools/fgconsole.c
blob: 54355bee61f94cffe14a75f71130eb65b879d8a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* 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 source tree.
 */

//usage:#define fgconsole_trivial_usage
//usage:	""
//usage:#define fgconsole_full_usage "\n\n"
//usage:	"Get active console"

#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;
}