From 8481ecfd2b2f820bcd4c82d300c1f5fda48eb9ed Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Mon, 14 May 2018 19:15:12 +0200 Subject: make: run the build rule before starting httpd for runserver rule --- src/blogc-make/httpd.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/blogc-make') diff --git a/src/blogc-make/httpd.c b/src/blogc-make/httpd.c index 7d67b57..a302eb4 100644 --- a/src/blogc-make/httpd.c +++ b/src/blogc-make/httpd.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "../common/utils.h" #include "ctx.h" #include "exec.h" @@ -47,6 +48,17 @@ int bm_httpd_run(bm_ctx_t **ctx, bm_rule_exec_func_t rule_exec, bc_slist_t *outputs, bc_trie_t *args) { + // this is here to avoid that the httpd starts running in the middle of the + // first build, as the reloader and the httpd are started in parallel. + // we run the task synchronously for the first time, and start the httpd + // thread afterwards. + bool wait_before_reloader = false; + if (0 != rule_exec(*ctx, outputs, args)) { + fprintf(stderr, "blogc-make: warning: failed to rebuild website. " + "retrying in 5 seconds ...\n\n"); + wait_before_reloader = true; + } + int err; pthread_attr_t attr; @@ -77,5 +89,8 @@ bm_httpd_run(bm_ctx_t **ctx, bm_rule_exec_func_t rule_exec, bc_slist_t *outputs, } // run the reloader + if (wait_before_reloader) { + sleep(5); + } return bm_reloader_run(ctx, rule_exec, outputs, args); } -- cgit v1.2.3-18-g5258