From 5118af588a78da1b40de35d3e1cf2b8e860b4d2a Mon Sep 17 00:00:00 2001
From: tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>
Date: Sun, 18 Sep 2011 01:23:55 +0000
Subject: Fix kdmctl spamming by kdmsak Fix KDM SAK passing to non-active VTs

git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1254120 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
---
 kdmlib/kdmtsak.cpp | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/kdmlib/kdmtsak.cpp b/kdmlib/kdmtsak.cpp
index c1ef5d12f..10b8c1acf 100644
--- a/kdmlib/kdmtsak.cpp
+++ b/kdmlib/kdmtsak.cpp
@@ -71,6 +71,18 @@ bool is_vt_active() {
 			}
 		}
 		else {
+			// See if the current session is local
+			// If it is, then the VT is not currently active and the SAK must be requested later when it is active
+			for ( TQStringList::Iterator it = sessionList.begin(); it != sessionList.end(); ++it ) {
+				TQStringList sessionInfoList = TQStringList::split(',', *it, true);
+				if ((*(sessionInfoList.at(0))).startsWith(":")) {
+					if (TQString(currentDisplay).startsWith(*(sessionInfoList.at(0)))) {
+						return false;
+					}
+				}
+			}
+			// Hmm, not local
+			// Do not reject the SAK
 			return true;
 		}
 	}
@@ -92,6 +104,7 @@ int main (int argc, char *argv[])
 			while (numread > 0) {
 				numread = read(mPipe_fd, readbuf, 6);
 			}
+			close(mPipe_fd);
 			// Now wait for SAK press
 			mPipe_fd = open(FIFO_FILE, O_RDWR);
 			while (mPipe_fd > -1) {
@@ -99,12 +112,19 @@ int main (int argc, char *argv[])
 				readbuf[numread] = 0;
 				readbuf[127] = 0;
 				if (strcmp(readbuf, "SAK\n\r") == 0) {
+					close(mPipe_fd);
 					if (is_vt_active()) {
-						close(mPipe_fd);
 						return 0;
 					}
 					else {
 						usleep(100);
+						// Flush the buffer
+						mPipe_fd = open(FIFO_FILE, O_RDWR | O_NONBLOCK);
+						numread = 1;
+						while (numread > 0) {
+							numread = read(mPipe_fd, readbuf, 6);
+						}
+						mPipe_fd = open(FIFO_FILE, O_RDWR);
 					}
 				}
 				else {
-- 
cgit v1.2.3

