summaryrefslogtreecommitdiffstats
path: root/kdesktop/lock/main.cc
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2013-04-19 12:50:40 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2013-04-19 12:50:40 -0500
commit5f4287e56dd5c1feecc08843aae1d4e4b8835d1e (patch)
tree16ee641017a3a2f176b6a7291482b6146381e46d /kdesktop/lock/main.cc
parent6640770b3239ad117d29df2929e5b7442e48ee3a (diff)
downloadtdebase-5f4287e56dd5c1feecc08843aae1d4e4b8835d1e.tar.gz
tdebase-5f4287e56dd5c1feecc08843aae1d4e4b8835d1e.zip
Fix Documents folder creation dialog
This resolves Bug 976 Prevent multiple kdesktop_lock processes from spawning per user
Diffstat (limited to 'kdesktop/lock/main.cc')
-rw-r--r--kdesktop/lock/main.cc41
1 files changed, 41 insertions, 0 deletions
diff --git a/kdesktop/lock/main.cc b/kdesktop/lock/main.cc
index 0659217a0..792764da1 100644
--- a/kdesktop/lock/main.cc
+++ b/kdesktop/lock/main.cc
@@ -25,6 +25,8 @@
#include "main.h"
#include "kdesktopsettings.h"
+#include <tqfileinfo.h>
+
#include <tdecmdlineargs.h>
#include <tdelocale.h>
#include <tdeglobal.h>
@@ -32,6 +34,7 @@
#include <tdeglobalsettings.h>
#include <dcopref.h>
#include <ksimpleconfig.h>
+#include <kstandarddirs.h>
#include <tdmtsak.h>
@@ -314,6 +317,44 @@ int main( int argc, char **argv )
MyApp app;
#endif
+ TDELockFile lock(locateLocal("tmp", "kdesktop_lock_lockfile"));
+ lock.setStaleTime(0);
+ TDELockFile::LockResult lockRet = lock.lock();
+ if (lockRet != TDELockFile::LockOK) {
+ // Terminate existing (stale) process if needed
+ int pid;
+ TQString hostName;
+ TQString appName;
+ if (lock.getLockInfo(pid, hostName, appName)) {
+ // Verify that the pid in question is an instance of kdesktop_lock
+ int len;
+ char procpath[PATH_MAX];
+ char fullpath[PATH_MAX];
+ snprintf(procpath, sizeof(procpath), "/proc/%d/exe", pid);
+ len = readlink( procpath, fullpath, sizeof(fullpath) );
+ if (len >= 0) {
+ fullpath[len] = 0;
+ TQFileInfo fileInfo(fullpath);
+ if (fileInfo.baseName() == "kdesktop_lock") {
+ // Verify that pid in question is owned by current user before killing it
+ uid_t current_uid = geteuid();
+
+ struct stat info;
+ if (lstat(procpath, &info) == 0) {
+ if (info.st_uid == current_uid) {
+ kill(pid, SIGKILL);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // Force a relock as a stale lockfile or process may have been dealt with above
+ if (!lock.isLocked()) {
+ lockRet = lock.lock(TDELockFile::LockNoBlock | TDELockFile::LockForce);
+ }
+
kdDebug() << "app " << kdesktop_screen_number << " " << starting_screen << " " << child << " " << child_sockets.count() << " " << parent_connection << endl;
app.disableSessionManagement();
TDEGlobal::locale()->insertCatalogue("libdmctl");