From 167c4cbea6bce3dc763b93cf13bbc1d5c4a103c6 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Fri, 11 Jan 2013 22:28:59 -0600 Subject: Fix tsak not working on new libudev versions Fix kicker Xinerama hiding Fix potential displayconfig lockup --- tsak/main.cpp | 65 ++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 25 deletions(-) (limited to 'tsak') diff --git a/tsak/main.cpp b/tsak/main.cpp index 726f779fa..646a9d45d 100644 --- a/tsak/main.cpp +++ b/tsak/main.cpp @@ -1,6 +1,6 @@ /* Copyright 2010 Adam Marchetti -Copyright 2011-2012 Timothy Pearson +Copyright 2011-2013 Timothy Pearson This file is part of tsak, the TDE Secure Attention Key daemon @@ -132,7 +132,7 @@ void tsak_friendly_termination() { // Wait for process termination sleep(1); - fprintf(stderr, "tsak terminated by external request\n"); + fprintf(stderr, "[tsak] tsak terminated by external request\n"); exit(17); } @@ -359,7 +359,7 @@ void broadcast_sak() int i; for (i=0;i<255;i++) { if (write(mPipe_fd_out, "SAK\n\r", 6) < 0) { - fprintf(stderr, "Unable to send SAK signal to clients\n"); + fprintf(stderr, "[tsak] Unable to send SAK signal to clients\n"); } } } @@ -368,7 +368,7 @@ void restart_tsak() { int i; - fprintf(stderr, "Forcibly terminating...\n"); + fprintf(stderr, "[tsak] Forcibly terminating...\n"); // Close down all child processes for (i=0; i= size) { if (revev.type == EV_LED) { if (write(keyboard_fds[current_keyboard], &revev, sizeof(revev)) < 0) { - fprintf(stderr, "Unable to replicate LED event\n"); + fprintf(stderr, "[tsak] Unable to replicate LED event\n"); } } } @@ -624,7 +624,7 @@ int main (int argc, char *argv[]) while (1) { if ((rd = read(keyboard_fds[current_keyboard], ev, size)) < size) { - fprintf(stderr, "Read failed.\n"); + fprintf(stderr, "[tsak] Read failed.\n"); break; } @@ -654,7 +654,7 @@ int main (int argc, char *argv[]) // Pass the event on... event = ev[0]; if (write(devout[current_keyboard], &event, sizeof event) < 0) { - fprintf(stderr, "Unable to replicate keyboard event!\n"); + fprintf(stderr, "[tsak] Unable to replicate keyboard event!\n"); } } if (hide_event == true) { @@ -683,7 +683,7 @@ int main (int argc, char *argv[]) // Wait a little bit so that udev hotplug can stabilize before we start monitoring sleep(1); - fprintf(stderr, "Hotplug monitoring process started\n"); + fprintf(stderr, "[tsak] Hotplug monitoring process started\n"); // Monitor for hotplugged keyboards int j; @@ -696,7 +696,7 @@ int main (int argc, char *argv[]) // Create the udev object udev = udev_new(); if (!udev) { - fprintf(stderr, "Cannot connect to udev interface\n"); + fprintf(stderr, "[tsak] Cannot connect to udev interface\n"); return 11; } @@ -707,6 +707,21 @@ int main (int argc, char *argv[]) while (1) { // Watch for input from the monitoring process + fd_set readfds; + FD_ZERO(&readfds); + FD_SET(udev_monitor_get_fd(mon), &readfds); + int fdcount = select(udev_monitor_get_fd(mon)+1, &readfds, NULL, NULL, NULL); + if (fdcount < 0) { + if (errno == EINTR) { + fprintf(stderr, "[tsak] Signal caught in hotplug monitoring process; ignoring\n"); + } + else { + fprintf(stderr, "[tsak] Select failed on udev file descriptor in hotplug monitoring process\n"); + } + usleep(1000); + continue; + } + dev = udev_monitor_receive_device(mon); if (dev) { // If a keyboard was removed we need to restart... @@ -741,20 +756,20 @@ int main (int argc, char *argv[]) // If a keyboard was added we need to restart... if (is_new_keyboard == true) { - fprintf(stderr, "Hotplugged new keyboard: (%s)\n", name); + fprintf(stderr, "[tsak] Hotplugged new keyboard: (%s)\n", name); udev_unref(udev); restart_tsak(); } } else { - fprintf(stderr, "No Device from receive_device(). A udev error has occurred; terminating hotplug monitoring process.\n"); - return 11; + fprintf(stderr, "[tsak] No device from receive_device(). A udev error has occurred; terminating hotplug monitoring process.\n"); + return 12; } } udev_unref(udev); - fprintf(stderr, "Hotplug monitoring process terminated\n"); + fprintf(stderr, "[tsak] Hotplug monitoring process terminated\n"); } } } -- cgit v1.2.1