dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0044-RESPONDERS-refactor-create_pipe_fd.patch

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