From 7877d13efb920de078604ba1b268b5066d0efb7b Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Thu, 28 Sep 2023 14:25:55 +0900 Subject: [PATCH] bin: windows: Restore Ctrl-C behavior on windows After supporting fleet management on Windows, Ctrl-C events won't be caught up. This commit re-enables for the behavior. Windows' ctrl event handlers stolen signals which are overlapped ones. So, we need to handle Ctrl-C events on the newly added event handler for Windows. In Windows, SIGINT and SIGBREAK are valid ctrl events on their terminal. This is why we only need to handle CTRL_C_EVENT and CTRL_BREAK_EVENT events on console handler. Signed-off-by: Hiroshi Hatake --- src/fluent-bit.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/fluent-bit.c b/src/fluent-bit.c index 51b814cfd02..141839dbbe9 100644 --- a/src/fluent-bit.c +++ b/src/fluent-bit.c @@ -550,7 +550,7 @@ static void flb_signal_exit(int signal) }; } -static void flb_signal_handler(int signal) +static void flb_signal_handler_status_line() { int len; char ts[32]; @@ -573,6 +573,12 @@ static void flb_signal_handler(int signal) /* write signal number */ write(STDERR_FILENO, ts, len); write(STDERR_FILENO, s, sizeof(s) - 1); +} + +static void flb_signal_handler(int signal) +{ + flb_signal_handler_status_line(); + switch (signal) { flb_print_signal(SIGINT); #ifndef FLB_SYSTEM_WINDOWS @@ -632,6 +638,15 @@ void flb_console_handler_set_ctx(flb_ctx_t *ctx, struct flb_cf *cf_opts) static BOOL WINAPI flb_console_handler(DWORD evType) { switch(evType) { + case 0 /* CTRL_C_EVENT_0 */: + flb_signal_handler_status_line(); + write (STDERR_FILENO, "SIGINT)\n", sizeof("SIGINT)\n")-1); + /* signal the main loop to execute reload even if CTRL_C event. + * This is necessary because all signal handlers in win32 + * are executed on their own thread. + */ + handler_signal = 2; + break; case 1 /* CTRL_BREAK_EVENT_1 */: if (flb_bin_restarting == FLB_RELOAD_IDLE) { flb_bin_restarting = FLB_RELOAD_IN_PROGRESS; @@ -1366,6 +1381,10 @@ int flb_main(int argc, char **argv) handler_signal = 0; flb_reload(ctx, cf_opts); } + else if (handler_signal == 2){ + handler_signal = 0; + break; + } #endif /* set the context again before checking the status again */