From 5f4287e56dd5c1feecc08843aae1d4e4b8835d1e Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Fri, 19 Apr 2013 12:50:40 -0500 Subject: Fix Documents folder creation dialog This resolves Bug 976 Prevent multiple kdesktop_lock processes from spawning per user --- kdesktop/lock/main.cc | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'kdesktop/lock/main.cc') 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 + #include #include #include @@ -32,6 +34,7 @@ #include #include #include +#include #include @@ -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"); -- cgit v1.2.1