From 7ee67da613daf90a09f1e4ab39a2f15229867f85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Sat, 20 Feb 2016 15:17:17 +0100 Subject: [PATCH] close #257 --- libguh/guhsettings.cpp | 16 ++++++++++++++++ libguh/guhsettings.h | 1 + server/main.cpp | 6 ++++++ 3 files changed, 23 insertions(+) diff --git a/libguh/guhsettings.cpp b/libguh/guhsettings.cpp index 9de54b82..3615f12d 100644 --- a/libguh/guhsettings.cpp +++ b/libguh/guhsettings.cpp @@ -169,6 +169,22 @@ QString GuhSettings::logPath() return logPath; } +QString GuhSettings::settingsPath() +{ + QString path; + QString organisationName = QCoreApplication::instance()->organizationName(); + + if (organisationName == "guh-test") { + path = "/tmp/" + organisationName; + } else if (GuhSettings::isRoot()) { + path = "/etc/guh/"; + } else { + path = QDir::homePath() + "/.config/" + organisationName; + } + + return path; +} + /*! Returns the path where the log file (console log) will be stored. */ QString GuhSettings::consoleLogPath() { diff --git a/libguh/guhsettings.h b/libguh/guhsettings.h index 63b3bf99..5c960114 100644 --- a/libguh/guhsettings.h +++ b/libguh/guhsettings.h @@ -47,6 +47,7 @@ public: static bool isRoot(); static QString logPath(); + static QString settingsPath(); static QString consoleLogPath(); // forwarded QSettings methods diff --git a/server/main.cpp b/server/main.cpp index fce576ac..45870c28 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -186,6 +186,12 @@ int main(int argc, char *argv[]) // inform about userid int userId = getuid(); if (userId != 0) { + // check if config directory for logfile exists + if (!QDir().mkpath(GuhSettings::settingsPath())) { + fprintf(stdout, "Could not create guh settings directory %s", qPrintable(GuhSettings::settingsPath())); + exit(EXIT_FAILURE); + } + qCDebug(dcApplication) << "====================================="; qCDebug(dcApplication) << "guhd" << GUH_VERSION_STRING << "started with user ID" << userId; qCDebug(dcApplication) << "=====================================";