diff options
Diffstat (limited to 'src/librc/librc-depend.c')
-rw-r--r-- | src/librc/librc-depend.c | 115 |
1 files changed, 77 insertions, 38 deletions
diff --git a/src/librc/librc-depend.c b/src/librc/librc-depend.c index d584af2c..32286c51 100644 --- a/src/librc/librc-depend.c +++ b/src/librc/librc-depend.c @@ -35,10 +35,10 @@ #define GENDEP RC_LIBEXECDIR "/sh/gendepends.sh" -#define RC_DEPCONFIG RC_SVCDIR "/depconfig" - static const char *bootlevel = NULL; +#define RC_DEPCONFIG "depconfig" + static char * get_shell_value(char *string) { @@ -120,8 +120,16 @@ get_deptype(const RC_DEPINFO *depinfo, const char *type) } RC_DEPTREE * -rc_deptree_load(void) { - return rc_deptree_load_file(RC_DEPTREE_CACHE); +rc_deptree_load(void) +{ + char *deptree_cache; + RC_DEPTREE *deptree; + + xasprintf(&deptree_cache, "%s/%s", rc_service_dir(), RC_DEPTREE_CACHE); + deptree = rc_deptree_load_file(deptree_cache); + free(deptree_cache); + + return deptree; } RC_DEPTREE * @@ -668,19 +676,19 @@ static const DEPPAIR deppairs[] = { static const char *const depdirs[] = { - RC_SVCDIR, - RC_SVCDIR "/starting", - RC_SVCDIR "/started", - RC_SVCDIR "/stopping", - RC_SVCDIR "/inactive", - RC_SVCDIR "/wasinactive", - RC_SVCDIR "/failed", - RC_SVCDIR "/hotplugged", - RC_SVCDIR "/daemons", - RC_SVCDIR "/options", - RC_SVCDIR "/exclusive", - RC_SVCDIR "/scheduled", - RC_SVCDIR "/tmp", + "", + "starting", + "started", + "stopping", + "inactive", + "wasinactive", + "failed", + "hotplugged", + "daemons", + "options", + "exclusive", + "scheduled", + "tmp", NULL }; @@ -690,19 +698,27 @@ rc_deptree_update_needed(time_t *newest, char *file) bool newer = false; RC_STRINGLIST *config; RC_STRING *s; - int i; struct stat buf; time_t mtime; + char *depconfig; + char *deptree_cache; + const char * const dirs[] = { RC_INIT_SUBDIR, RC_CONF_SUBDIR, RC_CONF_FILE, NULL }; + char *dir; + const char *service_dir = rc_service_dir(); + const char *sysconf_dir = rc_sysconf_dir(); /* Create base directories if needed */ - for (i = 0; depdirs[i]; i++) - if (mkdir(depdirs[i], 0755) != 0 && errno != EEXIST) - fprintf(stderr, "mkdir `%s': %s\n", depdirs[i], strerror(errno)); + for (int i = 0; depdirs[i]; i++) { + xasprintf(&dir, "%s/%s", service_dir, depdirs[i]); + if (mkdir(dir, 0755) != 0 && errno != EEXIST) + fprintf(stderr, "mkdir '%s': %s\n", dir, strerror(errno)); + free(dir); + } /* Quick test to see if anything we use has changed and we have * data in our deptree. */ - - if (stat(RC_DEPTREE_CACHE, &buf) == 0) { + xasprintf(&deptree_cache, "%s/%s", service_dir, RC_DEPTREE_CACHE); + if (stat(deptree_cache, &buf) == 0) { mtime = buf.st_mtime; } else { /* No previous cache found. @@ -712,30 +728,48 @@ rc_deptree_update_needed(time_t *newest, char *file) newer = true; mtime = time(NULL); } + free(deptree_cache); + + for (int i = 0; dirs[i]; i++) { + xasprintf(&dir, "%s/%s", sysconf_dir, dirs[i]); + newer |= !deep_mtime_check(dir, true, &mtime, file); + free(dir); + } - newer |= !deep_mtime_check(RC_INITDIR,true,&mtime,file); - newer |= !deep_mtime_check(RC_CONFDIR,true,&mtime,file); + /* Test user configs */ + if (rc_is_user()) { + const char *userconf_dir = rc_userconf_dir(); + for (int i = 0; dirs[i]; i++) { + xasprintf(&dir, "%s/%s", userconf_dir, dirs[i]); + newer |= !deep_mtime_check(dir, true, &mtime, file); + free(dir); + } + newer |= !deep_mtime_check(RC_CONF, true, &mtime, file); + /* RC_USER doesn't have those paths */ + } else { #ifdef RC_PKG_INITDIR - newer |= !deep_mtime_check(RC_PKG_INITDIR,true,&mtime,file); + newer |= !deep_mtime_check(RC_PKG_INITDIR, true, &mtime, file); #endif #ifdef RC_PKG_CONFDIR - newer |= !deep_mtime_check(RC_PKG_CONFDIR,true,&mtime,file); + newer |= !deep_mtime_check(RC_PKG_CONFDIR, true, &mtime, file); #endif -#ifdef RC_LOCAL_INITDIRs - newer |= !deep_mtime_check(RC_LOCAL_INITDIR,true,&mtime,file); +#ifdef RC_LOCAL_INITDIR + newer |= !deep_mtime_check(RC_LOCAL_INITDIR, true, &mtime, file); #endif #ifdef RC_LOCAL_CONFDIR - newer |= !deep_mtime_check(RC_LOCAL_CONFDIR,true,&mtime,file); + newer |= !deep_mtime_check(RC_LOCAL_CONFDIR, true, &mtime, file); #endif - newer |= !deep_mtime_check(RC_CONF,true,&mtime,file); + } /* Some init scripts dependencies change depending on config files * outside of baselayout, like syslog-ng, so we check those too. */ - config = rc_config_list(RC_DEPCONFIG); + xasprintf(&depconfig, "%s/depconfig", service_dir); + config = rc_config_list(depconfig); TAILQ_FOREACH(s, config, entries) { newer |= !deep_mtime_check(s->value, true, &mtime, file); } rc_stringlist_free(config); + free(depconfig); /* Return newest file time, if requested */ if ((newer) && (newest != NULL)) { @@ -768,6 +802,8 @@ rc_deptree_update(void) char *line = NULL; size_t len = 0; char *depend, *depends, *service, *type, *nosys, *onosys; + char *deptree_cache; + char *depconfig; size_t i, k, l; bool retval = true; const char *sys = rc_sys(); @@ -1048,7 +1084,8 @@ rc_deptree_update(void) This works and should be entirely shell parseable provided that depend names don't have any non shell variable characters in */ - if ((fp = fopen(RC_DEPTREE_CACHE, "w"))) { + xasprintf(&deptree_cache, "%s/%s", rc_service_dir(), RC_DEPTREE_CACHE); + if ((fp = fopen(deptree_cache, "w"))) { i = 0; TAILQ_FOREACH(depinfo, deptree, entries) { fprintf(fp, "depinfo_%zu_service='%s'\n", @@ -1066,27 +1103,29 @@ rc_deptree_update(void) } fclose(fp); } else { - fprintf(stderr, "fopen `%s': %s\n", - RC_DEPTREE_CACHE, strerror(errno)); + fprintf(stderr, "fopen `%s': %s\n", deptree_cache, strerror(errno)); retval = false; } + free(deptree_cache); /* Save our external config files to disk */ + xasprintf(&depconfig, "%s/depconfig", rc_service_dir()); if (TAILQ_FIRST(config)) { - if ((fp = fopen(RC_DEPCONFIG, "w"))) { + if ((fp = fopen(depconfig, "w"))) { TAILQ_FOREACH(s, config, entries) fprintf(fp, "%s\n", s->value); fclose(fp); } else { fprintf(stderr, "fopen `%s': %s\n", - RC_DEPCONFIG, strerror(errno)); + depconfig, strerror(errno)); retval = false; } } else { - unlink(RC_DEPCONFIG); + unlink(depconfig); } rc_stringlist_free(config); + free(depconfig); free(deptree); return retval; } |