Repository navigation
Conversation
jay
reviewed
Apr 22, 2020
Use raise to trigger signal handler instead of calling it directly and causing potential unexpected control flow. Part of curl#5260
This commit adds a global exit event to the test servers that Windows-specific wait routines can use to get triggered if the program was signaled to be terminated, eg. select_ws in sockfilt.c The exit event will be managed by the signal handling code and is set to not reset automatically to support multiple wait routines. Closes curl#5260
This makes sure that select_ws behaves similar to real select which stops waiting on a signal handler being triggered. This makes it possible to gracefully stop sockfilt.exe on Windows with taskkill /IM sockfilt.exe (without /F force flag). Part of curl#5260
mback2k
marked this pull request as ready for review
April 26, 2020 17:20
jay
approved these changes
Apr 26, 2020
jay
left a comment
Member
There was a problem hiding this comment.
I think it's fine, if I was going to nitpick I wouldn't call the event got_exit_event, that implies a boolean that it "got" the exit event. How about exit_event or exit_event_hnd.
Member
Author
👍
if you compare it to the existing boolean, yes, but to me it is the event that tells us that it got_exit_event/signal. I don't mind changing it during the merge, though. |
mback2k
added a commit
that referenced
this pull request
May 2, 2020
Use raise to trigger signal handler instead of calling it directly and causing potential unexpected control flow. Reviewed-by: Jay Satiro Part of #5260
mback2k
added a commit
that referenced
this pull request
May 2, 2020
Reviewed-by: Jay Satiro Part of #5260
mback2k
added a commit
that referenced
this pull request
May 2, 2020
This makes sure that select_ws behaves similar to real select which stops waiting on a signal handler being triggered. This makes it possible to gracefully stop sockfilt.exe on Windows with taskkill /IM sockfilt.exe (without /F force flag). Reviewed-by: Jay Satiro Part of #5260
Member
Author
|
@jay Thanks for the review! |
5 tasks done
vszakats
added a commit
that referenced
this pull request
Aug 6, 2026
…dd exit message On Windows, the init code calls `SetConsoleCtrlHandler()`, and before this patch also set handlers for all Unixy signals. Of these, `SIGBREAK` (used on Windows-only), `SIGINT`, `SIGABRT` and `SIGTERM` were also setting up a `SetConsoleCtrlHandler()`, in addition to the call made directly. (The rest, `SIGHUP`, `SIGPIPE`, `SIGALRM` are either missing the macros, or ignored by `signal()` on Windows.) As per WINE sources, `SetConsolCtrlHandler(<h>, TRUE)` calls are additive, which means the test server set up two console ctrl handlers. Then the ctrl handler set directly (`ctrl_event_handler()`), was triggering the other signal handler via `raise()`, for the 'initiate exit' logic, which in turn triggered exiting a wait within `select_ws()` and other loops. The Windows window handler also made use of the `SIGTERM` event to initiate exit via `raise()` and the second signal handler. To simplify, de-duplicate the ctrl handlers by dropping `signal()` calls and keeping the direct Win32 call with `ctrl_event_handler()` doing all the signal handling on Windows. Break out the 'initiate exit' logic into a function and call it from both Unix and Windows signal/ctrl/window handlers. Also drop calling `raise()` on exit, because it's a no-op without a `signal()` pair. Also: - drop logging the actual ctrl type number, replace with just logging whether we handled the event, in `ctrl_event_handler()`. To avoid using non-signal-safe functions (e.g. `fprintf()`) from the handler. - also replace `logmsg()` with `WriteFile()` to prevent regressions. Ref: #22045 - replace `logmsg()` with `WriteFile()` in `main_window_proc()`. - fix to forward ctrl handling to the OS in the rare case of failed `exit_event` initialization on startup. To swap a possible hang (within `WaitForMultipleObjectsEx()`) with an ungraceful shutdown. - add support for an 'exit message' string, set by signal/ctrl handlers, and log it on app exit. To avoid the need to deal with logging within the handlers, yet have a static trace message about the event. Complementing the already logged signal number. - drop stderr trace message from `exit_signal_handler()` in favor of an exit message. runtests triggers it frequantly, which added much noise to stderr. As a bonus, this also allows dropping the compiler warning suppression. Reported-by: Stefan Eissing Bug: #22487 (comment) Follow-up to 3aae64e #22507 Refs: https://learn.microsoft.com/windows/console/setconsolectrlhandler https://learn.microsoft.com/windows/console/registering-a-control-handler-function https://learn.microsoft.com/cpp/c-runtime-library/reference/raise https://learn.microsoft.com/cpp/c-runtime-library/reference/signal https://gitlab.winehq.org/wine/wine/-/blob/wine-11.14/dlls/kernelbase/console.c#L1517-1526 https://github.com/huangqinjin/ucrt/blob/d6e817a4cc90f6f1fe54f8a0aa4af4fff0bb647d/misc/signal.cpp#L286-L348 Follow-up to fe28fcf 7dc8a98 0e05877 #5260 Closes #22487
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
tests/server/util.c: use raise instead of calling signal handler
Use raise to trigger signal handler instead of calling it
directly and causing potential unexpected control flow.
tests/server/util.c: fix thread handle not being closed
tests/server/util.[ch]: add exit event to stop waiting on Windows
This commit adds a global exit event to the test servers that
Windows-specific wait routines can use to get triggered if the
program was signaled to be terminated, eg. select_ws in sockfilt.c
The exit event will be managed by the signal handling code and is
set to not reset automatically to support multiple wait routines.
sockfilt: make select_ws stop waiting on exit signal event
This makes sure that select_ws behaves similar to real select
which stops waiting on a signal handler being triggered.
This makes it possible to gracefully stop sockfilt.exe on
Windows with taskkill /IM sockfilt.exe (without /F force flag).