chiark / gitweb /
logging: site: Log state on PHASE_RUN entry instead of initially
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 16 Feb 2020 15:06:34 +0000 (15:06 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 16 Feb 2020 15:17:33 +0000 (15:17 +0000)
site_startup calls enter_state_run which would print a message, but
logging is not set up that early.  The result is a message printed to
stderr before daemonisation.

We can distinguish this situation from other calls to enter_state_run
because the old state is SITE_STOP, which only occurs between config
reading (closure invocation) and site_startup being called.
So we can suppress this message.

But it did serve a purpose: it would only be printed if the site was
listed in `sites'; otherwise site_startup wouldn't be called and the
`entering state RUN' message would be absent.

So instead we provide a more explicit way to tell: on entering
PHASE_RUN, site_startup has either been called, or not.  And logging
is set up.  state is then STOP or RUN.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
site.c

diff --git a/site.c b/site.c
index 358f4068e48f365196c8aef143ad0169129f3c44..191c36463da7cf7bd1d6186a1a1f51ebb0484877 100644 (file)
--- a/site.c
+++ b/site.c
@@ -1712,8 +1712,9 @@ static void set_link_quality(struct site *st)
 
 static void enter_state_run(struct site *st)
 {
-    slog(st,LOG_STATE,"entering state RUN%s",
-        current_valid(st) ? " (keyed)" : " (unkeyed)");
+    if (st->state!=SITE_STOP)
+       slog(st,LOG_STATE,"entering state RUN%s",
+            current_valid(st) ? " (keyed)" : " (unkeyed)");
     st->state=SITE_RUN;
     st->timeout=0;
 
@@ -2297,6 +2298,13 @@ static void site_phase_shutdown_hook(void *sst, uint32_t newphase)
     send_msg7(st,"shutting down");
 }
 
+static void site_phase_run_hook(void *sst, uint32_t newphase)
+{
+    struct site *st=sst;
+    slog(st,LOG_STATE,"entering phase RUN in state %s",
+        state_name(st->state));
+}
+
 static void site_childpersist_clearkeys(void *sst, uint32_t newphase)
 {
     struct site *st=sst;
@@ -2552,6 +2560,7 @@ static list_t *site_apply(closure_t *self, struct cloc loc, dict_t *context,
     enter_state_stop(st);
 
     add_hook(PHASE_SHUTDOWN,site_phase_shutdown_hook,st);
+    add_hook(PHASE_RUN,     site_phase_run_hook,     st);
     add_hook(PHASE_CHILDPERSIST,site_childpersist_clearkeys,st);
 
     return new_closure(&st->cl);