fix service enable/disable support

Signed-off-by: Robert Andersson <robert.m.andersson@se.atlascopco.com>
This commit is contained in:
Robert Andersson committed 2018-10-22 12:51:58 +02:00
1 parent 6a7f115781
commit 12d14aae84
2 files changed
+20 -23

No files matched your search

+16 -19
View File
@@ -30,6 +30,7 @@
#include <lite/lite.h> #include <lite/lite.h>
#include <lite/queue.h> /* BSD sys/queue.h API */ #include <lite/queue.h> /* BSD sys/queue.h API */
#include <sys/time.h> #include <sys/time.h>
#include <glob.h>
#include "finit.h" #include "finit.h"
#include "cond.h" #include "cond.h"
@@ -52,7 +53,7 @@ struct conf_change {
char *name; 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 TAILQ_HEAD(head, conf_change) conf_change_list = TAILQ_HEAD_INITIALIZER(conf_change_list);
static int parse_conf(char *file); static int parse_conf(char *file);
@@ -577,8 +578,8 @@ static int parse_conf(char *file)
*/ */
int conf_reload(void) int conf_reload(void)
{ {
int i, num; size_t i;
struct dirent **e; glob_t gl;
/* Mark and sweep */ /* Mark and sweep */
svc_mark_dynamic(); svc_mark_dynamic();
@@ -601,20 +602,14 @@ int conf_reload(void)
parse_conf(FINIT_CONF); parse_conf(FINIT_CONF);
/* Next, read all *.conf in /etc/finit.d/ */ /* Next, read all *.conf in /etc/finit.d/ */
num = scandir(rcsd, &e, NULL, alphasort); glob("/etc/finit.d/*.conf", 0, NULL, &gl);
if (num < 0) { glob("/etc/finit.d/enabled/*.conf", GLOB_APPEND, NULL, &gl);
_d("Skipping %s, no files found ...", rcsd);
goto done;
}
for (i = 0; i < num; i++) { for (i = 0; i < gl.gl_pathc; i++) {
char *name = e[i]->d_name; char *path = gl.gl_pathv[i];
char path[LINE_SIZE];
size_t len; size_t len;
struct stat st; struct stat st;
snprintf(path, sizeof(path), "%s/%s", rcsd, name);
/* Check that it's an actual file ... beyond any symlinks */ /* Check that it's an actual file ... beyond any symlinks */
if (lstat(path, &st)) { if (lstat(path, &st)) {
_d("Skipping %s, cannot access: %s", path, strerror(errno)); _d("Skipping %s, cannot access: %s", path, strerror(errno));
@@ -650,9 +645,7 @@ int conf_reload(void)
parse_conf_dynamic(path); parse_conf_dynamic(path);
} }
while (num--) globfree(&gl);
free(e[num]);
free(e);
done: done:
/* Drop record of all .conf changes */ /* Drop record of all .conf changes */
@@ -783,6 +776,9 @@ static void conf_cb(uev_t *w, void *arg, int events)
break; break;
} }
} }
if (conf_any_change())
service_reload_dynamic();
} }
static int add_watcher(uev_ctx_t *ctx, uev_t *w, char *path, uint32_t opt) 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. * changes to either symlink or target.
*/ */
rc += add_watcher(ctx, &w1, FINIT_RCSD, 0); rc += add_watcher(ctx, &w1, FINIT_RCSD, 0);
rc += add_watcher(ctx, &w2, FINIT_RCSD "/available", IN_DONT_FOLLOW); rc += add_watcher(ctx, &w2, FINIT_RCSD "/available/", IN_DONT_FOLLOW);
rc += add_watcher(ctx, &w3, FINIT_CONF, 0); rc += add_watcher(ctx, &w3, FINIT_RCSD "/enabled/", 0);
rc += add_watcher(ctx, &w4, FINIT_CONF, 0);
return rc + conf_reload(); return rc + conf_reload();
} }
@@ -869,7 +866,7 @@ int conf_monitor(uev_ctx_t *ctx)
int conf_init(void) int conf_init(void)
{ {
hostname = strdup(DEFHOST); hostname = strdup(DEFHOST);
w1.fd = w2.fd = w3.fd = -1; w1.fd = w2.fd = w3.fd = w4.fd = -1;
return conf_monitor(NULL); return conf_monitor(NULL);
} }
+4 -4
View File
@@ -120,7 +120,7 @@ int serv_list(char *arg)
if (fisdir(enabled)) if (fisdir(enabled))
do_list("ENABLED ", enabled); do_list("ENABLED ", enabled);
if (fisdir(FINIT_RCSD)) if (fisdir(FINIT_RCSD))
do_list("ENABLED ", FINIT_RCSD); do_list("STATIC ", FINIT_RCSD);
return 0; return 0;
} }
@@ -140,11 +140,11 @@ int serv_enable(char *arg)
} }
pushd(FINIT_RCSD); pushd(FINIT_RCSD);
snprintf(path, sizeof(path), "available/%s", arg); snprintf(path, sizeof(path), "%s/%s", available, arg);
if (!fexist(path)) if (!fexist(path))
errx(1, "Cannot find %s", 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)) if (fexist(link))
errx(1, "%s already exists", link); errx(1, "%s already exists", link);
@@ -165,7 +165,7 @@ int serv_disable(char *arg)
arg = corr; arg = corr;
} }
snprintf(link, sizeof(link), "%s/%s", FINIT_RCSD, arg); snprintf(link, sizeof(link), "%s/%s", enabled, arg);
if (stat(link, &st)) if (stat(link, &st))
err(1, "Cannot find %s", link); err(1, "Cannot find %s", link);