From 3753da34ce731dd2560bee1c54933fd5711383e4 Mon Sep 17 00:00:00 2001
From: obarun <eric@obarun.org>
Date: Sat, 6 Jan 2024 12:42:05 +1100
Subject: [PATCH] optimize start time

---
 src/lib66/sanitize/sanitize_fdholder.c |  2 +-
 src/lib66/sanitize/sanitize_init.c     | 12 +++++++++++-
 src/lib66/svc/svc_unsupervise.c        |  2 ++
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/lib66/sanitize/sanitize_fdholder.c b/src/lib66/sanitize/sanitize_fdholder.c
index c27e0af2..ee561645 100644
--- a/src/lib66/sanitize/sanitize_fdholder.c
+++ b/src/lib66/sanitize/sanitize_fdholder.c
@@ -182,7 +182,7 @@ int sanitize_fdholder(resolve_service_t *res, ss_state_t *sta, uint32_t flag, ui
         if (!openwritenclose_unsafe(file, list.s, list.len))
             log_warnusys_return(LOG_EXIT_ZERO, "write file: ", file) ;
 
-        svc_send_fdholder(socket, "twR") ;
+        //svc_send_fdholder(socket, "twR") ;
 
         stralloc_free(&list) ;
     }
diff --git a/src/lib66/sanitize/sanitize_init.c b/src/lib66/sanitize/sanitize_init.c
index ad93ec2a..b3ec035b 100644
--- a/src/lib66/sanitize/sanitize_init.c
+++ b/src/lib66/sanitize/sanitize_init.c
@@ -41,6 +41,7 @@
 #include <66/enum.h>
 #include <66/sanitize.h>
 #include <66/symlink.h>
+#include <66/svc.h>
 
 void cleanup(struct resolve_hash_s *hash, unsigned int alen)
 {
@@ -64,6 +65,10 @@ void cleanup(struct resolve_hash_s *hash, unsigned int alen)
         unlink(pres->sa.s + pres->live.scandir) ;
 
     }
+
+    if (alen)
+        svc_send_fdholder(hash[0].res.sa.s + hash[0].res.live.fdholderdir, "twR") ;
+
     errno = e ;
 }
 
@@ -76,7 +81,7 @@ void sanitize_init(unsigned int *alist, unsigned int alen, graph_t *g, struct re
         return ;
 
     ftrigr_t fifo = FTRIGR_ZERO ;
-    uint32_t earlier ;
+    uint32_t earlier, fdh = 0 ;
     gid_t gid = getgid() ;
     int is_supervised = 0 ;
     unsigned int pos = 0, nsv = 0, msg[alen] ;
@@ -173,6 +178,8 @@ void sanitize_init(unsigned int *alist, unsigned int alen, graph_t *g, struct re
                 cleanup(toclean, pos) ;
                 log_dieusys(LOG_EXIT_SYS, "create fifo: ", pres->sa.s + pres->live.eventdir) ;
             }
+
+            fdh = 1 ;
         }
 
         if (!state_write(&sta, pres)) {
@@ -183,6 +190,9 @@ void sanitize_init(unsigned int *alist, unsigned int alen, graph_t *g, struct re
         real[nsv++] = *hash ;
     }
 
+    if (!earlier && fdh && nsv)
+        svc_send_fdholder(real[0].res.sa.s + real[0].res.live.fdholderdir, "twR") ;
+
     /**
      * scandir is already running, we need to synchronize with it
      * */
diff --git a/src/lib66/svc/svc_unsupervise.c b/src/lib66/svc/svc_unsupervise.c
index e48f0562..850e4220 100644
--- a/src/lib66/svc/svc_unsupervise.c
+++ b/src/lib66/svc/svc_unsupervise.c
@@ -34,6 +34,8 @@ static void sanitize_it(resolve_service_t *res)
 
     sanitize_fdholder(res, &sta, STATE_FLAGS_FALSE, 0) ;
 
+    svc_send_fdholder(res->sa.s + res->live.fdholderdir, "twR") ;
+
     state_set_flag(&sta, STATE_FLAGS_TOUNSUPERVISE, STATE_FLAGS_TRUE) ;
     state_set_flag(&sta, STATE_FLAGS_ISUP, STATE_FLAGS_FALSE) ;
 
-- 
GitLab