|
|
905b4d |
From b95d9cbd6959a3174c4fb963be642f770938e4b7 Mon Sep 17 00:00:00 2001
|
|
|
905b4d |
From: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
905b4d |
Date: Tue, 21 Oct 2014 22:36:59 +0200
|
|
|
905b4d |
Subject: [PATCH 70/71] UTIL: Remove more code duplication setting up child
|
|
|
905b4d |
processes
|
|
|
905b4d |
MIME-Version: 1.0
|
|
|
905b4d |
Content-Type: text/plain; charset=UTF-8
|
|
|
905b4d |
Content-Transfer-Encoding: 8bit
|
|
|
905b4d |
|
|
|
905b4d |
All our child processes duplicated the same code that set up the
|
|
|
905b4d |
debugging all around. Instead of adding yet another copy for the
|
|
|
905b4d |
selinux_child, add a common utility function.
|
|
|
905b4d |
|
|
|
905b4d |
Reviewed-by: Michal Židek <mzidek@redhat.com>
|
|
|
905b4d |
---
|
|
|
905b4d |
src/providers/ad/ad_gpo.c | 23 ++---------------------
|
|
|
905b4d |
src/providers/krb5/krb5_init_shared.c | 24 ++++++++----------------
|
|
|
905b4d |
src/providers/ldap/sdap_child_helpers.c | 22 +---------------------
|
|
|
905b4d |
src/util/child_common.c | 29 +++++++++++++++++++++++++++++
|
|
|
905b4d |
src/util/child_common.h | 2 ++
|
|
|
905b4d |
5 files changed, 42 insertions(+), 58 deletions(-)
|
|
|
905b4d |
|
|
|
905b4d |
diff --git a/src/providers/ad/ad_gpo.c b/src/providers/ad/ad_gpo.c
|
|
|
905b4d |
index 80b0d45c2861a64f01fe7835cccee4348084c7da..83edbe4fb5a7e617cab95c0330ceae31392b18b2 100644
|
|
|
905b4d |
--- a/src/providers/ad/ad_gpo.c
|
|
|
905b4d |
+++ b/src/providers/ad/ad_gpo.c
|
|
|
905b4d |
@@ -1313,29 +1313,10 @@ ad_gpo_access_check(TALLOC_CTX *mem_ctx,
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
#define GPO_CHILD_LOG_FILE "gpo_child"
|
|
|
905b4d |
+
|
|
|
905b4d |
static errno_t gpo_child_init(void)
|
|
|
905b4d |
{
|
|
|
905b4d |
- int ret;
|
|
|
905b4d |
- FILE *debug_filep;
|
|
|
905b4d |
-
|
|
|
905b4d |
- if (debug_to_file != 0 && gpo_child_debug_fd == -1) {
|
|
|
905b4d |
- ret = open_debug_file_ex(GPO_CHILD_LOG_FILE, &debug_filep, false);
|
|
|
905b4d |
- if (ret != EOK) {
|
|
|
905b4d |
- DEBUG(SSSDBG_FATAL_FAILURE, "Error setting up logging (%d) [%s]\n",
|
|
|
905b4d |
- ret, strerror(ret));
|
|
|
905b4d |
- return ret;
|
|
|
905b4d |
- }
|
|
|
905b4d |
-
|
|
|
905b4d |
- gpo_child_debug_fd = fileno(debug_filep);
|
|
|
905b4d |
- if (gpo_child_debug_fd == -1) {
|
|
|
905b4d |
- DEBUG(SSSDBG_FATAL_FAILURE,
|
|
|
905b4d |
- "fileno failed [%d][%s]\n", errno, strerror(errno));
|
|
|
905b4d |
- ret = errno;
|
|
|
905b4d |
- return ret;
|
|
|
905b4d |
- }
|
|
|
905b4d |
- }
|
|
|
905b4d |
-
|
|
|
905b4d |
- return EOK;
|
|
|
905b4d |
+ return child_debug_init(GPO_CHILD_LOG_FILE, &gpo_child_debug_fd);
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
/*
|
|
|
905b4d |
diff --git a/src/providers/krb5/krb5_init_shared.c b/src/providers/krb5/krb5_init_shared.c
|
|
|
905b4d |
index 340eab1f0d432d411e2b807f66b03bffcbd14d1d..3b4bf096ef49d0f2d369fda20462b7fd56d61127 100644
|
|
|
905b4d |
--- a/src/providers/krb5/krb5_init_shared.c
|
|
|
905b4d |
+++ b/src/providers/krb5/krb5_init_shared.c
|
|
|
905b4d |
@@ -30,7 +30,6 @@ errno_t krb5_child_init(struct krb5_ctx *krb5_auth_ctx,
|
|
|
905b4d |
struct be_ctx *bectx)
|
|
|
905b4d |
{
|
|
|
905b4d |
errno_t ret;
|
|
|
905b4d |
- FILE *debug_filep;
|
|
|
905b4d |
time_t renew_intv = 0;
|
|
|
905b4d |
krb5_deltat renew_interval_delta;
|
|
|
905b4d |
char *renew_interval_str;
|
|
|
905b4d |
@@ -83,23 +82,16 @@ errno_t krb5_child_init(struct krb5_ctx *krb5_auth_ctx,
|
|
|
905b4d |
goto done;
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
- if (debug_to_file != 0) {
|
|
|
905b4d |
- ret = open_debug_file_ex(KRB5_CHILD_LOG_FILE, &debug_filep, false);
|
|
|
905b4d |
- if (ret != EOK) {
|
|
|
905b4d |
- DEBUG(SSSDBG_FATAL_FAILURE, "Error setting up logging (%d) [%s]\n",
|
|
|
905b4d |
- ret, strerror(ret));
|
|
|
905b4d |
- goto done;
|
|
|
905b4d |
- }
|
|
|
905b4d |
-
|
|
|
905b4d |
- krb5_auth_ctx->child_debug_fd = fileno(debug_filep);
|
|
|
905b4d |
- if (krb5_auth_ctx->child_debug_fd == -1) {
|
|
|
905b4d |
- DEBUG(SSSDBG_FATAL_FAILURE,
|
|
|
905b4d |
- "fileno failed [%d][%s]\n", errno, strerror(errno));
|
|
|
905b4d |
- ret = errno;
|
|
|
905b4d |
- goto done;
|
|
|
905b4d |
- }
|
|
|
905b4d |
+ krb5_auth_ctx->child_debug_fd = -1; /* -1 means not initialized */
|
|
|
905b4d |
+ ret = child_debug_init(KRB5_CHILD_LOG_FILE,
|
|
|
905b4d |
+ &krb5_auth_ctx->child_debug_fd);
|
|
|
905b4d |
+ if (ret != EOK) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_OP_FAILURE, "Could not set krb5_child debugging!\n");
|
|
|
905b4d |
+ goto done;
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
+ ret = EOK;
|
|
|
905b4d |
+
|
|
|
905b4d |
done:
|
|
|
905b4d |
return ret;
|
|
|
905b4d |
}
|
|
|
905b4d |
diff --git a/src/providers/ldap/sdap_child_helpers.c b/src/providers/ldap/sdap_child_helpers.c
|
|
|
905b4d |
index e5d46b9b756cd50fadb212da72ad1cc9bdd93330..40010989021eb7cf77b96876b2d1c4119ed39163 100644
|
|
|
905b4d |
--- a/src/providers/ldap/sdap_child_helpers.c
|
|
|
905b4d |
+++ b/src/providers/ldap/sdap_child_helpers.c
|
|
|
905b4d |
@@ -466,25 +466,5 @@ static errno_t set_tgt_child_timeout(struct tevent_req *req,
|
|
|
905b4d |
/* Setup child logging */
|
|
|
905b4d |
int sdap_setup_child(void)
|
|
|
905b4d |
{
|
|
|
905b4d |
- int ret;
|
|
|
905b4d |
- FILE *debug_filep;
|
|
|
905b4d |
-
|
|
|
905b4d |
- if (debug_to_file != 0 && ldap_child_debug_fd == -1) {
|
|
|
905b4d |
- ret = open_debug_file_ex(LDAP_CHILD_LOG_FILE, &debug_filep, false);
|
|
|
905b4d |
- if (ret != EOK) {
|
|
|
905b4d |
- DEBUG(SSSDBG_FATAL_FAILURE, "Error setting up logging (%d) [%s]\n",
|
|
|
905b4d |
- ret, strerror(ret));
|
|
|
905b4d |
- return ret;
|
|
|
905b4d |
- }
|
|
|
905b4d |
-
|
|
|
905b4d |
- ldap_child_debug_fd = fileno(debug_filep);
|
|
|
905b4d |
- if (ldap_child_debug_fd == -1) {
|
|
|
905b4d |
- DEBUG(SSSDBG_FATAL_FAILURE,
|
|
|
905b4d |
- "fileno failed [%d][%s]\n", errno, strerror(errno));
|
|
|
905b4d |
- ret = errno;
|
|
|
905b4d |
- return ret;
|
|
|
905b4d |
- }
|
|
|
905b4d |
- }
|
|
|
905b4d |
-
|
|
|
905b4d |
- return EOK;
|
|
|
905b4d |
+ return child_debug_init(LDAP_CHILD_LOG_FILE, &ldap_child_debug_fd);
|
|
|
905b4d |
}
|
|
|
905b4d |
diff --git a/src/util/child_common.c b/src/util/child_common.c
|
|
|
905b4d |
index e4a885b6e6e4a1a8a0cabd12ba1544a7c8f0f160..cc6a8fa758bfa6efa511c28cd9121e759b590342 100644
|
|
|
905b4d |
--- a/src/util/child_common.c
|
|
|
905b4d |
+++ b/src/util/child_common.c
|
|
|
905b4d |
@@ -801,3 +801,32 @@ int child_io_destructor(void *ptr)
|
|
|
905b4d |
|
|
|
905b4d |
return EOK;
|
|
|
905b4d |
}
|
|
|
905b4d |
+
|
|
|
905b4d |
+errno_t child_debug_init(const char *logfile, int *debug_fd)
|
|
|
905b4d |
+{
|
|
|
905b4d |
+ int ret;
|
|
|
905b4d |
+ FILE *debug_filep;
|
|
|
905b4d |
+
|
|
|
905b4d |
+ if (debug_fd == NULL) {
|
|
|
905b4d |
+ return EOK;
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
+ if (debug_to_file != 0 && *debug_fd == -1) {
|
|
|
905b4d |
+ ret = open_debug_file_ex(logfile, &debug_filep, false);
|
|
|
905b4d |
+ if (ret != EOK) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_FATAL_FAILURE, "Error setting up logging (%d) [%s]\n",
|
|
|
905b4d |
+ ret, sss_strerror(ret));
|
|
|
905b4d |
+ return ret;
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
+ *debug_fd = fileno(debug_filep);
|
|
|
905b4d |
+ if (*debug_fd == -1) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_FATAL_FAILURE,
|
|
|
905b4d |
+ "fileno failed [%d][%s]\n", errno, strerror(errno));
|
|
|
905b4d |
+ ret = errno;
|
|
|
905b4d |
+ return ret;
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
+ return EOK;
|
|
|
905b4d |
+}
|
|
|
905b4d |
diff --git a/src/util/child_common.h b/src/util/child_common.h
|
|
|
905b4d |
index 261da7f9c546ddfdb38506e5285024ad201bdd4d..e159719a2fca70a4ea044d79530a0d21cb3577e8 100644
|
|
|
905b4d |
--- a/src/util/child_common.h
|
|
|
905b4d |
+++ b/src/util/child_common.h
|
|
|
905b4d |
@@ -120,4 +120,6 @@ void child_cleanup(int readfd, int writefd);
|
|
|
905b4d |
|
|
|
905b4d |
int child_io_destructor(void *ptr);
|
|
|
905b4d |
|
|
|
905b4d |
+errno_t child_debug_init(const char *logfile, int *debug_fd);
|
|
|
905b4d |
+
|
|
|
905b4d |
#endif /* __CHILD_COMMON_H__ */
|
|
|
905b4d |
--
|
|
|
905b4d |
1.9.3
|
|
|
905b4d |
|