From f77a325986f7e3893ff063a62ffc5d20aba2cf16 Mon Sep 17 00:00:00 2001 From: obarun <eric@obarun.org> Date: Sat, 15 Jul 2023 13:20:59 +1100 Subject: [PATCH] fix recognition of earlier service --- src/lib66/sanitize/sanitize_init.c | 22 ++++++++++++---------- src/lib66/sanitize/sanitize_scandir.c | 4 +++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/lib66/sanitize/sanitize_init.c b/src/lib66/sanitize/sanitize_init.c index 4f29449e..676eb70f 100644 --- a/src/lib66/sanitize/sanitize_init.c +++ b/src/lib66/sanitize/sanitize_init.c @@ -46,7 +46,7 @@ void sanitize_init(unsigned int *alist, unsigned int alen, graph_t *g, resolve_s ftrigr_t fifo = FTRIGR_ZERO ; uint32_t earlier ; gid_t gid = getgid() ; - int is_supervised = 0, is_init ; + int is_supervised = 0, is_init = 0, gearlier = 0 ; unsigned int pos = 0, nsv = 0 ; unsigned int real[alen] ; unsigned int msg[areslen] ; @@ -78,6 +78,8 @@ void sanitize_init(unsigned int *alist, unsigned int alen, graph_t *g, resolve_s if (is_init < 0 || service_is(&sta, STATE_FLAGS_TOINIT) == STATE_FLAGS_TRUE) sanitize_livestate(&ares[aresid]) ; + if (earlier) + gearlier = aresid ; /** * Bundle and module type are not a daemons. We don't need to supervise it. * Special case for Oneshot, we only deal with the scandir symlink. */ @@ -101,12 +103,15 @@ void sanitize_init(unsigned int *alist, unsigned int alen, graph_t *g, resolve_s } /* down file */ - char downfile[scandirlen + 6] ; - auto_strings(downfile, scandir, "/down") ; - int fd = open_trunc(downfile) ; - if (fd < 0) - log_dieusys(LOG_EXIT_SYS, "create file: ", downfile) ; - fd_close(fd) ; + if (!earlier) { + + char downfile[scandirlen + 6] ; + auto_strings(downfile, scandir, "/down") ; + int fd = open_trunc(downfile) ; + if (fd < 0) + log_dieusys(LOG_EXIT_SYS, "create file: ", downfile) ; + fd_close(fd) ; + } if (!earlier && is_supervised) { @@ -166,9 +171,6 @@ void sanitize_init(unsigned int *alist, unsigned int alen, graph_t *g, resolve_s } } - if (earlier) - sanitize_scandir(&ares[0]) ; - /** * We pass through here even for Bundle, Module and Oneshot. * We need to write the state file anyway. Thus can always diff --git a/src/lib66/sanitize/sanitize_scandir.c b/src/lib66/sanitize/sanitize_scandir.c index d34621d2..c89e15cd 100644 --- a/src/lib66/sanitize/sanitize_scandir.c +++ b/src/lib66/sanitize/sanitize_scandir.c @@ -105,6 +105,7 @@ void sanitize_scandir(resolve_service_t *res) int r ; char *name = res->sa.s + res->name ; + uint8_t earlier = 0 ; size_t namelen = strlen(name) ; size_t livelen = strlen(res->sa.s + res->live.livedir) ; size_t scandirlen = livelen + SS_SCANDIR_LEN + 1 + strlen(res->sa.s + res->ownerstr) ; @@ -126,7 +127,8 @@ void sanitize_scandir(resolve_service_t *res) compute_supervision_dir(res) ; - if (service_is(&sta, STATE_FLAGS_ISEARLIER) == STATE_FLAGS_TRUE) { + earlier = service_is(&sta, STATE_FLAGS_ISEARLIER) == STATE_FLAGS_TRUE ? 1 : 0 ; + if (!earlier) { if (svc_scandir_send(svcandir, "h") <= 0) log_dieu(LOG_EXIT_SYS, "reload scandir: ", svcandir) ; -- GitLab