From 03bb58006b03ee1567e18e3f2e4e52ceeaa17502 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 22 Sep 2015 18:32:40 +0900 Subject: [PATCH] nghttpx: Extract several chown() usages into 1 function --- src/shrpx.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/shrpx.cc b/src/shrpx.cc index 1f819d89..37980eca 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -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); @@ -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); @@ -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); @@ -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);