From 5caae0d24db8c739d3b659ec1b6a0e9e6641a571 Mon Sep 17 00:00:00 2001 From: "Anna (navi) Figueiredo Gomes" Date: Sat, 20 Jul 2024 01:21:55 +0200 Subject: openrc/rc-logger.c: set log path for user dynamically since it's not possible to differentiate the option set from an user configuration file versus the system wide, for user-mode openrc, use XDG_STATE_DIR (~/.local/state) unconditionally for now. Signed-off-by: Anna (navi) Figueiredo Gomes --- src/openrc/rc-logger.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/openrc/rc-logger.c b/src/openrc/rc-logger.c index 34cf2e82..dad141ea 100644 --- a/src/openrc/rc-logger.c +++ b/src/openrc/rc-logger.c @@ -146,7 +146,7 @@ rc_logger_open(const char *level) FILE *log = NULL; FILE *plog = NULL; char *logfile_path; - const char *logfile; + char *logfile; int log_error = 0; if (!rc_conf_yesno("rc_logger")) @@ -248,12 +248,21 @@ rc_logger_open(const char *level) } /* Append the temporary log to the real log */ - logfile = rc_conf_value("rc_log_path"); - if (logfile == NULL) - logfile = DEFAULTLOG; - if (!strcmp(logfile, logfile_path)) { - eerror("Cowardly refusing to concatenate a logfile into itself."); - eerrorx("Please change rc_log_path to something other than %s to get rid of this message", logfile_path); + if (rc_is_user()) { + char *env; + if ((env = getenv("XDG_STATE_HOME"))) + xasprintf(&logfile, "%s/openrc.log", env); + else if ((env = getenv("HOME"))) + xasprintf(&logfile, "%s/openrc.log", env); + else + eerrorx("XDG_STATE_HOME and HOME unset."); + } else { + const char *config_log = rc_conf_value("rc_log_path"); + logfile = config_log ? xstrdup(config_log) : xstrdup(DEFAULTLOG); + if (!strcmp(logfile, logfile_path)) { + eerror("Cowardly refusing to concatenate a logfile into itself."); + eerrorx("Please change rc_log_path to something other than %s to get rid of this message", logfile_path); + } } if ((plog = fopen(logfile, "ae"))) { @@ -292,6 +301,7 @@ rc_logger_open(const char *level) eerrorx("Warning: temporary logfile left behind: %s", logfile_path); free(logfile_path); + free(logfile); exit(0); /* NOTREACHED */ -- cgit v1.2.3