Skip to content

Commit

Permalink
librc-depend, gendepends: Use rc_scriptdirs for lookup of services.
Browse files Browse the repository at this point in the history
  • Loading branch information
navi-desu committed Oct 26, 2024
1 parent 9c0cf7e commit 5d186b3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
6 changes: 2 additions & 4 deletions sh/gendepends.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ depend() {
}

_done_dirs=
for _dir in \
@SYSCONFDIR@/init.d \
@PKG_PREFIX@/etc/init.d \
@LOCAL_PREFIX@/etc/init.d
for _dir in $RC_SCRIPTDIRS
do
_dir="$_dir/init.d"
[ -d "$_dir" ] || continue

# Don't do the same dir twice
Expand Down
38 changes: 30 additions & 8 deletions src/librc/librc-depend.c
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,35 @@ rc_deptree_update_needed(time_t *newest, char *file)
return newer;
}

static void
setup_environment(void) {
char *scriptdirs, *env;
size_t env_size = 0;
struct utsname uts;

for (const char * const *dirs = rc_scriptdirs(); *dirs; dirs++)
env_size += strlen(*dirs) + sizeof(' ');

env = scriptdirs = xmalloc(env_size);

for (const char * const *dirs = rc_scriptdirs(); *dirs; dirs++) {
int len = snprintf(scriptdirs, env_size, "%s ", *dirs);
scriptdirs += len;
env_size -= len;
}

setenv("RC_SCRIPTDIRS", env, 1);
free(env);

/* Some init scripts need RC_LIBEXECDIR to source stuff
Ideally we should be setting our full env instead */
if (!getenv("RC_LIBEXECDIR"))
setenv("RC_LIBEXECDIR", RC_LIBEXECDIR, 0);

if (uname(&uts) == 0)
setenv("RC_UNAME", uts.sysname, 1);
}

/* This is a 7 phase operation
Phase 1 is a shell script which loads each init script and config in turn
and echos their dependency info to stdout
Expand Down Expand Up @@ -804,17 +833,10 @@ rc_deptree_update(void)
size_t i, l;
bool retval = true;
const char *sys = rc_sys();
struct utsname uts;
int serrno;

/* Some init scripts need RC_LIBEXECDIR to source stuff
Ideally we should be setting our full env instead */
if (!getenv("RC_LIBEXECDIR"))
setenv("RC_LIBEXECDIR", RC_LIBEXECDIR, 0);

if (uname(&uts) == 0)
setenv("RC_UNAME", uts.sysname, 1);
/* Phase 1 - source all init scripts and print dependencies */
setup_environment();
if (!(fp = popen(GENDEP, "r")))
return false;

Expand Down

0 comments on commit 5d186b3

Please sign in to comment.