From d0e166134f0c575a0a5e7af914dd29b1e99986bc Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Apr 02 2018 17:48:59 +0000 Subject: If stderr is not a tty log to syslog so the helpers can log All the helpers were configured to use the log method cm_log_stderr which when exececuted as a helper from the certmonger daemon would log nowhere. If stderr is detected as a tty (e.g. the helper is run directly on the cli) then logging will go there. Otherwise it will log to syslog (honoring the log level). --- diff --git a/src/certmaster.c b/src/certmaster.c index c9572b8..7e0bed9 100644 --- a/src/certmaster.c +++ b/src/certmaster.c @@ -86,7 +86,10 @@ main(int argc, const char **argv) bindtextdomain(PACKAGE, MYLOCALEDIR); #endif - cm_log_set_method(cm_log_stderr); + if (isatty(STDERR_FILENO)) + cm_log_set_method(cm_log_stderr); + else + cm_log_set_method(cm_log_syslog); pctx = poptGetContext(argv[0], argc, argv, popts, 0); if (pctx == NULL) { return CM_SUBMIT_STATUS_UNCONFIGURED; diff --git a/src/dogtag.c b/src/dogtag.c index 871f387..cd0b38b 100644 --- a/src/dogtag.c +++ b/src/dogtag.c @@ -296,7 +296,10 @@ main(int argc, const char **argv) } umask(S_IRWXG | S_IRWXO); - cm_log_set_method(cm_log_stderr); + if (isatty(STDERR_FILENO)) + cm_log_set_method(cm_log_stderr); + else + cm_log_set_method(cm_log_syslog); cm_log_set_level(verbose); nctx = NSS_InitContext(CM_DEFAULT_CERT_STORAGE_LOCATION, diff --git a/src/ipa.c b/src/ipa.c index 5506352..67a0c65 100644 --- a/src/ipa.c +++ b/src/ipa.c @@ -689,7 +689,10 @@ main(int argc, const char **argv) } umask(S_IRWXG | S_IRWXO); - cm_log_set_method(cm_log_stderr); + if (isatty(STDERR_FILENO)) + cm_log_set_method(cm_log_stderr); + else + cm_log_set_method(cm_log_syslog); cm_log_set_level(verbose); /* Start backfilling defaults, both hard-coded and from the IPA diff --git a/src/local.c b/src/local.c index 48a9e36..f437d62 100644 --- a/src/local.c +++ b/src/local.c @@ -488,7 +488,10 @@ main(int argc, const char **argv) umask(S_IRWXG | S_IRWXO); - cm_log_set_method(cm_log_stderr); + if (isatty(STDERR_FILENO)) + cm_log_set_method(cm_log_stderr); + else + cm_log_set_method(cm_log_syslog); cm_log_set_level(verbose); if (localdir == NULL) { diff --git a/src/scep.c b/src/scep.c index 1ddb883..5020258 100644 --- a/src/scep.c +++ b/src/scep.c @@ -343,7 +343,10 @@ main(int argc, const char **argv) } umask(S_IRWXG | S_IRWXO); - cm_log_set_method(cm_log_stderr); + if (isatty(STDERR_FILENO)) + cm_log_set_method(cm_log_stderr); + else + cm_log_set_method(cm_log_syslog); cm_log_set_level(verbose); ctx = talloc_new(NULL);