diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2014-10-21 12:29:55 +0200 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2014-11-05 19:55:09 +0100 |
commit | 06f10b2a0ebb26f2460cd445f8040e9205de7500 (patch) | |
tree | 06f5b2bda73bc2042abe72498924a709f5aa8159 /src/util/child_common.c | |
parent | 936940720b1b0e701a2317abc4c2d05a78338f33 (diff) | |
download | sssd-06f10b2a0ebb26f2460cd445f8040e9205de7500.tar.gz sssd-06f10b2a0ebb26f2460cd445f8040e9205de7500.tar.xz sssd-06f10b2a0ebb26f2460cd445f8040e9205de7500.zip |
UTIL: Remove code duplication of struct io
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 <mzidek@redhat.com>
Diffstat (limited to 'src/util/child_common.c')
-rw-r--r-- | src/util/child_common.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/util/child_common.c b/src/util/child_common.c index 81bbab70e..e4a885b6e 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; +} |