diff mbox series

[bug#43921,Shepherd,1/2] Use XDG_CACHE_HOME/shepherd for unprivileged users' log directory.

Message ID 20201011094358.14013-1-janneke@gnu.org
State New
Headers show
Series Add User Service example. | expand

Checks

Context Check Description
cbaines/applying patch fail View Laminar job
cbaines/applying patch fail View Laminar job

Commit Message

Jan Nieuwenhuizen Oct. 11, 2020, 9:43 a.m. UTC
* modules/shepherd/support.scm (%user-cache-dir): New variable.
(user-default-log-file): Use it.
* doc/shepherd.texi (Invoking shepherd): Document it.
---
 doc/shepherd.texi            |  4 +++-
 modules/shepherd/support.scm | 11 +++++++++--
 2 files changed, 12 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/doc/shepherd.texi b/doc/shepherd.texi
index 696477e..7c9a739 100644
--- a/doc/shepherd.texi
+++ b/doc/shepherd.texi
@@ -417,7 +417,9 @@  permissions are not as expected.
 Log output into @var{file}.
 
 For unprivileged users, the default log file is
-@file{$XDG_CONFIG_HOME/shepherd/shepherd.log}.
+@file{$XDG_CACHE_HOME/shepherd/shepherd.log}.  If the
+@code{XDG_CACHE_HOME} environment variable is not defined,
+@code{$HOME/.cache/shepherd/shepherd.log} is used instead.
 
 @cindex syslog
 When running as root, the default behavior is to connect to
diff --git a/modules/shepherd/support.scm b/modules/shepherd/support.scm
index cdb7b35..fe64a05 100644
--- a/modules/shepherd/support.scm
+++ b/modules/shepherd/support.scm
@@ -4,6 +4,7 @@ 
 ;; Copyright (C) 2002, 2003 Wolfgang Jährling <wolfgang@pro-linux.de>
 ;; Copyright (C) 2016 Mathieu Lirzin <mthl@gnu.org>
 ;; Copyright (C) 2018 Danny Milosavljevic <dannym@scratchpost.org>
+;; Copyright (C) 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
 ;;
 ;; This file is part of the GNU Shepherd.
 ;;
@@ -265,6 +266,12 @@  There is NO WARRANTY, to the extent permitted by law.")))
       (false-if-exception (passwd:dir (getpwuid (getuid))))
       "/"))
 
+(define %user-cache-dir
+  ;; Default cache directory if shepherd is run as a normal user.
+  (string-append (or (getenv "XDG_CACHE_HOME")
+                     (string-append user-homedir "/.cache"))
+                 "/shepherd"))
+
 (define %user-config-dir
   ;; Default config directory if shepherd is run as a normal user.
   (string-append (or (getenv "XDG_CONFIG_HOME")
@@ -302,8 +309,8 @@  TARGET should be a string representing a filepath + name."
 ;; Logging.
 (define (user-default-log-file)
   "Return the file name of the user's default log file."
-  (mkdir-p %user-config-dir #o700)
-  (string-append %user-config-dir "/shepherd.log"))
+  (mkdir-p %user-cache-dir #o700)
+  (string-append %user-cache-dir "/shepherd.log"))
 
 (define default-logfile-date-format
   ;; 'strftime' format string to prefix each entry in the log.