summaryrefslogtreecommitdiffstats
path: root/kdmlib
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-09-17 23:27:00 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-09-17 23:27:00 +0000
commite723b237f11e18822f7971f1b5d8884b666455eb (patch)
treed1b26ff60a10aa84244fa2526a8778b11d54410f /kdmlib
parentc8ff4ef743f03d015db000d6f44b4249575c390f (diff)
downloadtdebase-e723b237f11e18822f7971f1b5d8884b666455eb.tar.gz
tdebase-e723b237f11e18822f7971f1b5d8884b666455eb.zip
Make the SAK only work on the current VT
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1254116 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kdmlib')
-rw-r--r--kdmlib/kdmtsak.cpp67
1 files changed, 63 insertions, 4 deletions
diff --git a/kdmlib/kdmtsak.cpp b/kdmlib/kdmtsak.cpp
index 967e54855..c1ef5d12f 100644
--- a/kdmlib/kdmtsak.cpp
+++ b/kdmlib/kdmtsak.cpp
@@ -20,8 +20,62 @@
#include "kdmtsak.h"
+#include <tqstringlist.h>
+
#define FIFO_FILE "/tmp/ksocket-global/tsak"
+TQString exec(char* cmd) {
+ FILE* pipe = popen(cmd, "r");
+ if (!pipe) return "ERROR";
+ char buffer[128];
+ TQString result = "";
+ while(!feof(pipe)) {
+ if(fgets(buffer, 128, pipe) != NULL)
+ result += buffer;
+ }
+ pclose(pipe);
+ return result;
+}
+
+bool is_vt_active() {
+ const char * currentDisplay;
+ currentDisplay = getenv ("DISPLAY");
+ if (currentDisplay == NULL) {
+ return true;
+ }
+ else {
+ TQString cvtName = "";
+ TQString output = exec("kdmctl list");
+ TQString curConsole = exec("fgconsole");
+ bool intFound;
+ int curConsoleNum = curConsole.toInt(&intFound);
+ if (intFound = false) {
+ return 1;
+ }
+ curConsole = TQString("vt%1").tqarg(curConsoleNum);;
+ TQStringList sessionList = TQStringList::split('\t', output, false);
+ for ( TQStringList::Iterator it = sessionList.begin(); it != sessionList.end(); ++it ) {
+ TQStringList sessionInfoList = TQStringList::split(',', *it, true);
+ if ((*(sessionInfoList.at(0))).startsWith(":")) {
+ if ((*(sessionInfoList.at(1))) == TQString(curConsole)) {
+ cvtName = (*(sessionInfoList.at(0)));
+ }
+ }
+ }
+ if (cvtName != "") {
+ if (TQString(currentDisplay).startsWith(cvtName)) {
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+ else {
+ return true;
+ }
+ }
+}
+
int main (int argc, char *argv[])
{
int mPipe_fd;
@@ -33,20 +87,25 @@ 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);
+ mPipe_fd = open(FIFO_FILE, O_RDWR | O_NONBLOCK);
numread = 1;
while (numread > 0) {
numread = read(mPipe_fd, readbuf, 6);
}
// Now wait for SAK press
- mPipe_fd = open(FIFO_FILE, O_RDONLY);
+ mPipe_fd = open(FIFO_FILE, O_RDWR);
while (mPipe_fd > -1) {
numread = read(mPipe_fd, readbuf, 6);
readbuf[numread] = 0;
readbuf[127] = 0;
if (strcmp(readbuf, "SAK\n\r") == 0) {
- close(mPipe_fd);
- return 0;
+ if (is_vt_active()) {
+ close(mPipe_fd);
+ return 0;
+ }
+ else {
+ usleep(100);
+ }
}
else {
usleep(100);