summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2016-05-19 18:12:17 +0200
committerJakub Hrozek <jhrozek@redhat.com>2016-05-31 13:07:15 +0200
commit45e11be651dbd3855a35de4abd2922e5b9d4b963 (patch)
treea98a1fe79bd675a7bd4aaa824205a20ea9fd71f8 /src/util
parent518f5b83fd546e3188da01e4743ddb27a574e08f (diff)
downloadsssd-45e11be651dbd3855a35de4abd2922e5b9d4b963.tar.gz
sssd-45e11be651dbd3855a35de4abd2922e5b9d4b963.tar.xz
sssd-45e11be651dbd3855a35de4abd2922e5b9d4b963.zip
Do not leak fds in case of failures setting up a child process
Resolves: https://fedorahosted.org/sssd/ticket/3006 The handling of open pipes in failure cases was suboptimal. Moreover, the faulty logic was copied all over the place. This patch introduces helper macros to: - initialize the pipe endpoints to -1 - close an open pipe fd and set it to -1 afterwards - close both ends unless already closed These macros are used in the child handling code. The patch also uses child_io_destructor in the p11_child code for safer fd handling. Reviewed-by: Petr Cech <pcech@redhat.com>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/util.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/util/util.h b/src/util/util.h
index 11054c106..b4ab14e71 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -84,6 +84,20 @@
#define FLAGS_INTERACTIVE 0x0002
#define FLAGS_PID_FILE 0x0004
+#define PIPE_INIT { -1, -1 }
+
+#define PIPE_FD_CLOSE(fd) do { \
+ if (fd != -1) { \
+ close(fd); \
+ fd = -1; \
+ } \
+} while(0);
+
+#define PIPE_CLOSE(p) do { \
+ PIPE_FD_CLOSE(p[0]); \
+ PIPE_FD_CLOSE(p[1]); \
+} while(0);
+
#ifndef talloc_zfree
#define talloc_zfree(ptr) do { talloc_free(discard_const(ptr)); ptr = NULL; } while(0)
#endif