diff options
author | Anna (navi) Figueiredo Gomes <navi@vlhl.dev> | 2024-07-20 01:21:55 +0200 |
---|---|---|
committer | Anna (navi) Figueiredo Gomes <navi@vlhl.dev> | 2024-07-20 03:15:17 +0200 |
commit | 5caae0d24db8c739d3b659ec1b6a0e9e6641a571 (patch) | |
tree | ec28f9e3bf0f2f92743638070fee1b758502cffb /src | |
parent | a8dd10c0c49ca6c04fb5e298dd35a91145fac743 (diff) |
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 <navi@vlhl.dev>
Diffstat (limited to 'src')
-rw-r--r-- | src/openrc/rc-logger.c | 24 |
1 files 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 */ |