From e1d4ac426c817377cbe01287b6ada824146d26c9 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Sat, 29 Nov 2014 16:49:08 +0100 Subject: [PATCH] Move chown to fpm_unix_set_socket_premissions() For consistency, with fpm_unix_resolve_socket_premissions. Compute + Use in the same source file. To make easier future enhancement. Also check chdir output to fix a build warning. --- sapi/fpm/fpm/fpm_sockets.c | 9 +++------ sapi/fpm/fpm/fpm_unix.c | 16 +++++++++++++++- sapi/fpm/fpm/fpm_unix.h | 1 + 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/sapi/fpm/fpm/fpm_sockets.c b/sapi/fpm/fpm/fpm_sockets.c index 0286f0eee8..065f63e762 100644 --- a/sapi/fpm/fpm/fpm_sockets.c +++ b/sapi/fpm/fpm/fpm_sockets.c @@ -201,12 +201,9 @@ static int fpm_sockets_new_listening_socket(struct fpm_worker_pool_s *wp, struct umask(saved_umask); - if (wp->socket_uid != -1 || wp->socket_gid != -1) { - if (0 > chown(path, wp->socket_uid, wp->socket_gid)) { - zlog(ZLOG_SYSERROR, "failed to chown() the socket '%s'", wp->config->listen_address); - close(sock); - return -1; - } + if (0 > fpm_unix_set_socket_premissions(wp, path)) { + close(sock); + return -1; } } diff --git a/sapi/fpm/fpm/fpm_unix.c b/sapi/fpm/fpm/fpm_unix.c index 32448fc4d5..57707d8f8a 100644 --- a/sapi/fpm/fpm/fpm_unix.c +++ b/sapi/fpm/fpm/fpm_unix.c @@ -76,6 +76,18 @@ int fpm_unix_resolve_socket_premissions(struct fpm_worker_pool_s *wp) /* {{{ */ } /* }}} */ +int fpm_unix_set_socket_premissions(struct fpm_worker_pool_s *wp, const char *path) /* {{{ */ +{ + if (wp->socket_uid != -1 || wp->socket_gid != -1) { + if (0 > chown(path, wp->socket_uid, wp->socket_gid)) { + zlog(ZLOG_SYSERROR, "failed to chown() the socket '%s'", wp->config->listen_address); + return -1; + } + } + return 0; +} +/* }}} */ + static int fpm_unix_conf_wp(struct fpm_worker_pool_s *wp) /* {{{ */ { struct passwd *pwd; @@ -187,7 +199,9 @@ int fpm_unix_init_child(struct fpm_worker_pool_s *wp) /* {{{ */ return -1; } } else if (made_chroot) { - chdir("/"); + if (0 > chdir("/")) { + zlog(ZLOG_WARNING, "[pool %s] failed to chdir(/)", wp->config->name); + } } if (is_root) { diff --git a/sapi/fpm/fpm/fpm_unix.h b/sapi/fpm/fpm/fpm_unix.h index 3451db126b..b2995ff3e0 100644 --- a/sapi/fpm/fpm/fpm_unix.h +++ b/sapi/fpm/fpm/fpm_unix.h @@ -8,6 +8,7 @@ #include "fpm_worker_pool.h" int fpm_unix_resolve_socket_premissions(struct fpm_worker_pool_s *wp); +int fpm_unix_set_socket_premissions(struct fpm_worker_pool_s *wp, const char *path); int fpm_unix_init_child(struct fpm_worker_pool_s *wp); int fpm_unix_init_main(); -- 2.40.0