Skip to content

Commit f0a4c49

Browse files
committed
librc: read RC_SCRIPTDIRS from the environment
1 parent 0a140ad commit f0a4c49

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/librc/librc.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,12 +656,30 @@ rc_set_user(void)
656656
clear_dirfds();
657657
}
658658

659+
static const char **env_scriptdirs;
660+
659661
const char * const *
660662
rc_scriptdirs(void)
661663
{
664+
static bool set = false;
665+
const char *dirs;
666+
662667
if (rc_dirs.set)
663668
return rc_dirs.scriptdirs;
664-
return scriptdirs;
669+
670+
if (!set && (dirs = getenv("RC_SCRIPTDIRS"))) {
671+
char *tmp = xstrdup(dirs);
672+
unsigned entries = 0;
673+
674+
for (const char *entry = dirs; *entry; entry++)
675+
entries += *entry == ':';
676+
env_scriptdirs = calloc(entries + 2, sizeof(*scriptdirs));
677+
678+
for (size_t i = 0; i < entries + 1 && tmp; i++)
679+
env_scriptdirs[i] = strsep(&tmp, ":");
680+
}
681+
682+
return env_scriptdirs ? env_scriptdirs : scriptdirs;
665683
}
666684

667685
size_t

src/shared/misc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ static const char *const env_allowlist[] = {
5959
"EERROR_QUIET", "EINFO_QUIET",
6060
"IN_BACKGROUND", "IN_DRYRUN", "IN_HOTPLUG",
6161
"RC_DEBUG", "RC_NODEPS", "RC_USER_SERVICES",
62+
"RC_SCRIPTDIRS",
6263
"LANG", "LC_MESSAGES", "TERM",
6364
"EINFO_COLOR", "EINFO_VERBOSE",
6465
NULL

0 commit comments

Comments
 (0)