From f2d142ef57f762960276933393270d5dc468e542 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Fri, 29 Dec 2017 19:17:57 +0100 Subject: [PATCH] Only reload .conf and services if any .conf file has changed This patch is an optimization. Now that we monitor for any .conf file changes (as soon as the event loop starts) we can skip automatic reload of all .conf files and services if no .conf file has changed. Unless the user issues an `initctl reload`, `init q`, or sends us SIGHUP. Signed-off-by: Joachim Nilsson --- src/conf.c | 8 ++++++++ src/conf.h | 1 + src/finit.c | 6 ++++-- src/sm.c | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/conf.c b/src/conf.c index 43ad27bb..9cb153fa 100644 --- a/src/conf.c +++ b/src/conf.c @@ -633,6 +633,14 @@ static int do_change(char *name, uint32_t mask) return 0; } +int conf_any_change(void) +{ + if (TAILQ_EMPTY(&conf_change_list)) + return 0; + + return 1; +} + int conf_changed(char *file) { char *ptr; diff --git a/src/conf.h b/src/conf.h index 70144606..64e98564 100644 --- a/src/conf.h +++ b/src/conf.h @@ -33,6 +33,7 @@ char *rlim2str(int rlim); int conf_init (void); void conf_reload (void); +int conf_any_change (void); int conf_changed (char *file); int conf_monitor (uev_ctx_t *ctx); diff --git a/src/finit.c b/src/finit.c index aac922a1..4a5d986a 100644 --- a/src/finit.c +++ b/src/finit.c @@ -291,13 +291,15 @@ static void finalize(void) if (runparts && fisdir(runparts)) { _d("Running startup scripts in %s ...", runparts); run_parts(runparts, NULL); - service_reload_dynamic(); + if (conf_any_change()) + service_reload_dynamic(); } /* Convenient SysV compat for when you just don't care ... */ if (!access(FINIT_RC_LOCAL, X_OK)) { run_interactive(FINIT_RC_LOCAL, "Calling %s", FINIT_RC_LOCAL); - service_reload_dynamic(); + if (conf_any_change()) + service_reload_dynamic(); } /* Hooks that should run at the very end */ diff --git a/src/sm.c b/src/sm.c index 2d3e6fc8..c53c6170 100644 --- a/src/sm.c +++ b/src/sm.c @@ -143,7 +143,7 @@ restart: erase("/etc/nologin"); /* Make sure to (re)load all *.conf in /etc/finit.d/ */ - if (runlevel != 0 && runlevel != 6) + if (conf_any_change()) conf_reload(); /* Reset once flag of runtasks */