Skip to content

Commit

Permalink
bin: windows: Restore Ctrl-C behavior on windows
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
cosmo0920 authored and edsiper committed Oct 2, 2023
1 parent cfca7ca commit 7877d13
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/fluent-bit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit 7877d13

Please sign in to comment.