>From 67c8d8be3030a1cf3dbda14bd74f3c4308190642 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Tue, 8 Jul 2014 15:05:24 +0200 Subject: [PATCH 1/2] SSSD: Send debug to stderr when running on foreground https://fedorahosted.org/sssd/ticket/2348 When SSSD is running in interactive mode, we should print DEBUG messages directly to stderr, not journal. --- src/monitor/monitor.c | 21 ++++++++++++++++++++- src/providers/ldap/ldap_child.c | 2 ++ src/util/child_common.c | 10 ++++++++++ src/util/debug.c | 3 ++- src/util/util.h | 3 +++ 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c index 5feba706af63e579403296329e3275c7ba8c12e9..39f4e6437e1a60c830a30b4596a385b3c54ea167 100644 --- a/src/monitor/monitor.c +++ b/src/monitor/monitor.c @@ -1124,6 +1124,14 @@ static int get_service_config(struct mt_ctx *ctx, const char *name, talloc_free(svc); return ENOMEM; } + } else if (ctx->is_daemon == false) { + svc->command = talloc_strdup_append( + svc->command, " --debug-to-stderr" + ); + if (!svc->command) { + talloc_free(svc); + return ENOMEM; + } } } @@ -1287,6 +1295,14 @@ static int get_provider_config(struct mt_ctx *ctx, const char *name, talloc_free(svc); return ENOMEM; } + } else if (ctx->is_daemon == false) { + svc->command = talloc_strdup_append( + svc->command, " --debug-to-stderr" + ); + if (!svc->command) { + talloc_free(svc); + return ENOMEM; + } } } @@ -2735,7 +2751,10 @@ int main(int argc, const char *argv[]) } if (opt_daemon) flags |= FLAGS_DAEMON; - if (opt_interactive) flags |= FLAGS_INTERACTIVE; + if (opt_interactive) { + flags |= FLAGS_INTERACTIVE; + debug_to_stderr = 1; + } if (opt_config_file) { config_file = talloc_strdup(tmp_ctx, opt_config_file); diff --git a/src/providers/ldap/ldap_child.c b/src/providers/ldap/ldap_child.c index ee7bbff89ae63373d781a78cb5d5f2f1704f27bd..e2fe3f232b3f051bf1d94617c2c711b7087130c7 100644 --- a/src/providers/ldap/ldap_child.c +++ b/src/providers/ldap/ldap_child.c @@ -439,6 +439,8 @@ int main(int argc, const char *argv[]) _("Show timestamps with microseconds"), NULL}, {"debug-fd", 0, POPT_ARG_INT, &debug_fd, 0, _("An open file descriptor for the debug logs"), NULL}, + {"debug-to-stderr", 0, POPT_ARG_NONE | POPT_ARGFLAG_DOC_HIDDEN, &debug_to_stderr, 0, \ + _("Send the debug output to stderr directly."), NULL }, \ POPT_TABLEEND }; diff --git a/src/util/child_common.c b/src/util/child_common.c index 08aac1143e3dccf1d02a3600f86cec92f1587efd..81bbab70ed44a6c0a4410909924aec195c643bea 100644 --- a/src/util/child_common.c +++ b/src/util/child_common.c @@ -637,8 +637,10 @@ static errno_t prepare_child_argv(TALLOC_CTX *mem_ctx, bool child_debug_to_file = debug_to_file; bool child_debug_timestamps = debug_timestamps; bool child_debug_microseconds = debug_microseconds; + bool child_debug_stderr = debug_to_stderr; if (child_debug_to_file) argc++; + if (child_debug_stderr) argc++; /* * program name, debug_level, debug_to_file, debug_timestamps, @@ -659,6 +661,14 @@ static errno_t prepare_child_argv(TALLOC_CTX *mem_ctx, goto fail; } + if (child_debug_stderr) { + argv[--argc] = talloc_strdup(argv, "--debug-to-stderr"); + if (argv[argc] == NULL) { + ret = ENOMEM; + goto fail; + } + } + if (child_debug_to_file) { argv[--argc] = talloc_asprintf(argv, "--debug-fd=%d", child_debug_fd); diff --git a/src/util/debug.c b/src/util/debug.c index b66de07b4e3a4549548f627f07a45f97068fa21b..a99d5403a238f125010b9b309355b30f9f528c44 100644 --- a/src/util/debug.c +++ b/src/util/debug.c @@ -42,6 +42,7 @@ int debug_level = SSSDBG_UNRESOLVED; int debug_timestamps = SSSDBG_TIMESTAMP_UNRESOLVED; int debug_microseconds = SSSDBG_MICROSECONDS_UNRESOLVED; int debug_to_file = 0; +int debug_to_stderr = 0; const char *debug_log_file = "sssd"; FILE *debug_file = NULL; @@ -212,7 +213,7 @@ void debug_fn(const char *file, errno_t ret; va_list ap_fallback; - if (!debug_file) { + if (!debug_file && !debug_to_stderr) { /* If we are not outputting logs to files, we should be sending them * to journald. * NOTE: on modern systems, this is where stdout/stderr will end up diff --git a/src/util/util.h b/src/util/util.h index 5c02c33a551440afeb32c00542fe2574784e8cb1..6a9bc0c2e5f5dd3307a3e0708b6f755eec687ac8 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -68,6 +68,7 @@ extern int debug_level; extern int debug_timestamps; extern int debug_microseconds; extern int debug_to_file; +extern int debug_to_stderr; extern const char *debug_log_file; void debug_fn(const char *file, long line, @@ -107,6 +108,8 @@ errno_t set_debug_file_from_fd(const int fd); _("Debug level"), NULL}, \ {"debug-to-files", 'f', POPT_ARG_NONE, &debug_to_file, 0, \ _("Send the debug output to files instead of stderr"), NULL }, \ + {"debug-to-stderr", 0, POPT_ARG_NONE | POPT_ARGFLAG_DOC_HIDDEN, &debug_to_stderr, 0, \ + _("Send the debug output to stderr directly."), NULL }, \ {"debug-timestamps", 0, POPT_ARG_INT, &debug_timestamps, 0, \ _("Add debug timestamps"), NULL}, \ {"debug-microseconds", 0, POPT_ARG_INT, &debug_microseconds, 0, \ -- 1.9.3