From 81d495430ddcab805997c3945c195d2844bc1eaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sl=C3=A1vek=20Banko?= Date: Fri, 5 Nov 2021 16:41:06 +0100 Subject: dcopclient: Use default path for XDG_RUNTIME_DIR if the variable is not set. This resolves issue TDE/tdebase#241. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Slávek Banko --- dcop/client/dcop.cpp | 107 +++++++++++++++++++++++++++------------------------ 1 file changed, 57 insertions(+), 50 deletions(-) diff --git a/dcop/client/dcop.cpp b/dcop/client/dcop.cpp index 53acbd1c7..a07f6a41a 100644 --- a/dcop/client/dcop.cpp +++ b/dcop/client/dcop.cpp @@ -590,69 +590,76 @@ int runDCOP( QCStringList args, UserList users, Session session, } } - if( users.count() > 1 || ( users.count() == 1 && - ( getenv( "ICEAUTHORITY" ) == 0 || getenv( "DISPLAY" ) == 0 ) ) ) + if ((users.count() > 1) || ((users.count() == 1) && + ((getenv("ICEAUTHORITY") == 0) || (getenv("DISPLAY") == 0)))) { - // Check for ICE authority file and if the file can be read by us - TQString iceFileBase = "ICEauthority"; - TQString iceFile; - TQFileInfo fi; + // Check for ICE authority file and if the file can be read by us + TQString iceFileBase = "ICEauthority"; + TQString iceFile; + TQFileInfo fi; - if (getenv("XDG_RUNTIME_DIR") != 0 ) - { - TQFileInfo xdgRuntime(getenv("XDG_RUNTIME_DIR")); - passwd* pstruct = getpwnam(it.key().local8Bit()); - if (pstruct) + TQString xdgRuntimeDir = TQString::fromLocal8Bit(getenv("XDG_RUNTIME_DIR")); + if (xdgRuntimeDir.isEmpty()) { - iceFile = TQString("%1/%2/%3").arg(xdgRuntime.dirPath()).arg(pstruct->pw_uid).arg(iceFileBase); - fi.setFile(iceFile); + xdgRuntimeDir = "/run/user/"; } - if (!pstruct || !fi.exists()) + if (!xdgRuntimeDir.isEmpty()) { - iceFile = TQString::null; + TQFileInfo xdgRuntime(xdgRuntimeDir); + passwd* pstruct = getpwnam(it.key().local8Bit()); + if (pstruct) + { + iceFile = TQString("%1/%2/%3").arg(xdgRuntime.dirPath()).arg(pstruct->pw_uid).arg(iceFileBase); + fi.setFile(iceFile); + } + if (!pstruct || !fi.exists()) + { + iceFile = TQString::null; + } } - } - if (iceFile.isEmpty()) - { - iceFile = TQString("%1/.%2").arg(it.data()).arg(iceFileBase); - fi.setFile(iceFile); - } - if( iceFile.isEmpty() ) - { - cerr_ << "WARNING: Cannot determine home directory for user " - << it.key() << "!" << endl - << "Please check permissions or set the $ICEAUTHORITY variable manually before" << endl - << "calling dcop." << endl; - } - else if( fi.exists() ) - { - if( fi.isReadable() ) + if (iceFile.isEmpty()) { - char *envStr = strdup( ( "ICEAUTHORITY=" + iceFile ).ascii() ); - putenv( envStr ); - //cerr_ << "ice: " << envStr << endl; + iceFile = TQString("%1/.%2").arg(it.data()).arg(iceFileBase); + fi.setFile(iceFile); } - else + if (iceFile.isEmpty()) { - cerr_ << "WARNING: ICE authority file " << iceFile - << "is not readable by you!" << endl - << "Please check permissions or set the $ICEAUTHORITY variable manually before" << endl - << "calling dcop." << endl; + cerr_ << "WARNING: Cannot determine home directory for user " + << it.key() << "!" << endl + << "Please check permissions or set the $ICEAUTHORITY variable manually before" << endl + << "calling dcop." << endl; + } + else if (fi.exists()) + { + if (fi.isReadable()) + { + char *envStr = strdup(("ICEAUTHORITY=" + iceFile).local8Bit()); + putenv(envStr); + //cerr_ << "ice: " << envStr << endl; + } + else + { + cerr_ << "WARNING: ICE authority file " << iceFile + << "is not readable by you!" << endl + << "Please check permissions or set the $ICEAUTHORITY variable manually before" << endl + << "calling dcop." << endl; + } } - } - else - { - if( users.count() > 1 ) - continue; else { - cerr_ << "WARNING: Cannot find ICE authority file " - << iceFile << "!" << endl - << "Please check permissions or set the $ICEAUTHORITY" - << " variable manually before" << endl - << "calling dcop." << endl; + if (users.count() > 1) + { + continue; + } + else + { + cerr_ << "WARNING: Cannot find ICE authority file " + << iceFile << "!" << endl + << "Please check permissions or set the $ICEAUTHORITY" + << " variable manually before" << endl + << "calling dcop." << endl; + } } - } } // Main loop -- cgit v1.2.1