diff options
author | Nick Mathewson <nickm@torproject.org> | 2020-05-21 10:08:48 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2020-05-21 10:08:48 -0400 |
commit | 43f4324e29855bced51cb9c8f126bfb35e93fb2c (patch) | |
tree | 8a0d767841e55b13596b80a17bf662de11f999d6 | |
parent | 3121e5c103473255002761ac9aed6874b10aa78d (diff) | |
parent | c4fb3bfed5c4e3e2e263e23e4a46ad81ddbc5936 (diff) | |
download | tor-43f4324e29855bced51cb9c8f126bfb35e93fb2c.tar.gz tor-43f4324e29855bced51cb9c8f126bfb35e93fb2c.zip |
Merge remote-tracking branch 'tor-github/pr/1899/head'
-rw-r--r-- | changes/ticket34211 | 3 | ||||
-rw-r--r-- | src/app/main/main.c | 20 |
2 files changed, 23 insertions, 0 deletions
diff --git a/changes/ticket34211 b/changes/ticket34211 new file mode 100644 index 0000000000..b454873abf --- /dev/null +++ b/changes/ticket34211 @@ -0,0 +1,3 @@ + o Minor features (windows): + - Add support for console control signals like Ctrl+C in Windows + Closes ticket 34211. Patch from Damon Harris (TheDcoder). 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. */ |