Commit 21cbf417 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

nghttpx: Use SOCK_NONBLOCK and SOCK_CLOEXEC flag in socketpair to avoid race

parent ca680c16
......@@ -193,15 +193,13 @@ int Http2Session::init_notification()
{
int rv;
int sockpair[2];
rv = socketpair(AF_UNIX, SOCK_STREAM, 0, sockpair);
rv = socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0,
sockpair);
if(rv == -1) {
SSLOG(FATAL, this) << "socketpair() failed: errno=" << errno;
return -1;
}
for(int i = 0; i < 2; ++i) {
evutil_make_socket_nonblocking(sockpair[i]);
evutil_make_socket_closeonexec(sockpair[i]);
}
wrbev_ = bufferevent_socket_new(evbase_, sockpair[0],
BEV_OPT_CLOSE_ON_FREE|
BEV_OPT_DEFER_CALLBACKS);
......
......@@ -103,17 +103,13 @@ void ListenHandler::create_worker_thread(size_t num)
for(size_t i = 0; i < num; ++i) {
int rv;
auto info = util::make_unique<WorkerInfo>();
rv = socketpair(AF_UNIX, SOCK_STREAM, 0, info->sv);
rv = socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0,
info->sv);
if(rv == -1) {
LLOG(ERROR, this) << "socketpair() failed: errno=" << errno;
continue;
}
for(int j = 0; j < 2; ++j) {
evutil_make_socket_nonblocking(info->sv[j]);
evutil_make_socket_closeonexec(info->sv[j]);
}
info->sv_ssl_ctx = sv_ssl_ctx_;
info->cl_ssl_ctx = cl_ssl_ctx_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment