From 12d14aae844c205c8501b792a2da2cc3df052a06 Mon Sep 17 00:00:00 2001 From: Robert Andersson Date: Wed, 12 Sep 2018 15:02:04 +0200 Subject: [PATCH] fix service enable/disable support Signed-off-by: Robert Andersson --- src/conf.c | 35 ++++++++++++++++------------------- src/serv.c | 8 ++++---- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/conf.c b/src/conf.c index abef1190..aefeb8ba 100644 --- a/src/conf.c +++ b/src/conf.c @@ -30,6 +30,7 @@ #include #include /* BSD sys/queue.h API */ #include +#include #include "finit.h" #include "cond.h" @@ -52,7 +53,7 @@ struct conf_change { char *name; }; -static uev_t w1, w2, w3; +static uev_t w1, w2, w3, w4; static TAILQ_HEAD(head, conf_change) conf_change_list = TAILQ_HEAD_INITIALIZER(conf_change_list); static int parse_conf(char *file); @@ -577,8 +578,8 @@ static int parse_conf(char *file) */ int conf_reload(void) { - int i, num; - struct dirent **e; + size_t i; + glob_t gl; /* Mark and sweep */ svc_mark_dynamic(); @@ -601,20 +602,14 @@ int conf_reload(void) parse_conf(FINIT_CONF); /* Next, read all *.conf in /etc/finit.d/ */ - num = scandir(rcsd, &e, NULL, alphasort); - if (num < 0) { - _d("Skipping %s, no files found ...", rcsd); - goto done; - } + glob("/etc/finit.d/*.conf", 0, NULL, &gl); + glob("/etc/finit.d/enabled/*.conf", GLOB_APPEND, NULL, &gl); - for (i = 0; i < num; i++) { - char *name = e[i]->d_name; - char path[LINE_SIZE]; + for (i = 0; i < gl.gl_pathc; i++) { + char *path = gl.gl_pathv[i]; size_t len; struct stat st; - snprintf(path, sizeof(path), "%s/%s", rcsd, name); - /* Check that it's an actual file ... beyond any symlinks */ if (lstat(path, &st)) { _d("Skipping %s, cannot access: %s", path, strerror(errno)); @@ -650,9 +645,7 @@ int conf_reload(void) parse_conf_dynamic(path); } - while (num--) - free(e[num]); - free(e); + globfree(&gl); done: /* Drop record of all .conf changes */ @@ -783,6 +776,9 @@ static void conf_cb(uev_t *w, void *arg, int events) break; } } + + if (conf_any_change()) + service_reload_dynamic(); } static int add_watcher(uev_ctx_t *ctx, uev_t *w, char *path, uint32_t opt) @@ -857,8 +853,9 @@ int conf_monitor(uev_ctx_t *ctx) * changes to either symlink or target. */ rc += add_watcher(ctx, &w1, FINIT_RCSD, 0); - rc += add_watcher(ctx, &w2, FINIT_RCSD "/available", IN_DONT_FOLLOW); - rc += add_watcher(ctx, &w3, FINIT_CONF, 0); + rc += add_watcher(ctx, &w2, FINIT_RCSD "/available/", IN_DONT_FOLLOW); + rc += add_watcher(ctx, &w3, FINIT_RCSD "/enabled/", 0); + rc += add_watcher(ctx, &w4, FINIT_CONF, 0); return rc + conf_reload(); } @@ -869,7 +866,7 @@ int conf_monitor(uev_ctx_t *ctx) int conf_init(void) { hostname = strdup(DEFHOST); - w1.fd = w2.fd = w3.fd = -1; + w1.fd = w2.fd = w3.fd = w4.fd = -1; return conf_monitor(NULL); } diff --git a/src/serv.c b/src/serv.c index 5228aa28..f638d9a8 100644 --- a/src/serv.c +++ b/src/serv.c @@ -120,7 +120,7 @@ int serv_list(char *arg) if (fisdir(enabled)) do_list("ENABLED ", enabled); if (fisdir(FINIT_RCSD)) - do_list("ENABLED ", FINIT_RCSD); + do_list("STATIC ", FINIT_RCSD); return 0; } @@ -140,11 +140,11 @@ int serv_enable(char *arg) } pushd(FINIT_RCSD); - snprintf(path, sizeof(path), "available/%s", arg); + snprintf(path, sizeof(path), "%s/%s", available, arg); if (!fexist(path)) errx(1, "Cannot find %s", path); - snprintf(link, sizeof(link), "%s/%s", FINIT_RCSD, arg); + snprintf(link, sizeof(link), "%s/%s", enabled, arg); if (fexist(link)) errx(1, "%s already exists", link); @@ -165,7 +165,7 @@ int serv_disable(char *arg) arg = corr; } - snprintf(link, sizeof(link), "%s/%s", FINIT_RCSD, arg); + snprintf(link, sizeof(link), "%s/%s", enabled, arg); if (stat(link, &st)) err(1, "Cannot find %s", link);