From d4033604529b64156d5dd0f03fbe733ec7ae8246 Mon Sep 17 00:00:00 2001 From: William Jon McCann Date: Tue, 14 Aug 2007 12:12:38 -0400 Subject: make sure the device is a console and add some instructions --- src/test-tty-idle-monitor.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/test-tty-idle-monitor.c') 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 #include +#include #include +#include +#include +#include #include #include #include +#ifdef __linux__ +#include +#endif + #include #include @@ -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, -- cgit