dcopclient: Use default path for XDG_RUNTIME_DIR if the variable is not set.

This resolves issue TDE/tdebase#241.

Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
(cherry picked from commit 81d495430d)
v3.5.13-sru
Slávek Banko 3 years ago
parent 9b41b5ff4b
commit a18e805939
No known key found for this signature in database
GPG Key ID: 608F5293A04BE668

@ -590,69 +590,76 @@ int runDCOP( QCStringList args, UserList users, Session session,
} }
} }
if( users.count() > 1 || ( users.count() == 1 && if ((users.count() > 1) || ((users.count() == 1) &&
( getenv( "ICEAUTHORITY" ) == 0 || getenv( "DISPLAY" ) == 0 ) ) ) ((getenv("ICEAUTHORITY") == 0) || (getenv("DISPLAY") == 0))))
{ {
// Check for ICE authority file and if the file can be read by us // Check for ICE authority file and if the file can be read by us
TQString iceFileBase = "ICEauthority"; TQString iceFileBase = "ICEauthority";
TQString iceFile; TQString iceFile;
TQFileInfo fi; TQFileInfo fi;
if (getenv("XDG_RUNTIME_DIR") != 0 ) TQString xdgRuntimeDir = TQString::fromLocal8Bit(getenv("XDG_RUNTIME_DIR"));
{ if (xdgRuntimeDir.isEmpty())
TQFileInfo xdgRuntime(getenv("XDG_RUNTIME_DIR"));
passwd* pstruct = getpwnam(it.key().local8Bit());
if (pstruct)
{ {
iceFile = TQString("%1/%2/%3").arg(xdgRuntime.dirPath()).arg(pstruct->pw_uid).arg(iceFileBase); xdgRuntimeDir = "/run/user/<uid>";
fi.setFile(iceFile);
} }
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())
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() )
{ {
char *envStr = strdup( ( "ICEAUTHORITY=" + iceFile ).ascii() ); iceFile = TQString("%1/.%2").arg(it.data()).arg(iceFileBase);
putenv( envStr ); fi.setFile(iceFile);
//cerr_ << "ice: " << envStr << endl;
} }
else if (iceFile.isEmpty())
{ {
cerr_ << "WARNING: ICE authority file " << iceFile cerr_ << "WARNING: Cannot determine home directory for user "
<< "is not readable by you!" << endl << it.key() << "!" << endl
<< "Please check permissions or set the $ICEAUTHORITY variable manually before" << endl << "Please check permissions or set the $ICEAUTHORITY variable manually before" << endl
<< "calling dcop." << 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 else
{ {
cerr_ << "WARNING: Cannot find ICE authority file " if (users.count() > 1)
<< iceFile << "!" << endl {
<< "Please check permissions or set the $ICEAUTHORITY" continue;
<< " variable manually before" << endl }
<< "calling dcop." << endl; 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 // Main loop

Loading…
Cancel
Save