Skip to content

Commit c664da6

Browse files
committed
Initial path support for user services in librc
This introduces new variables and functions to allow for setting paths (RC_SVCDIR, RC_RUNLEVELDIR, RC_INITDIR and RC_CONFDIR) at runtime, needed for user services. This also patches librc to use said functions instead of the #define'd variables. Signed-off-by: anna <anna@navirc.com>
1 parent 6f44445 commit c664da6

File tree

4 files changed

+187
-80
lines changed

4 files changed

+187
-80
lines changed

src/librc/librc-daemon.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ rc_service_daemon_set(const char *service, const char *exec,
400400
return false;
401401
}
402402

403-
xasprintf(&dirpath, RC_SVCDIR "/daemons/%s", basename_c(service));
403+
xasprintf(&dirpath, "%s/daemons/%s", rc_svcdir_get(), basename_c(service));
404404

405405
/* Regardless, erase any existing daemon info */
406406
if ((dp = opendir(dirpath))) {
@@ -470,7 +470,7 @@ rc_service_started_daemon(const char *service,
470470
if (!service || !exec)
471471
return false;
472472

473-
xasprintf(&dirpath, RC_SVCDIR "/daemons/%s", basename_c(service));
473+
xasprintf(&dirpath, "%s/daemons/%s", rc_svcdir_get(), basename_c(service));
474474
match = _match_list(exec, argv, NULL);
475475

476476
if (indx > 0) {
@@ -522,8 +522,8 @@ rc_service_daemons_crashed(const char *service)
522522
char *ch_root;
523523
char *spidfile;
524524

525-
path += snprintf(dirpath, sizeof(dirpath), RC_SVCDIR "/daemons/%s",
526-
basename_c(service));
525+
path += snprintf(dirpath, sizeof(dirpath), "%s/daemons/%s",
526+
rc_svcdir_get(), basename_c(service));
527527

528528
if (!(dp = opendir(dirpath)))
529529
return false;

src/librc/librc-depend.c

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@
2222

2323
#define GENDEP RC_LIBEXECDIR "/sh/gendepends.sh"
2424

25-
#define RC_DEPCONFIG RC_SVCDIR "/depconfig"
25+
#define RC_DEPCONFIG "/depconfig"
26+
27+
static char*
28+
depconfigpath_get() {
29+
char *path = xmalloc(sizeof(char) * PATH_MAX);
30+
snprintf(path, PATH_MAX, "%s/%s", rc_svcdir_get(), RC_DEPCONFIG);
31+
return path;
32+
}
2633

2734
static const char *bootlevel = NULL;
2835

@@ -655,19 +662,19 @@ static const DEPPAIR deppairs[] = {
655662

656663
static const char *const depdirs[] =
657664
{
658-
RC_SVCDIR,
659-
RC_SVCDIR "/starting",
660-
RC_SVCDIR "/started",
661-
RC_SVCDIR "/stopping",
662-
RC_SVCDIR "/inactive",
663-
RC_SVCDIR "/wasinactive",
664-
RC_SVCDIR "/failed",
665-
RC_SVCDIR "/hotplugged",
666-
RC_SVCDIR "/daemons",
667-
RC_SVCDIR "/options",
668-
RC_SVCDIR "/exclusive",
669-
RC_SVCDIR "/scheduled",
670-
RC_SVCDIR "/tmp",
665+
"",
666+
"starting",
667+
"started",
668+
"stopping",
669+
"inactive",
670+
"wasinactive",
671+
"failed",
672+
"hotplugged",
673+
"daemons",
674+
"options",
675+
"exclusive",
676+
"scheduled",
677+
"tmp",
671678
NULL
672679
};
673680

@@ -682,9 +689,13 @@ rc_deptree_update_needed(time_t *newest, char *file)
682689
time_t mtime;
683690

684691
/* Create base directories if needed */
685-
for (i = 0; depdirs[i]; i++)
686-
if (mkdir(depdirs[i], 0755) != 0 && errno != EEXIST)
687-
fprintf(stderr, "mkdir `%s': %s\n", depdirs[i], strerror(errno));
692+
char *depdir = xmalloc(sizeof(char) * PATH_MAX);
693+
for (i = 0; depdirs[i]; i++) {
694+
snprintf(depdir, PATH_MAX, "%s/%s", rc_svcdir_get(), depdirs[i]);
695+
if (mkdir(depdir, 0755) != 0 && errno != EEXIST)
696+
fprintf(stderr, "mkdir `%s': %s\n", depdir, strerror(errno));
697+
}
698+
free(depdir);
688699

689700
/* Quick test to see if anything we use has changed and we have
690701
* data in our deptree. */
@@ -700,8 +711,8 @@ rc_deptree_update_needed(time_t *newest, char *file)
700711
mtime = time(NULL);
701712
}
702713

703-
newer |= !deep_mtime_check(RC_INITDIR,true,&mtime,file);
704-
newer |= !deep_mtime_check(RC_CONFDIR,true,&mtime,file);
714+
newer |= !deep_mtime_check(rc_initdir_get(),true,&mtime,file);
715+
newer |= !deep_mtime_check(rc_confdir_get(),true,&mtime,file);
705716
#ifdef RC_PKG_INITDIR
706717
newer |= !deep_mtime_check(RC_PKG_INITDIR,true,&mtime,file);
707718
#endif
@@ -718,7 +729,9 @@ rc_deptree_update_needed(time_t *newest, char *file)
718729

719730
/* Some init scripts dependencies change depending on config files
720731
* outside of baselayout, like syslog-ng, so we check those too. */
721-
config = rc_config_list(RC_DEPCONFIG);
732+
char *depconf = depconfigpath_get();
733+
config = rc_config_list(depconf);
734+
free(depconf);
722735
TAILQ_FOREACH(s, config, entries) {
723736
newer |= !deep_mtime_check(s->value, true, &mtime, file);
724737
}
@@ -1059,19 +1072,21 @@ rc_deptree_update(void)
10591072
}
10601073

10611074
/* Save our external config files to disk */
1075+
char *depconf = depconfigpath_get();
10621076
if (TAILQ_FIRST(config)) {
1063-
if ((fp = fopen(RC_DEPCONFIG, "w"))) {
1077+
if ((fp = fopen(depconf, "w"))) {
10641078
TAILQ_FOREACH(s, config, entries)
10651079
fprintf(fp, "%s\n", s->value);
10661080
fclose(fp);
10671081
} else {
10681082
fprintf(stderr, "fopen `%s': %s\n",
1069-
RC_DEPCONFIG, strerror(errno));
1083+
depconf, strerror(errno));
10701084
retval = false;
10711085
}
10721086
} else {
1073-
unlink(RC_DEPCONFIG);
1087+
unlink(depconf);
10741088
}
1089+
free(depconf);
10751090

10761091
rc_stringlist_free(config);
10771092
free(deptree);

0 commit comments

Comments
 (0)