Skip to content

Improve signal handling of test servers on Windows - #5218

Merged
mback2k merged 3 commits into
curl:masterfrom
mback2k:win-test-server-signal-handling
Apr 12, 2020
Merged

mback2k merged 3 commits into
curl:masterfrom
mback2k:win-test-server-signal-handling

Conversation

@mback2k

@mback2k mback2k commented Apr 11, 2020 •

Copy link
Copy Markdown
Member
  • tests/server: move all signal handling routines to util.[ch]:
    Avoid code duplication to prepare for portability enhancements.
  • tests/server: add CTRL event handler for Win32 consoles:
    Forward CTRL events as signals to existing signal event handler.
  • tests/server: add hidden window to gracefully handle WM_CLOSE:
    Forward Window events as signals to existing signal event handler.

Reasoing:

  • the Perl testsuite uses taskkill to gracefully (without /f) and forcefully (with /f) terminate test servers, but the graceful case is currently not handled by the test servers themselves, due to:

    SIGINT is not supported for any Win32 application. When a CTRL+C interrupt occurs, Win32 operating systems generate a new thread to specifically handle that interrupt. This can cause a single-thread application, such as one in UNIX, to become multithreaded and cause unexpected behavior.
    ...
    The SIGILL and SIGTERM signals are not generated under Windows. They are included for ANSI compatibility. Therefore, you can set signal handlers for these signals by using signal, and you can also explicitly generate these signals by calling raise.
    Source: https://docs.microsoft.com/de-de/cpp/c-runtime-library/reference/signal?view=vs-2019

  • therefore this PR implements Console and Window based event handler to receive the graceful WM_CLOSE message and CTRL_C_EVENT, CTRL_CLOSE_EVENT and CTRL_BREAK_EVENT events.

@mback2k mback2k added tests Windows Windows-specific labels Apr 11, 2020
@mback2k
mback2k requested a review from bagder April 11, 2020 21:58
@mback2k mback2k self-assigned this Apr 11, 2020
@mback2k

mback2k commented Apr 11, 2020 •

Copy link
Copy Markdown
Member Author

TODO before merge: include reasoning in PR description in unit.c

@mback2k
mback2k force-pushed the win-test-server-signal-handling branch 3 times, most recently from ca490a1 to 4f27246 Compare April 12, 2020 13:04
mback2k added 3 commits April 12, 2020 15:55
Avoid code duplication to prepare for portability enhancements.
Forward CTRL events as signals to existing signal event handler.
Forward Window events as signals to existing signal event handler.
@mback2k
mback2k force-pushed the win-test-server-signal-handling branch from 4f27246 to ac1e206 Compare April 12, 2020 16:38
@mback2k
mback2k merged commit ac1e206 into curl:master Apr 12, 2020
vszakats added a commit that referenced this pull request Aug 6, 2026
In year 2020 the Unixy signal handler received a `logmsg()` call to log
the signal number, but at the same time it already saved it to a global
variable and logged it on exit, meaning this extra `logmsg()` was
redundant. Because `logmsg()` is not signal-safe, this call was replaced
in 2025 with signal-safe logging, but without the signal number, while
also adding complexity, spent on trying to open the log file and handle
errors. All for nothing, because the signal number was logged all along.

This patch removes all this, and simplifies it to a single, signal-safe
`write()` to STDERR to say that the signal handler triggered. This is
also non-critical, but may help debugging.

Also: point the POSIX documentation to the 2004 revision, which has a
shorter list of safe functions. (was: 2018)

Follow-up to e95f509 #16852
Follow-up to 9869f6d #5218

Closes #22507
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Windows Windows-specific

Development

Successfully merging this pull request may close these issues.

2 participants