nghttpx: Store errno to a variable temporarly

This commit is contained in:
Tatsuhiro Tsujikawa 2014-08-13 22:13:08 +09:00
parent 21cbf417c8
commit 7b85f6c50d
3 changed files with 12 additions and 6 deletions

View File

@ -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);
}
}

View File

@ -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<char*>(&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;
}

View File

@ -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;
}