From ddc093b90e26b2f5291ee70f9d752607429cd81a Mon Sep 17 00:00:00 2001 From: David Faure Date: Fri, 21 Oct 2011 20:57:54 +0200 Subject: Add QStandardPaths::RuntimeLocation, for sockets ($XDG_RUNTIME_DIR) Change-Id: I19c36a04a9deae49ffc20fdec6a2a7eb05155cb4 Reviewed-by: Thiago Macieira (Intel) --- src/corelib/io/qstandardpaths_unix.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/corelib/io/qstandardpaths_unix.cpp') 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 #include #include +#include +#include #include #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; } -- cgit v1.2.3