From f0deaa24ad57d2db921bf1b092350988c50558a7 Mon Sep 17 00:00:00 2001 From: "Jan (janneke) Nieuwenhuizen" Date: Sun, 11 Oct 2020 10:54:26 +0200 Subject: [PATCH v3 1/2] Use XDG_CACHE_HOME/shepherd for unprivileged users' log directory. Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 * 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 --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 ;; Copyright (C) 2016 Mathieu Lirzin ;; Copyright (C) 2018 Danny Milosavljevic +;; Copyright (C) 2020 Jan (janneke) Nieuwenhuizen ;; ;; 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. -- Jan Nieuwenhuizen | GNU LilyPond http://lilypond.org Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.com