diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2012-11-28 14:16:52 +0100 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2013-02-10 19:54:57 +0100 |
commit | 4811057a37549a6ef3a2b04f8bcce8b64d44f581 (patch) | |
tree | e18ceac102e500ffefc10da83503027c2950d3db /src/util/debug.c | |
parent | 2cbb879c517f2c756a2eb3962527979bac01ddab (diff) | |
download | sssd-ldapdebug.tar.gz sssd-ldapdebug.tar.xz sssd-ldapdebug.zip |
Enable libldap debuggingldapdebug
Diffstat (limited to 'src/util/debug.c')
-rw-r--r-- | src/util/debug.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/util/debug.c b/src/util/debug.c index 54fb8011b..305799bdc 100644 --- a/src/util/debug.c +++ b/src/util/debug.c @@ -274,3 +274,55 @@ void talloc_log_fn(const char *message) { DEBUG(SSSDBG_FATAL_FAILURE, (message)); } + +int reopen_stderr_for_libldap(const char *filename) +{ + int ret; + char *logpath; + const char *log_file; + FILE *new_stderr; + TALLOC_CTX *tmp_ctx; + + if (!debug_to_file) return EOK; + + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) return ENOMEM; + + log_file = filename ? filename : debug_log_file; + + logpath = talloc_asprintf(tmp_ctx, "%s/%s.log", LOG_PATH, log_file); + if (logpath == NULL) { + ret = ENOMEM; + goto done; + } + + fclose(stderr); + new_stderr = freopen(logpath, "a", stderr); + if (!new_stderr) { + ret = errno; + DEBUG(SSSDBG_OP_FAILURE, ("Couldn't reopen stderr to logfile\n")); + goto done; + } + + ret = EOK; +done: + talloc_free(tmp_ctx); + return ret; +} + +int reopen_stderr_after_libldap(void) +{ + FILE *new_stderr; + int ret; + + if (!debug_to_file) return EOK; + + new_stderr = freopen("/dev/null", "a", stderr); + if (!new_stderr) { + ret = errno; + DEBUG(SSSDBG_OP_FAILURE, ("Couldn't reopen stderr to logfile\n")); + return ret; + } + + return EOK; +} |