fgconsole.c 922 B

1234567891011121314151617181920212223242526272829303132333435
  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. //usage:#define fgconsole_trivial_usage
  10. //usage: ""
  11. //usage:#define fgconsole_full_usage "\n\n"
  12. //usage: "Get active console"
  13. #include "libbb.h"
  14. /* From <linux/vt.h> */
  15. struct vt_stat {
  16. unsigned short v_active; /* active vt */
  17. unsigned short v_signal; /* signal to send */
  18. unsigned short v_state; /* vt bitmask */
  19. };
  20. enum { VT_GETSTATE = 0x5603 }; /* get global vt state info */
  21. int fgconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  22. int fgconsole_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
  23. {
  24. struct vt_stat vtstat;
  25. vtstat.v_active = 0;
  26. xioctl(get_console_fd_or_die(), VT_GETSTATE, &vtstat);
  27. printf("%d\n", vtstat.v_active);
  28. return EXIT_SUCCESS;
  29. }