summaryrefslogtreecommitdiffstats
path: root/tdm/kfrontend/sakdlg.cc
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2013-04-06 16:57:38 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2013-04-06 16:57:38 -0500
commitaa0b92c035cc0b060af4bfa9e512792884ac2dc1 (patch)
tree96e80cd34541655b82c0a616506334c5b2fab51c /tdm/kfrontend/sakdlg.cc
parent091b1eface0a6172927a481c8d7e4030f3d2d0b9 (diff)
downloadtdebase-aa0b92c035cc0b060af4bfa9e512792884ac2dc1.tar.gz
tdebase-aa0b92c035cc0b060af4bfa9e512792884ac2dc1.zip
Use threading and select instead of busywaiting on TDM control socket
This partially resolves Bug 690 Clean up TDM logfile
Diffstat (limited to 'tdm/kfrontend/sakdlg.cc')
-rw-r--r--tdm/kfrontend/sakdlg.cc97
1 files changed, 17 insertions, 80 deletions
diff --git a/tdm/kfrontend/sakdlg.cc b/tdm/kfrontend/sakdlg.cc
index b68418e15..4818c1cdd 100644
--- a/tdm/kfrontend/sakdlg.cc
+++ b/tdm/kfrontend/sakdlg.cc
@@ -87,7 +87,7 @@ extern bool trinity_desktop_lock_use_sak;
//
SAKDlg::SAKDlg(TQWidget *parent)
: TQDialog(parent, "information dialog", true, (trinity_desktop_lock_use_system_modal_dialogs?((WFlags)WStyle_StaysOnTop):((WFlags)WX11BypassWM))),
- mUnlockingFailed(false), mPipe_fd(-1), closingDown(false)
+ mUnlockingFailed(false), closingDown(false)
{
if (trinity_desktop_lock_use_system_modal_dialogs) {
// Signal that we do not want any window controls to be shown at all
@@ -130,7 +130,13 @@ SAKDlg::SAKDlg(TQWidget *parent)
connect(mSAKProcess, TQT_SIGNAL(processExited(TDEProcess*)), this, TQT_SLOT(slotSAKProcessExited()));
mSAKProcess->start();
- TQTimer::singleShot( 0, this, TQT_SLOT(handleInputPipe()) );
+ mControlPipeHandlerThread = new TQEventLoopThread();
+ mControlPipeHandler = new ControlPipeHandlerObject();
+ mControlPipeHandler->mSAKDlgParent = this;
+ mControlPipeHandler->moveToThread(mControlPipeHandlerThread);
+ TQObject::connect(mControlPipeHandler, SIGNAL(processCommand(TQString)), this, SLOT(processInputPipeCommand(TQString)));
+ TQTimer::singleShot(0, mControlPipeHandler, SLOT(run()));
+ mControlPipeHandlerThread->start();
}
void SAKDlg::slotSAKProcessExited()
@@ -141,82 +147,12 @@ void SAKDlg::slotSAKProcessExited()
hide();
}
-void SAKDlg::handleInputPipe(void) {
- if (closingDown) {
- ::unlink(mPipeFilename.ascii());
- return;
- }
-
- if (isShown() == false) {
- TQTimer::singleShot( 100, this, TQT_SLOT(handleInputPipe()) );
- return;
- }
-
- char readbuf[2048];
- int displayNumber;
- TQString currentDisplay;
- currentDisplay = TQString(getenv("DISPLAY"));
- currentDisplay = currentDisplay.replace(":", "");
- displayNumber = currentDisplay.toInt();
- mPipeFilename = TQString(FIFO_SAK_FILE).arg(displayNumber);
- ::unlink((TQString(FIFO_FILE).arg(displayNumber)).ascii());
-
- /* Create the FIFOs if they do not exist */
- umask(0);
- struct stat buffer;
- int status;
- char *fifo_parent_dir = strdup(FIFO_DIR);
- dirname(fifo_parent_dir);
- status = stat(fifo_parent_dir, &buffer);
- if (status != 0) {
- mkdir(fifo_parent_dir, 0644);
- }
- free(fifo_parent_dir);
- status = stat(FIFO_DIR, &buffer);
- if (status == 0) {
- int file_mode = ((buffer.st_mode & S_IRWXU) >> 6) * 100;
- file_mode = file_mode + ((buffer.st_mode & S_IRWXG) >> 3) * 10;
- file_mode = file_mode + ((buffer.st_mode & S_IRWXO) >> 0) * 1;
- if ((file_mode != 600) || (buffer.st_uid != 0) || (buffer.st_gid != 0)) {
- ::unlink(mPipeFilename.ascii());
- printf("[WARNING] Possible security breach! Please check permissions on " FIFO_DIR " (must be 600 and owned by root/root, got %d %d/%d). Not listening for login credentials on remote control socket.\n", file_mode, buffer.st_uid, buffer.st_gid); fflush(stdout);
- return;
- }
- }
- mkdir(FIFO_DIR,0600);
- mknod(mPipeFilename.ascii(), S_IFIFO|0600, 0);
- chmod(mPipeFilename.ascii(), 0600);
-
- mPipe_fd = ::open(mPipeFilename.ascii(), O_RDONLY | O_NONBLOCK);
- int numread;
- TQString inputcommand = "";
- while ((!inputcommand.contains('\n')) && (!closingDown)) {
- numread = ::read(mPipe_fd, readbuf, 2048);
- readbuf[numread] = 0;
- readbuf[2047] = 0;
- inputcommand += readbuf;
- if (!tqApp->hasPendingEvents()) {
- usleep(500);
- }
- tqApp->processEvents();
- }
- if (closingDown) {
- ::unlink(mPipeFilename.ascii());
- return;
- }
- inputcommand = inputcommand.replace('\n', "");
- TQStringList commandList = TQStringList::split('\t', inputcommand, false);
+void SAKDlg::processInputPipeCommand(TQString command) {
+ command = command.replace('\n', "");
+ TQStringList commandList = TQStringList::split('\t', command, false);
if ((*(commandList.at(0))) == "CLOSE") {
mSAKProcess->kill();
}
- if (!closingDown) {
- TQTimer::singleShot( 0, this, TQT_SLOT(handleInputPipe()) );
- ::close(mPipe_fd);
- ::unlink(mPipeFilename.ascii());
- }
- else {
- ::unlink(mPipeFilename.ascii());
- }
}
SAKDlg::~SAKDlg()
@@ -225,11 +161,12 @@ SAKDlg::~SAKDlg()
mSAKProcess->kill(SIGTERM);
delete mSAKProcess;
}
- if (mPipe_fd != -1) {
- closingDown = true;
- ::close(mPipe_fd);
- ::unlink(mPipeFilename.ascii());
- }
+
+ mControlPipeHandlerThread->terminate();
+ mControlPipeHandlerThread->wait();
+ delete mControlPipeHandler;
+ delete mControlPipeHandlerThread;
+
hide();
}