summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qstandardpaths_unix.cpp
diff options
context:
space:
mode:
authorDavid Faure <faure@kde.org>2011-10-21 20:57:54 +0200
committerQt by Nokia <qt-info@nokia.com>2011-10-23 00:56:56 +0200
commitddc093b90e26b2f5291ee70f9d752607429cd81a (patch)
tree0a69f3ef97cd45419b6c0d661996255259e59a30 /src/corelib/io/qstandardpaths_unix.cpp
parent4b72c3f4347bfb8493e877d26f172f2e18c69a83 (diff)
Add QStandardPaths::RuntimeLocation, for sockets ($XDG_RUNTIME_DIR)
Change-Id: I19c36a04a9deae49ffc20fdec6a2a7eb05155cb4 Reviewed-by: Thiago Macieira (Intel) <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qstandardpaths_unix.cpp')
-rw-r--r--src/corelib/io/qstandardpaths_unix.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp
index 5a52c2518f..12f872f5fa 100644
--- a/src/corelib/io/qstandardpaths_unix.cpp
+++ b/src/corelib/io/qstandardpaths_unix.cpp
@@ -46,6 +46,8 @@
#include <qfile.h>
#include <qtextstream.h>
#include <qcoreapplication.h>
+#include <private/qfilesystemengine_p.h>
+#include <errno.h>
#include <stdlib.h>
#ifndef QT_NO_STANDARDPATHS
@@ -93,6 +95,38 @@ QString QStandardPaths::storageLocation(StandardLocation type)
xdgConfigHome = QDir::homePath() + QLatin1String("/.config");
return xdgConfigHome;
}
+ case RuntimeLocation:
+ {
+ const uid_t myUid = geteuid();
+ // http://standards.freedesktop.org/basedir-spec/latest/
+ QString xdgRuntimeDir = QFile::decodeName(qgetenv("XDG_RUNTIME_DIR"));
+ if (xdgRuntimeDir.isEmpty()) {
+ const QString userName = QFileSystemEngine::resolveUserName(myUid);
+ xdgRuntimeDir = QDir::tempPath() + QLatin1String("/runtime-") + userName;
+ QDir dir(xdgRuntimeDir);
+ if (!dir.exists()) {
+ if (!QDir().mkdir(xdgRuntimeDir)) {
+ qWarning("QStandardPaths: error creating runtime directory %s: %s", qPrintable(xdgRuntimeDir), qPrintable(qt_error_string(errno)));
+ return QString();
+ }
+ }
+ }
+ // "The directory MUST be owned by the user"
+ QFileInfo fileInfo(xdgRuntimeDir);
+ if (fileInfo.ownerId() != myUid) {
+ qWarning("QStandardPaths: wrong ownership on runtime directory %s, %d instead of %d", qPrintable(xdgRuntimeDir),
+ fileInfo.ownerId(), myUid);
+ return QString();
+ }
+ // "and he MUST be the only one having read and write access to it. Its Unix access mode MUST be 0700."
+ QFile file(xdgRuntimeDir);
+ const QFile::Permissions wantedPerms = QFile::ReadUser | QFile::WriteUser | QFile::ExeUser;
+ if (file.permissions() != wantedPerms && !file.setPermissions(wantedPerms)) {
+ qWarning("QStandardPaths: wrong permissions on runtime directory %s", qPrintable(xdgRuntimeDir));
+ return QString();
+ }
+ return xdgRuntimeDir;
+ }
default:
break;
}