Skip to content

servers: drop complex and redundant signal handler output - #22507

Closed
vszakats wants to merge 4 commits into
curl:masterfrom
vszakats:signal-drop-pointless-logging-in-signal-handler
Closed

vszakats wants to merge 4 commits into
curl:masterfrom
vszakats:signal-drop-pointless-logging-in-signal-handler

Conversation

@vszakats

@vszakats vszakats commented Aug 6, 2026 •

Copy link
Copy Markdown
Member

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


  • drop the write() call too? it needs warning suppression. Or shorten
    the suppression to (void)!write() again, maybe for a single line it's better.
    → [FUTURE PR maybe]

@github-actions github-actions Bot added the tests label Aug 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR simplifies the test-server POSIX signal handler output by removing redundant/complex signal-safe logging attempts (including opening the server log file) and replacing them with a single signal-safe write() to STDERR, while also updating the referenced POSIX async-signal-safe function list link to the 2004 revision.

Changes:

  • Remove the signal-handler logic that attempted to open/write/close the server log file (and related error-path writes).
  • Replace it with a single write(STDERR_FILENO, ...) message indicating the handler triggered.
  • Update the POSIX documentation link for async-signal-safe functions to the 2004 revision.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/server/util.c Resolved
Comment thread tests/server/util.c Resolved
@vszakats vszakats closed this in 3aae64e Aug 6, 2026
@vszakats
vszakats deleted the signal-drop-pointless-logging-in-signal-handler branch August 6, 2026 10:49
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants