diff options
author | William Jon McCann <mccann@jhu.edu> | 2007-08-14 12:12:38 -0400 |
---|---|---|
committer | William Jon McCann <mccann@jhu.edu> | 2007-08-14 12:12:38 -0400 |
commit | d4033604529b64156d5dd0f03fbe733ec7ae8246 (patch) | |
tree | 332aac193678d64a359d65e5f5d66c43b2399a5a /src/test-tty-idle-monitor.c | |
parent | 396363e70765af215f7302964ac9543305733a2b (diff) |
make sure the device is a console and add some instructions
Diffstat (limited to 'src/test-tty-idle-monitor.c')
-rw-r--r-- | src/test-tty-idle-monitor.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/test-tty-idle-monitor.c b/src/test-tty-idle-monitor.c index d3725a4..8517f75 100644 --- a/src/test-tty-idle-monitor.c +++ b/src/test-tty-idle-monitor.c @@ -23,11 +23,19 @@ #include <stdlib.h> #include <stdio.h> +#include <unistd.h> #include <sys/types.h> +#include <sys/stat.h> +#include <sys/ioctl.h> +#include <fcntl.h> #include <pwd.h> #include <string.h> #include <errno.h> +#ifdef __linux__ +#include <linux/kd.h> +#endif + #include <locale.h> #include <glib.h> @@ -42,6 +50,35 @@ idle_changed_cb (CkTtyIdleMonitor *monitor, g_message ("idle hint changed: %s", idle_hint ? "idle" : "not idle"); } +static gboolean +is_console (const char *device) +{ + int fd; + gboolean ret; + int kb_ok; + char arg; + + ret = FALSE; + fd = open (device, O_RDONLY | O_NOCTTY); + if (fd < 0) { + goto out; + } + +#ifdef __linux__ + kb_ok = (ioctl (fd, KDGKBTYPE, &arg) == 0 + && ((arg == KB_101) || (arg == KB_84))); +#else + kb_ok = 1; +#endif + + ret = (isatty (fd) && kb_ok); + + close (fd); + + out: + return ret; +} + int main (int argc, char **argv) { @@ -60,6 +97,13 @@ main (int argc, char **argv) device = g_strdup (argv[1]); } + if (! is_console (device)) { + g_warning ("Device is not a console"); + exit (1); + } + + g_message ("Testing the TTY idle monitor.\n1. Wait for idleness to be detected.\n2. Hit keys on the keyboard to see if activity is noticed."); + monitor = ck_tty_idle_monitor_new (device); g_signal_connect (monitor, |