From a935425e5f4af229680f0e5bda0a7898020a06c4 Mon Sep 17 00:00:00 2001 From: Pier Luigi Fiorini Date: Sat, 17 Oct 2015 18:29:20 +0200 Subject: [PATCH 12/34] Configurable user session log See issue #135. [ChangeLog][Configuration] Add SessionLogFile to the XDisplay and WaylandDisplay sections in order to make user session log location configurable. --- data/man/sddm.conf.rst.in | 8 ++++++++ src/common/Configuration.h | 2 ++ src/helper/UserSession.cpp | 15 +++++++++++---- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/data/man/sddm.conf.rst.in b/data/man/sddm.conf.rst.in index d5263e0..edce9cf 100644 --- a/data/man/sddm.conf.rst.in +++ b/data/man/sddm.conf.rst.in @@ -93,6 +93,10 @@ OPTIONS Path of script to execute when starting the desktop session. Default value is "@SESSION_COMMAND@". +`SessionLogFile=` + Path to the user session log file, relative to the home directory. + Default value is ".cache/xsession-errors". + `DisplayCommand=` Path of script to execute when starting the display server. Default value is "@DATA_INSTALL_DIR@/scripts/Xsetup". @@ -117,6 +121,10 @@ OPTIONS Path of script to execute when starting the desktop session. Default value is "@WAYLAND_SESSION_COMMAND@". +`SessionLogFile=` + Path to the user session log file, relative to the home directory. + Default value is ".cache/wayland-errors". + [Users] section: `DefaultPath=` diff --git a/src/common/Configuration.h b/src/common/Configuration.h index 1997fe0..89a57db 100644 --- a/src/common/Configuration.h +++ b/src/common/Configuration.h @@ -60,6 +60,7 @@ namespace SDDM { Entry(XauthPath, QString, _S("/usr/bin/xauth"), _S("Path to xauth binary")); Entry(SessionDir, QString, _S("/usr/share/xsessions"), _S("Directory containing available X sessions")); Entry(SessionCommand, QString, _S(SESSION_COMMAND), _S("Path to a script to execute when starting the desktop session")); + Entry(SessionLogFile, QString, _S(".cache/xsession-errors"), _S("Path to the user session log file")); Entry(DisplayCommand, QString, _S(DATA_INSTALL_DIR "/scripts/Xsetup"), _S("Path to a script to execute when starting the display server")); Entry(DisplayStopCommand, QString, _S(DATA_INSTALL_DIR "/scripts/Xstop"), _S("Path to a script to execute when stopping the display server")); Entry(MinimumVT, int, MINIMUM_VT, _S("The lowest virtual terminal number that will be used.")); @@ -68,6 +69,7 @@ namespace SDDM { Section(WaylandDisplay, Entry(SessionDir, QString, _S("/usr/share/wayland-sessions"), _S("Directory containing available Wayland sessions")); Entry(SessionCommand, QString, _S(WAYLAND_SESSION_COMMAND), _S("Path to a script to execute when starting the desktop session")); + Entry(SessionLogFile, QString, _S(".cache/wayland-errors"), _S("Path to the user session log file")); ); Section(Users, diff --git a/src/helper/UserSession.cpp b/src/helper/UserSession.cpp index 0c0ab2b..bd6d1c5 100644 --- a/src/helper/UserSession.cpp +++ b/src/helper/UserSession.cpp @@ -134,17 +134,24 @@ namespace SDDM { //we want to redirect after we setuid so that the log file is owned by the user // determine stderr log file based on session type - QString fileName = sessionType == QStringLiteral("x11") - ? QStringLiteral(".xsession-errors") : QStringLiteral(".wayland-errors"); + QString sessionLog = QStringLiteral("%1/%2") + .arg(QString::fromLocal8Bit(pw->pw_dir)) + .arg(sessionType == QStringLiteral("x11") + ? mainConfig.XDisplay.SessionLogFile.get() + : mainConfig.WaylandDisplay.SessionLogFile.get()); + + // create the path + QFileInfo finfo(sessionLog); + QDir().mkpath(finfo.absolutePath()); //swap the stderr pipe of this subprcess into a file - int fd = ::open(qPrintable(fileName), O_WRONLY | O_CREAT | O_TRUNC, 0600); + int fd = ::open(qPrintable(sessionLog), O_WRONLY | O_CREAT | O_TRUNC, 0600); if (fd >= 0) { dup2 (fd, STDERR_FILENO); ::close(fd); } else { - qWarning() << "Could not open stderr to" << fileName; + qWarning() << "Could not open stderr to" << sessionLog; } //redirect any stdout to /dev/null -- 2.5.0