From 77b13371c87702aee3f858f6b2b73826cf5a01bd Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Tue, 21 Oct 2014 22:36:59 +0200 Subject: UTIL: Remove more code duplication setting up child processes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All our child processes duplicated the same code that set up the debugging all around. Instead of adding yet another copy for the selinux_child, add a common utility function. Reviewed-by: Michal Židek --- src/util/child_common.c | 29 +++++++++++++++++++++++++++++ src/util/child_common.h | 2 ++ 2 files changed, 31 insertions(+) (limited to 'src/util') diff --git a/src/util/child_common.c b/src/util/child_common.c index e4a885b6e..cc6a8fa75 100644 --- a/src/util/child_common.c +++ b/src/util/child_common.c @@ -801,3 +801,32 @@ int child_io_destructor(void *ptr) return EOK; } + +errno_t child_debug_init(const char *logfile, int *debug_fd) +{ + int ret; + FILE *debug_filep; + + if (debug_fd == NULL) { + return EOK; + } + + if (debug_to_file != 0 && *debug_fd == -1) { + ret = open_debug_file_ex(logfile, &debug_filep, false); + if (ret != EOK) { + DEBUG(SSSDBG_FATAL_FAILURE, "Error setting up logging (%d) [%s]\n", + ret, sss_strerror(ret)); + return ret; + } + + *debug_fd = fileno(debug_filep); + if (*debug_fd == -1) { + DEBUG(SSSDBG_FATAL_FAILURE, + "fileno failed [%d][%s]\n", errno, strerror(errno)); + ret = errno; + return ret; + } + } + + return EOK; +} diff --git a/src/util/child_common.h b/src/util/child_common.h index 261da7f9c..e159719a2 100644 --- a/src/util/child_common.h +++ b/src/util/child_common.h @@ -120,4 +120,6 @@ void child_cleanup(int readfd, int writefd); int child_io_destructor(void *ptr); +errno_t child_debug_init(const char *logfile, int *debug_fd); + #endif /* __CHILD_COMMON_H__ */ -- cgit