Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bin: windows: Restore Ctrl-C behavior on windows #7986

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/fluent-bit.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,15 +550,14 @@ static void flb_signal_exit(int signal)
};
}

static void flb_signal_handler(int signal)
static void flb_signal_handler_status_line(struct flb_cf *cf_opts)
{
int len;
char ts[32];
char s[] = "[engine] caught signal (";
time_t now;
struct tm *cur;
flb_ctx_t *ctx = flb_context_get();
struct flb_cf *cf_opts = flb_cf_context_get();

now = time(NULL);
cur = localtime(&now);
Expand All @@ -573,6 +572,13 @@ 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)
{
struct flb_cf *cf_opts = flb_cf_context_get();
flb_signal_handler_status_line(cf_opts);

switch (signal) {
flb_print_signal(SIGINT);
#ifndef FLB_SYSTEM_WINDOWS
Expand Down Expand Up @@ -631,7 +637,19 @@ void flb_console_handler_set_ctx(flb_ctx_t *ctx, struct flb_cf *cf_opts)

static BOOL WINAPI flb_console_handler(DWORD evType)
{
struct flb_cf *cf_opts;

switch(evType) {
case 0 /* CTRL_C_EVENT_0 */:
cf_opts = flb_cf_context_get();
flb_signal_handler_status_line(cf_opts);
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 +1384,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
Loading