nghttpx: Chown UNIX domain socket to user specified as --user

This commit is contained in:
Tatsuhiro Tsujikawa 2015-09-22 18:34:03 +09:00
parent 03bb58006b
commit 87a38bdf8d
1 changed files with 10 additions and 0 deletions

View File

@ -704,6 +704,16 @@ int event_loop() {
} }
ssv.server_fd = fd; ssv.server_fd = fd;
if (get_config()->uid != 0) {
// fd is not associated to inode, so we cannot use fchown(2)
// here. https://lkml.org/lkml/2004/11/1/84
if (chown_to_running_user(get_config()->host.get()) == -1) {
auto error = errno;
LOG(WARN) << "Changing owner of UNIX domain socket "
<< get_config()->host.get() << " failed: " << strerror(error);
}
}
} else { } else {
close_env_fd({ENV_UNIX_FD}); close_env_fd({ENV_UNIX_FD});
auto fd6 = create_tcp_server_socket(AF_INET6); auto fd6 = create_tcp_server_socket(AF_INET6);