From e2ef6e9c34c33b9667cce50fcf77eca6bb173585 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 6 Jun 2021 00:34:11 +0200 Subject: [PATCH] plugins: sys: drop conditions not affecting any svc_t - Fix bug when calling sys_update_conds() when dir already exists and we're not being called from the scandir() handler. I.e., every time but the first for each new condition sub-family - Drop sys conditions that don't affect any svc_t. This may seem counterintuitive, and we should probably not use oneshot conds, but if we leave these conds asserted they may cause inadvertent trigger if a finit.conf is loaded which ha this sys cond. E.g., if ctrlaltdel is asserted and we enable a task in finit.conf and call `initctl reload`, the task would start immediately, even though ctrl-alt-del may have been pressed a week ago Signed-off-by: Joachim Wiberg --- plugins/sys.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/plugins/sys.c b/plugins/sys.c index 15db0ad0..619711bc 100644 --- a/plugins/sys.c +++ b/plugins/sys.c @@ -41,17 +41,31 @@ static int sys_add_path(struct iwatch *iw, char *path) return iwatch_add(iw, path, IN_ONLYDIR | IN_CLOSE_WRITE); } +/* + * unlink conditions with no active task/service, otherwise they may + * trigger inadvertently when calling `initctl reload` to activate + * a new configuration. + */ static void sys_update_conds(char *dir, char *name, uint32_t mask) { + char path[256]; char *cond; + char *ptr; - cond = strstr(name, COND_BASE); + ptr = strrchr(name, '/'); + if (ptr) + snprintf(path, sizeof(path), "%s/%s", dir, ++ptr); + else + snprintf(path, sizeof(path), "%s/%s", dir, name); + + cond = strstr(path, COND_BASE); if (!cond) return; cond += strlen(COND_BASE) + 1; _d("cond: %s set: %d", cond, mask & IN_CREATE ? 1 : 0); - cond_update(cond); + if (!cond_update(cond)) + unlink(path); } /* synthesize events in case of new run dirs */