From efcfaeed63cff84f547c5ae9e5fd8ee02d0bae21 Mon Sep 17 00:00:00 2001 From: Pavel Reichl Date: Thu, 23 Oct 2014 15:05:05 +0100 Subject: [PATCH 44/46] RESPONDERS: refactor create_pipe_fd() Resolves: https://fedorahosted.org/sssd/ticket/2470 Reviewed-by: Jakub Hrozek (cherry picked from commit f3b9a5b3cf62124bdb5fc11ae2fe6a89ff921539) --- src/responder/common/responder.h | 2 +- src/responder/common/responder_common.c | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/responder/common/responder.h b/src/responder/common/responder.h index 8837e11425be36c67da038287de48c069ae335cd..cd2b3232c53e919c7d47170ccd1016a8604c9742 100644 --- a/src/responder/common/responder.h +++ b/src/responder/common/responder.h @@ -178,7 +178,7 @@ responder_get_domain(struct resp_ctx *rctx, const char *domain); errno_t responder_get_domain_by_id(struct resp_ctx *rctx, const char *id, struct sss_domain_info **_ret_dom); -int create_pipe_fd(const char *sock_name, int *fd, mode_t umaskval); +int create_pipe_fd(const char *sock_name, int *_fd, mode_t umaskval); /* responder_cmd.c */ int sss_cmd_empty_packet(struct sss_packet *packet); diff --git a/src/responder/common/responder_common.c b/src/responder/common/responder_common.c index 85aa04335b72c38fb7a128f04315e3c4189c5d56..9a13c95d63d93df96ffceb51f969eb562c3a6b08 100644 --- a/src/responder/common/responder_common.c +++ b/src/responder/common/responder_common.c @@ -584,24 +584,25 @@ static int sss_dp_init(struct resp_ctx *rctx, return EOK; } -int create_pipe_fd(const char *sock_name, int *fd, mode_t umaskval) +int create_pipe_fd(const char *sock_name, int *_fd, mode_t umaskval) { struct sockaddr_un addr; errno_t ret; + int fd; - *fd = socket(AF_UNIX, SOCK_STREAM, 0); - if (*fd == -1) { + fd = socket(AF_UNIX, SOCK_STREAM, 0); + if (fd == -1) { return EIO; } umask(umaskval); - ret = set_nonblocking(*fd); + ret = set_nonblocking(fd); if (ret != EOK) { goto done; } - ret = set_close_on_exec(*fd); + ret = set_close_on_exec(fd); if (ret != EOK) { goto done; } @@ -619,13 +620,13 @@ int create_pipe_fd(const char *sock_name, int *fd, mode_t umaskval) "Cannot remove old socket (errno=%d), bind might fail!\n", ret); } - if (bind(*fd, (struct sockaddr *)&addr, sizeof(addr)) == -1) { + if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) == -1) { DEBUG(SSSDBG_FATAL_FAILURE, "Unable to bind on socket '%s'\n", sock_name); ret = EIO; goto done; } - if (listen(*fd, 10) != 0) { + if (listen(fd, 10) == -1) { DEBUG(SSSDBG_FATAL_FAILURE, "Unable to listen on socket '%s'\n", sock_name); ret = EIO; @@ -638,8 +639,10 @@ done: /* we want default permissions on created files to be very strict, so set our umask to 0177 */ umask(0177); - if (ret != EOK) { - close(*fd); + if (ret == EOK) { + *_fd = fd; + } else { + close(fd); } return ret; } -- 1.9.3