diff options
| author | Anna (navi) Figueiredo Gomes <navi@vlhl.dev> | 2025-03-16 19:19:59 +0100 |
|---|---|---|
| committer | Anna (navi) Figueiredo Gomes <navi@vlhl.dev> | 2025-03-16 19:19:59 +0100 |
| commit | 1a7a68780d6dc1649d08f189bbd21691ebfd7d5b (patch) | |
| tree | 7104b63445fd594ef9d1637c76192b2348f9cd77 | |
| parent | 72b1e8cd0c08dee3efb0954298453ee7c56f2037 (diff) | |
openrc-run: Iterate all scriptdirs in reverse order to load configs.origin/scriptdir_load
Less error prone and more flexible, and allows for better support of
multiple script dirs.
| -rw-r--r-- | sh/openrc-run.sh.in | 39 | ||||
| -rw-r--r-- | src/shared/misc.c | 18 |
2 files changed, 33 insertions, 24 deletions
diff --git a/sh/openrc-run.sh.in b/sh/openrc-run.sh.in index c8e347dd..f1e37b82 100644 --- a/sh/openrc-run.sh.in +++ b/sh/openrc-run.sh.in @@ -159,6 +159,13 @@ _status() fi } +_load_config() +{ + if ! sourcex -e "$1.$RC_RUNLEVEL"; then + sourcex -e "$1" + fi +} + # These functions select the appropriate function to call from the # supervisor modules default_start() @@ -234,33 +241,17 @@ if [ -d "@SYSCONFDIR@/rc.conf.d" ]; then done fi -_usr_conf_d=${XDG_CONFIG_HOME:-${HOME}/.config}/rc if yesno "$RC_USER_SERVICES"; then - sourcex -e "$_usr_conf_d/rc.conf" -fi - -_conf_d=${RC_SERVICE%/*}/../conf.d -# If we're net.eth0 or openvpn.work then load net or openvpn config -_c=${RC_SVCNAME%%.*} -if [ -n "$_c" -a "$_c" != "$RC_SVCNAME" ]; then - if ! sourcex -e "$_conf_d/$_c.$RC_RUNLEVEL"; then - sourcex -e "$_conf_d/$_c" - fi -fi -unset _c - -# Overlay with our specific config -if ! sourcex -e "$_conf_d/$RC_SVCNAME.$RC_RUNLEVEL"; then - sourcex -e "$_conf_d/$RC_SVCNAME" + sourcex -e "${XDG_CONFIG_HOME:-${HOME}/.config}/rc/rc.conf" fi -unset _conf_d -if yesno "$RC_USER_SERVICES" && [ $_usr_conf_d != ${RC_SERVICE%/*} ]; then - if ! sourcex -e "$_usr_conf_d/$RC_SVCNAME.$RC_RUNLEVEL"; then - sourcex -e "$_usr_conf_d/$RC_SVCNAME" - fi -fi -unset _usr_conf_d +IFS=: +_c=${RC_SVCNAME%%.*} # If we're net.eth0 or openvpn.work then load net or openvpn config +for _script_d in $RC_SCRIPTDIRS; do + [ "$_c" != "$RC_SVCNAME" ] && _load_config "$_script_d/conf.d/$_c" + _load_config "$_script_d/conf.d/$RC_SVCNAME" +done +unset IFS _script_d # load service supervisor functions sourcex "@LIBEXECDIR@/sh/runit.sh" diff --git a/src/shared/misc.c b/src/shared/misc.c index e6d477d8..b7e01264 100644 --- a/src/shared/misc.c +++ b/src/shared/misc.c @@ -154,6 +154,22 @@ env_filter(void) rc_stringlist_free(profile); } +static void +export_script_path(void) +{ + const char * const *scriptdirs = rc_scriptdirs(); + size_t count, size, written = 0; + char *path; + + /* build script path in reverse order so configs override each other */ + for (count = 0; scriptdirs[count]; count++) + size += strlen(scriptdirs[count]) + sizeof(':'); + path = xmalloc(size); + for (count--; count; count--) + written += snprintf(path + written, size - written, "%s:", scriptdirs[count]); + setenv("RC_SCRIPTDIRS", path, true); +} + void env_config(void) { @@ -214,6 +230,8 @@ env_config(void) free(e); free(tmpdir); + export_script_path(); + if ((fp = fopen(RC_KRUNLEVEL, "r"))) { if (xgetline(&buffer, &size, fp) != -1) setenv("RC_DEFAULTLEVEL", buffer, 1); |
