Skip to content

Commit

Permalink
Only set signals to Ignore on non-Linux of no signal-handler is in pl…
Browse files Browse the repository at this point in the history
…ace. Also set the SA_RESTART flag to avoid operations returning EINTR.
  • Loading branch information
Markus Plichta committed Apr 6, 2024
1 parent 89b43ba commit 06914cb
Showing 1 changed file with 45 additions and 5 deletions.
50 changes: 45 additions & 5 deletions src/dpp/sslclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,51 @@ ssl_client::ssl_client(const std::string &_hostname, const std::string &_port, b
keepalive(reuse)
{
#ifndef WIN32
signal(SIGALRM, SIG_IGN);
signal(SIGHUP, SIG_IGN);
signal(SIGPIPE, SIG_IGN);
signal(SIGCHLD, SIG_IGN);
signal(SIGXFSZ, SIG_IGN);
struct sigaction sa;
sigaction(SIGALRM, nullptr, &sa);
if (sa.sa_flags == 0 && sa.sa_handler == nullptr)
{
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_IGN;
sa.sa_flags = SA_RESTART;
sigaction(SIGALRM, &sa, nullptr);
}

sigaction(SIGHUP, nullptr, &sa);
if (sa.sa_flags == 0 && sa.sa_handler == nullptr)
{
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_IGN;
sa.sa_flags = SA_RESTART;
sigaction(SIGHUP, &sa, nullptr);
}

sigaction(SIGPIPE, nullptr, &sa);
if (sa.sa_flags == 0 && sa.sa_handler == nullptr)
{
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_IGN;
sa.sa_flags = SA_RESTART;
sigaction(SIGPIPE, &sa, nullptr);
}

sigaction(SIGCHLD, nullptr, &sa);
if (sa.sa_flags == 0 && sa.sa_handler == nullptr)
{
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_IGN;
sa.sa_flags = SA_RESTART;
sigaction(SIGCHLD, &sa, nullptr);
}

sigaction(SIGXFSZ, nullptr, &sa);
if (sa.sa_flags == 0 && sa.sa_handler == nullptr)
{
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_IGN;
sa.sa_flags = SA_RESTART;
sigaction(SIGXFSZ, &sa, nullptr);
}
#else
// Set up winsock.
WSADATA wsadata;
Expand Down

0 comments on commit 06914cb

Please sign in to comment.