Skip to content

Commit

Permalink
nghttpx: Extract several chown() usages into 1 function
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuhiro-t committed Sep 22, 2015
1 parent 230b1f9 commit 03bb580
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/shrpx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ int resolve_hostname(Address *addr, const char *hostname, uint16_t port,
}
} // namespace

namespace {
int chown_to_running_user(const char *path) {
return chown(path, get_config()->uid, get_config()->gid);
}
} // namespace

namespace {
void save_pid() {
std::ofstream out(get_config()->pid_file.get(), std::ios::binary);
Expand All @@ -193,8 +199,7 @@ void save_pid() {
}

if (get_config()->uid != 0) {
if (chown(get_config()->pid_file.get(), get_config()->uid,
get_config()->gid) == -1) {
if (chown_to_running_user(get_config()->pid_file.get()) == -1) {
auto error = errno;
LOG(WARN) << "Changing owner of pid file " << get_config()->pid_file.get()
<< " failed: " << strerror(error);
Expand Down Expand Up @@ -2181,7 +2186,7 @@ int main(int argc, char **argv) {
mod_config()->http2_upstream_dump_request_header = f;

if (get_config()->uid != 0) {
if (chown(path, get_config()->uid, get_config()->gid) == -1) {
if (chown_to_running_user(path) == -1) {
auto error = errno;
LOG(WARN) << "Changing owner of http2 upstream request header file "
<< path << " failed: " << strerror(error);
Expand All @@ -2202,7 +2207,7 @@ int main(int argc, char **argv) {
mod_config()->http2_upstream_dump_response_header = f;

if (get_config()->uid != 0) {
if (chown(path, get_config()->uid, get_config()->gid) == -1) {
if (chown_to_running_user(path) == -1) {
auto error = errno;
LOG(WARN) << "Changing owner of http2 upstream response header file"
<< " " << path << " failed: " << strerror(error);
Expand Down

0 comments on commit 03bb580

Please sign in to comment.