diff options
author | Damon Harris <TheDcoder@protonmail.com> | 2020-05-13 15:05:54 +0530 |
---|---|---|
committer | Damon Harris <TheDcoder@protonmail.com> | 2020-05-20 23:28:39 +0530 |
commit | c4fb3bfed5c4e3e2e263e23e4a46ad81ddbc5936 (patch) | |
tree | aaa42755c4b7be1237df46d695832585288d3143 /src/app/main | |
parent | b7a165228f02e693b3e777b4c815214bb6e05691 (diff) | |
download | tor-c4fb3bfed5c4e3e2e263e23e4a46ad81ddbc5936.tar.gz tor-c4fb3bfed5c4e3e2e263e23e4a46ad81ddbc5936.zip |
Add support for console control signals in Windows
Diffstat (limited to 'src/app/main')
-rw-r--r-- | src/app/main/main.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/app/main/main.c b/src/app/main/main.c index 689bc526ab..c2300f7a38 100644 --- a/src/app/main/main.c +++ b/src/app/main/main.c @@ -294,6 +294,19 @@ process_signal(int sig) } } +#ifdef _WIN32 +/** Activate SIGINT on reciving a control signal in console */ +static BOOL WINAPI +process_win32_console_ctrl(DWORD ctrl_type) +{ + /* Ignore type of the ctrl signal */ + (void) ctrl_type; + + activate_signal(SIGINT); + return TRUE; +} +#endif + /** * Write current memory usage information to the log. */ @@ -496,6 +509,13 @@ handle_signals(void) &signal_handlers[i].signal_value); } } + +#ifdef _WIN32 + /* Windows lacks traditional POSIX signals but WinAPI provides a function + * to handle control signals like Ctrl+C in the console, we can use this to + * simulate the SIGINT signal */ + if (enabled) SetConsoleCtrlHandler(process_win32_console_ctrl, TRUE); +#endif } /* Cause the signal handler for signal_num to be called in the event loop. */ |