From dded3c9111031dcf7e8c8853983f6b4d9df660ad Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Tue, 31 Oct 2023 16:03:22 +0900 Subject: [PATCH] reload: bin: Handle hot-reloading is aborted case In our hot-reloading context handling, there is a possibility not to able to handle hot-reloading correctly. For this case, we should treat as error and halt the process. Signed-off-by: Hiroshi Hatake --- include/fluent-bit/flb_reload.h | 1 + src/flb_reload.c | 17 ++++++++++++----- src/fluent-bit.c | 24 ++++++++++++++++++------ 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/include/fluent-bit/flb_reload.h b/include/fluent-bit/flb_reload.h index 7066505a21c..d2da3575df1 100644 --- a/include/fluent-bit/flb_reload.h +++ b/include/fluent-bit/flb_reload.h @@ -27,6 +27,7 @@ #define FLB_RELOAD_IDLE 0 #define FLB_RELOAD_IN_PROGRESS 1 +#define FLB_RELOAD_ABORTED 2 int flb_reload_property_check_all(struct flb_config *config); int flb_reload_reconstruct_cf(struct flb_cf *src_cf, struct flb_cf *dest_cf); diff --git a/src/flb_reload.c b/src/flb_reload.c index ea43a3554d4..796ed3e06c9 100644 --- a/src/flb_reload.c +++ b/src/flb_reload.c @@ -512,12 +512,19 @@ int flb_reload(flb_ctx_t *ctx, struct flb_cf *cf_opts) ret = flb_start(new_ctx); - /* Store the new value of hot reloading times into the new context */ - if (ret == 0) { - new_config->hot_reloaded_count = reloaded_count; - flb_debug("[reload] hot reloaded %d time(s)", reloaded_count); - new_config->hot_reloading = FLB_FALSE; + if (ret != 0) { + flb_stop(new_ctx); + flb_destroy(new_ctx); + + flb_error("[reload] loaded configuration contains error(s). Reloading is aborted"); + + return -1; } + /* Store the new value of hot reloading times into the new context */ + new_config->hot_reloaded_count = reloaded_count; + flb_debug("[reload] hot reloaded %d time(s)", reloaded_count); + new_config->hot_reloading = FLB_FALSE; + return 0; } diff --git a/src/fluent-bit.c b/src/fluent-bit.c index 8ecd517f859..346c041c79f 100644 --- a/src/fluent-bit.c +++ b/src/fluent-bit.c @@ -1394,16 +1394,23 @@ int flb_main(int argc, char **argv) #endif if (flb_bin_restarting == FLB_RELOAD_IN_PROGRESS) { /* reload by using same config files/path */ - flb_reload(ctx, cf_opts); - ctx = flb_context_get(); - flb_bin_restarting = FLB_RELOAD_IDLE; + ret = flb_reload(ctx, cf_opts); + if (ret == 0) { + ctx = flb_context_get(); + flb_bin_restarting = FLB_RELOAD_IDLE; + } + else { + flb_bin_restarting = FLB_RELOAD_ABORTED; + } } } if (exit_signal) { flb_signal_exit(exit_signal); } - ret = ctx->config->exit_status_code; + if (flb_bin_restarting != FLB_RELOAD_ABORTED) { + ret = ctx->config->exit_status_code; + } cf_opts = flb_cf_context_get(); @@ -1425,8 +1432,13 @@ int flb_main(int argc, char **argv) } #endif - flb_stop(ctx); - flb_destroy(ctx); + if (flb_bin_restarting == FLB_RELOAD_ABORTED) { + fprintf(stderr, "reloading is aborted and exit\n"); + } + else { + flb_stop(ctx); + flb_destroy(ctx); + } return ret; }