3
0

fgconsole.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. *
  7. * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  8. */
  9. //config:config FGCONSOLE
  10. //config: bool "fgconsole (1.5 kb)"
  11. //config: default y
  12. //config: select PLATFORM_LINUX
  13. //config: help
  14. //config: This program prints active (foreground) console number.
  15. //applet:IF_FGCONSOLE(APPLET_NOEXEC(fgconsole, fgconsole, BB_DIR_USR_BIN, BB_SUID_DROP, fgconsole))
  16. //kbuild:lib-$(CONFIG_FGCONSOLE) += fgconsole.o
  17. //usage:#define fgconsole_trivial_usage
  18. //usage: ""
  19. //usage:#define fgconsole_full_usage "\n\n"
  20. //usage: "Get active console"
  21. #include "libbb.h"
  22. /* From <linux/vt.h> */
  23. struct vt_stat {
  24. unsigned short v_active; /* active vt */
  25. unsigned short v_signal; /* signal to send */
  26. unsigned short v_state; /* vt bitmask */
  27. };
  28. enum { VT_GETSTATE = 0x5603 }; /* get global vt state info */
  29. int fgconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  30. int fgconsole_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
  31. {
  32. struct vt_stat vtstat;
  33. vtstat.v_active = 0;
  34. xioctl(get_console_fd_or_die(), VT_GETSTATE, &vtstat);
  35. printf("%d\n", vtstat.v_active);
  36. return EXIT_SUCCESS;
  37. }