From 7b85f6c50d7b8b1392c16bb4e8a6ea629f842fa6 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 13 Aug 2014 22:13:08 +0900 Subject: [PATCH] nghttpx: Store errno to a variable temporarly --- src/shrpx.cc | 9 ++++++--- src/shrpx_http2_session.cc | 6 ++++-- src/shrpx_listen_handler.cc | 3 ++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/shrpx.cc b/src/shrpx.cc index c6040ca4..e5fa1cd7 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -287,11 +287,13 @@ void drop_privileges() { if(getuid() == 0 && get_config()->uid != 0) { if(setgid(get_config()->gid) != 0) { - LOG(FATAL) << "Could not change gid: " << strerror(errno); + auto error = errno; + LOG(FATAL) << "Could not change gid: " << strerror(error); exit(EXIT_FAILURE); } if(setuid(get_config()->uid) != 0) { - LOG(FATAL) << "Could not change uid: " << strerror(errno); + auto error = errno; + LOG(FATAL) << "Could not change uid: " << strerror(error); exit(EXIT_FAILURE); } if(setuid(0) != -1) { @@ -527,7 +529,8 @@ int event_loop() auto listener_handler = new ListenHandler(evbase, sv_ssl_ctx, cl_ssl_ctx); if(get_config()->daemon) { if(daemon(0, 0) == -1) { - LOG(FATAL) << "Failed to daemonize: " << strerror(errno); + auto error = errno; + LOG(FATAL) << "Failed to daemonize: " << strerror(error); exit(EXIT_FAILURE); } } diff --git a/src/shrpx_http2_session.cc b/src/shrpx_http2_session.cc index 81238769..ce06ccb2 100644 --- a/src/shrpx_http2_session.cc +++ b/src/shrpx_http2_session.cc @@ -196,7 +196,8 @@ int Http2Session::init_notification() rv = socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0, sockpair); if(rv == -1) { - SSLOG(FATAL, this) << "socketpair() failed: errno=" << errno; + auto error = errno; + SSLOG(FATAL, this) << "socketpair() failed: errno=" << error; return -1; } @@ -277,8 +278,9 @@ void eventcb(bufferevent *bev, short events, void *ptr) int val = 1; if(setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast(&val), sizeof(val)) == -1) { + auto error = errno; SSLOG(WARNING, http2session) - << "Setting option TCP_NODELAY failed: errno=" << errno; + << "Setting option TCP_NODELAY failed: errno=" << error; } return; } diff --git a/src/shrpx_listen_handler.cc b/src/shrpx_listen_handler.cc index 21eef4d3..19c4a6f4 100644 --- a/src/shrpx_listen_handler.cc +++ b/src/shrpx_listen_handler.cc @@ -106,7 +106,8 @@ void ListenHandler::create_worker_thread(size_t num) rv = socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0, info->sv); if(rv == -1) { - LLOG(ERROR, this) << "socketpair() failed: errno=" << errno; + auto error = errno; + LLOG(ERROR, this) << "socketpair() failed: errno=" << error; continue; }