From 06f10b2a0ebb26f2460cd445f8040e9205de7500 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Tue, 21 Oct 2014 12:29:55 +0200 Subject: UTIL: Remove code duplication of struct io MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We had struct io and the associated destructor copied twice in the code already and need it again in the SELinux provider. Instead of adding another copy, move the code to a shared subtree under util/ Reviewed-by: Michal Židek --- src/util/child_common.c | 29 +++++++++++++++++++++++++++++ src/util/child_common.h | 7 +++++++ 2 files changed, 36 insertions(+) (limited to 'src/util') diff --git a/src/util/child_common.c b/src/util/child_common.c index 81bbab70..e4a885b6 100644 --- a/src/util/child_common.c +++ b/src/util/child_common.c @@ -772,3 +772,32 @@ void child_cleanup(int readfd, int writefd) } } } + +int child_io_destructor(void *ptr) +{ + int ret; + struct child_io_fds *io = talloc_get_type(ptr, struct child_io_fds); + if (io == NULL) return EOK; + + if (io->write_to_child_fd != -1) { + ret = close(io->write_to_child_fd); + io->write_to_child_fd = -1; + if (ret != EOK) { + ret = errno; + DEBUG(SSSDBG_CRIT_FAILURE, + "close failed [%d][%s].\n", ret, strerror(ret)); + } + } + + if (io->read_from_child_fd != -1) { + ret = close(io->read_from_child_fd); + io->read_from_child_fd = -1; + if (ret != EOK) { + ret = errno; + DEBUG(SSSDBG_CRIT_FAILURE, + "close failed [%d][%s].\n", ret, strerror(ret)); + } + } + + return EOK; +} diff --git a/src/util/child_common.h b/src/util/child_common.h index 95865bb5..261da7f9 100644 --- a/src/util/child_common.h +++ b/src/util/child_common.h @@ -45,6 +45,11 @@ struct io_buffer { size_t size; }; +struct child_io_fds { + int read_from_child_fd; + int write_to_child_fd; +}; + /* COMMON SIGCHLD HANDLING */ typedef void (*sss_child_fn_t)(int pid, int wait_status, void *pvt); @@ -113,4 +118,6 @@ errno_t exec_child(TALLOC_CTX *mem_ctx, void child_cleanup(int readfd, int writefd); +int child_io_destructor(void *ptr); + #endif /* __CHILD_COMMON_H__ */ -- cgit