summaryrefslogtreecommitdiffstats
path: root/tdmlib/tdmtsak.cpp
diff options
context:
space:
mode:
authorTimothy Pearson <[email protected]>2013-06-11 12:30:35 -0500
committerTimothy Pearson <[email protected]>2013-06-11 12:30:35 -0500
commit864059732e6d5147c1d241c40667e1e2f4a16465 (patch)
tree9773e84f302bf722914eac84a222efb134c81792 /tdmlib/tdmtsak.cpp
parent789ab7d1f5b48a8f0f545678526fc22e13107600 (diff)
downloadtdebase-864059732e6d5147c1d241c40667e1e2f4a16465.tar.gz
tdebase-864059732e6d5147c1d241c40667e1e2f4a16465.zip
Fix tdmtsak behaviour when tsak is restarted due to hardware changes
Diffstat (limited to 'tdmlib/tdmtsak.cpp')
-rw-r--r--tdmlib/tdmtsak.cpp49
1 files changed, 32 insertions, 17 deletions
diff --git a/tdmlib/tdmtsak.cpp b/tdmlib/tdmtsak.cpp
index b3ff08cc1..c893f86ec 100644
--- a/tdmlib/tdmtsak.cpp
+++ b/tdmlib/tdmtsak.cpp
@@ -140,25 +140,38 @@ int main (int argc, char *argv[])
}
if (verifier_result == 0) {
- // OK, the calling process is authorized to retrieve SAK data
- // First, flush the buffer
- mPipe_fd = open(FIFO_FILE, O_RDONLY | O_NONBLOCK);
- if (checkonly) {
- if (mPipe_fd < 0) {
- return 6; // SAK not available
- }
- else {
- return 0;
- }
+ // OK, the calling process is authorized to retrieve SAK data
+ // First, flush the buffer
+ mPipe_fd = open(FIFO_FILE, O_RDONLY | O_NONBLOCK);
+ if (checkonly) {
+ if (mPipe_fd < 0) {
+ return 6; // SAK not available
}
- numread = 1;
- while (numread > 0) {
- numread = read(mPipe_fd, readbuf, 6);
+ else {
+ return 0;
}
- close(mPipe_fd);
- // Now wait for SAK press
+ }
+ numread = 1;
+ while (numread > 0) {
+ numread = read(mPipe_fd, readbuf, 6);
+ }
+ close(mPipe_fd);
+ // Now wait for SAK press
+ while (mPipe_fd > -1) {
mPipe_fd = open(FIFO_FILE, O_RDONLY);
- while (mPipe_fd > -1) {
+
+ if (mPipe_fd <= -1) {
+ // This may be a transient glitch, such as when a KVM is being toggled or a new keyboard has been added
+ // Wait up to 5 seconds while trying to open the pipe again
+ int timeout = 5;
+ while ((mPipe_fd <= -1) && (timeout > 0)) {
+ sleep(1);
+ mPipe_fd = open(FIFO_FILE, O_RDONLY);
+ timeout--;
+ }
+ }
+
+ if (mPipe_fd > -1) {
numread = read(mPipe_fd, readbuf, 6);
readbuf[numread] = 0;
readbuf[127] = 0;
@@ -183,8 +196,10 @@ int main (int argc, char *argv[])
usleep(100);
}
}
+
close(mPipe_fd);
- return 6;
+ }
+ return 6;
}
else {
return verifier_result;