1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
4 #include "cmConfigure.h" // IWYU pragma: keep
8 #if defined(CMAKE_USE_SYSTEM_LIBUV) && !defined(_WIN32) && \
9 UV_VERSION_MAJOR == 1 && UV_VERSION_MINOR < 19
10 # define CMAKE_UV_SIGNAL_HACK
11 # include "cmUVHandlePtr.h"
13 libuv does not use SA_RESTART on its signal handler, but C++ streams
14 depend on it for reliable i/o operations. This RAII helper convinces
15 libuv to install its handler, and then revises the handler to add the
16 SA_RESTART flag. We use a distinct uv loop that never runs to avoid
17 ever really getting a callback. libuv may fill the hack loop's signal
18 pipe and then stop writing, but that won't break any real loops.
20 class cmUVSignalHackRAII
23 cm::uv_signal_ptr HackSignal;
24 static void HackCB(uv_signal_t*, int) {}
29 uv_loop_init(&this->HackLoop);
30 this->HackSignal.init(this->HackLoop);
31 this->HackSignal.start(HackCB, SIGCHLD);
32 struct sigaction hack_sa;
33 sigaction(SIGCHLD, nullptr, &hack_sa);
34 if (!(hack_sa.sa_flags & SA_RESTART)) {
35 hack_sa.sa_flags |= SA_RESTART;
36 sigaction(SIGCHLD, &hack_sa, nullptr);
41 this->HackSignal.stop();
42 uv_loop_close(&this->HackLoop);