aboutsummaryrefslogtreecommitdiff
path: root/src/librc/librc-misc.c
diff options
context:
space:
mode:
authorAnna (navi) Figueiredo Gomes <navi@vlhl.dev>2024-03-20 23:45:47 +0100
committerAnna (navi) Figueiredo Gomes <navi@vlhl.dev>2024-07-19 20:40:28 +0200
commitc34fcd63f05044f9034b26c52f19c91e04668da7 (patch)
tree8ef449218cf736057197cd39fba1dac6117216c3 /src/librc/librc-misc.c
parent917a7031d946c0b608517936fab0f54689167265 (diff)
openrc: dynamic paths for user services
add two api functions, `rc_service_dir` and `rc_sysconf_dir`, both are generate paths (and sub-paths) for resources, and meant to replace the hardcoded variables like `RC_SVCDIR`. those functions differ by dynamically switching between the system path, or the user path, set in their home folder or runtime directory. this lays out the intial support for user services. Signed-off-by: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
Diffstat (limited to 'src/librc/librc-misc.c')
-rw-r--r--src/librc/librc-misc.c56
1 files changed, 36 insertions, 20 deletions
diff --git a/src/librc/librc-misc.c b/src/librc/librc-misc.c
index ce658f5c..538a67c2 100644
--- a/src/librc/librc-misc.c
+++ b/src/librc/librc-misc.c
@@ -358,9 +358,10 @@ static RC_STRINGLIST * rc_config_directory(RC_STRINGLIST *config)
rc_config_set_value(config, line->value);
rc_stringlist_free(rc_conf_d_list);
}
- rc_stringlist_free(rc_conf_d_files);
}
}
+
+ rc_stringlist_free(rc_conf_d_files);
return config;
}
@@ -412,32 +413,47 @@ _free_rc_conf(void)
char *
rc_conf_value(const char *setting)
{
- RC_STRINGLIST *old;
+ RC_STRINGLIST *tmp;
RC_STRING *s;
char *p;
+ const char *userconf_dir;
+
+ if (rc_conf)
+ return rc_config_value(rc_conf, setting);
+
+ rc_conf = rc_config_load(RC_CONF);
+ atexit(_free_rc_conf);
+
+ /* Support old configs. */
+ if (exists(RC_CONF_OLD)) {
+ tmp = rc_config_load(RC_CONF_OLD);
+ TAILQ_CONCAT(rc_conf, tmp, entries);
+ rc_stringlist_free(tmp);
+ }
- if (!rc_conf) {
- rc_conf = rc_config_load(RC_CONF);
- atexit(_free_rc_conf);
+ /* Overlay user-specific configuration */
+ if ((userconf_dir = rc_userconf_dir())) {
+ char *user_config;
+ xasprintf(&user_config, "%s/%s", userconf_dir, RC_CONF_FILE);
- /* Support old configs. */
- if (exists(RC_CONF_OLD)) {
- old = rc_config_load(RC_CONF_OLD);
- TAILQ_CONCAT(rc_conf, old, entries);
- rc_stringlist_free(old);
+ if (exists(user_config)) {
+ tmp = rc_config_load(user_config);
+ TAILQ_CONCAT(rc_conf, tmp, entries);
+ rc_stringlist_free(tmp);
}
+ free(user_config);
+ }
- rc_conf = rc_config_directory(rc_conf);
- rc_conf = rc_config_kcl(rc_conf);
+ rc_conf = rc_config_directory(rc_conf);
+ rc_conf = rc_config_kcl(rc_conf);
- /* Convert old uppercase to lowercase */
- TAILQ_FOREACH(s, rc_conf, entries) {
- p = s->value;
- while (p && *p && *p != '=') {
- if (isupper((unsigned char)*p))
- *p = tolower((unsigned char)*p);
- p++;
- }
+ /* Convert old uppercase to lowercase */
+ TAILQ_FOREACH(s, rc_conf, entries) {
+ p = s->value;
+ while (p && *p && *p != '=') {
+ if (isupper((unsigned char)*p))
+ *p = tolower((unsigned char)*p);
+ p++;
}
}