From 83e1400e0ce762a9932041977e3c9b90f049425b Mon Sep 17 00:00:00 2001 From: aszlig Date: Sun, 23 Apr 2017 19:02:50 +0200 Subject: [PATCH] nixos/slim: Implement logging to journal The main change here is a patch of SLiM to tread a log file of /dev/stderr specially in that it now uses std::cerr instead of a file for logging. This allows us to set the logfile to stderr in NixOS for the generated SLiM configuration file and we now get logging to the systemd journal. Signed-off-by: aszlig --- .../services/x11/display-managers/slim.nix | 7 +- .../display-managers/slim/default.nix | 4 + .../display-managers/slim/no-logfile.patch | 80 +++++++++++++++++++ 3 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 pkgs/applications/display-managers/slim/no-logfile.patch diff --git a/nixos/modules/services/x11/display-managers/slim.nix b/nixos/modules/services/x11/display-managers/slim.nix index 05b979eef47f..0c4dd1973b53 100644 --- a/nixos/modules/services/x11/display-managers/slim.nix +++ b/nixos/modules/services/x11/display-managers/slim.nix @@ -17,6 +17,7 @@ let login_cmd exec ${pkgs.stdenv.shell} ${dmcfg.session.script} "%session" halt_cmd ${config.systemd.package}/sbin/shutdown -h now reboot_cmd ${config.systemd.package}/sbin/shutdown -r now + logfile /dev/stderr ${optionalString (cfg.defaultUser != null) ("default_user " + cfg.defaultUser)} ${optionalString (cfg.defaultUser != null) ("focus_password yes")} ${optionalString cfg.autoLogin "auto_login yes"} @@ -128,11 +129,7 @@ in config = mkIf cfg.enable { services.xserver.displayManager.job = - { preStart = - '' - rm -f /var/log/slim.log - ''; - environment = + { environment = { SLIM_CFGFILE = slimConfig; SLIM_THEMESDIR = slimThemesDir; }; diff --git a/pkgs/applications/display-managers/slim/default.nix b/pkgs/applications/display-managers/slim/default.nix index fca84199e511..c75a8976b3fa 100644 --- a/pkgs/applications/display-managers/slim/default.nix +++ b/pkgs/applications/display-managers/slim/default.nix @@ -22,6 +22,10 @@ stdenv.mkDerivation rec { # Ensure that sessions appear in sort order, rather than in # directory order. ./sort-sessions.patch + + # Allow to set logfile to a special "/dev/stderr" in order to continue + # logging to stderr and thus to the journal. + ./no-logfile.patch ]; preConfigure = "substituteInPlace CMakeLists.txt --replace /lib $out/lib"; diff --git a/pkgs/applications/display-managers/slim/no-logfile.patch b/pkgs/applications/display-managers/slim/no-logfile.patch new file mode 100644 index 000000000000..f2f5f1549930 --- /dev/null +++ b/pkgs/applications/display-managers/slim/no-logfile.patch @@ -0,0 +1,80 @@ +diff --git a/log.cpp b/log.cpp +index b44677a..7c89dda 100644 +--- a/log.cpp ++++ b/log.cpp +@@ -1,23 +1,31 @@ + #include "log.h" + #include ++#include + + bool + LogUnit::openLog(const char * filename) + { +- if (logFile.is_open()) { ++ if (isFile && logFile.is_open()) { + cerr << APPNAME + << ": opening a new Log file, while another is already open" + << endl; +- logFile.close(); ++ closeLog(); + } +- logFile.open(filename, ios_base::app); + +- return !(logFile.fail()); ++ if (strcmp(filename, "/dev/stderr") == 0) { ++ isFile = false; ++ return true; ++ } else { ++ logFile.open(filename, ios_base::app); ++ isFile = true; ++ return !(logFile.fail()); ++ } + } + + void + LogUnit::closeLog() + { ++ if (!isFile) return; + if (logFile.is_open()) + logFile.close(); + } +diff --git a/log.h b/log.h +index b7810be..ad548a2 100644 +--- a/log.h ++++ b/log.h +@@ -9,11 +9,14 @@ + #endif + #include "const.h" + #include ++#include + + using namespace std; + + static class LogUnit { + ofstream logFile; ++ bool isFile; ++ inline ostream &getStream() { return isFile ? logFile : cerr; } + public: + bool openLog(const char * filename); + void closeLog(); +@@ -22,17 +25,17 @@ public: + + template + LogUnit & operator<<(const Type & text) { +- logFile << text; logFile.flush(); ++ getStream() << text; getStream().flush(); + return *this; + } + + LogUnit & operator<<(ostream & (*fp)(ostream&)) { +- logFile << fp; logFile.flush(); ++ getStream() << fp; getStream().flush(); + return *this; + } + + LogUnit & operator<<(ios_base & (*fp)(ios_base&)) { +- logFile << fp; logFile.flush(); ++ getStream() << fp; getStream().flush(); + return *this; + } + } logStream;