diff options
Diffstat (limited to 'src/ck-sysdeps-linux.c')
-rw-r--r-- | src/ck-sysdeps-linux.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/ck-sysdeps-linux.c b/src/ck-sysdeps-linux.c index fcf3b4e..7dc99f7 100644 --- a/src/ck-sysdeps-linux.c +++ b/src/ck-sysdeps-linux.c @@ -25,8 +25,10 @@ #include <fcntl.h> #include <unistd.h> #include <string.h> +#include <errno.h> #include <sys/types.h> #include <sys/stat.h> +#include <sys/ioctl.h> #include <sys/vt.h> #include <linux/tty.h> @@ -38,6 +40,10 @@ #include "ck-sysdeps.h" +#ifndef ERROR +#define ERROR -1 +#endif + /* adapted from procps */ struct _CkProcessStat { @@ -655,3 +661,46 @@ ck_get_console_num_from_device (const char *device, return ret; } + +gboolean +ck_get_active_console_num (int console_fd, + guint *num) +{ + gboolean ret; + int res; + guint active; + struct vt_stat stat; + + g_assert (console_fd != -1); + + active = 0; + ret = FALSE; + + res = ioctl (console_fd, VT_GETSTATE, &stat); + if (res == ERROR) { + perror ("ioctl VT_GETSTATE"); + goto out; + } + + { + int i; + + g_debug ("Current VT: tty%d", stat.v_active); + for (i = 1; i <= 16; i++) { + gboolean is_on; + is_on = stat.v_state & (1 << i); + + g_debug ("VT %d:%s", i, is_on ? "on" : "off"); + } + } + + active = stat.v_active; + ret = TRUE; + + out: + if (num != NULL) { + *num = active; + } + + return ret; +} |