From 3364f76f5984ff4cbc8e7a1a455cedfa228adc4b Mon Sep 17 00:00:00 2001
From: Rob Crittenden <rcritten@redhat.com>
Date: Mon, 2 Apr 2018 13:26:39 -0400
Subject: [PATCH 20/25] 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).
---
src/certmaster.c | 5 ++++-
src/dogtag.c | 5 ++++-
src/ipa.c | 5 ++++-
src/local.c | 5 ++++-
src/scep.c | 5 ++++-
5 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/src/certmaster.c b/src/certmaster.c
index 64662fa..dc68ecd 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 0247cf2..3780a2d 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 13ea4ca..1279d1c 100644
--- a/src/ipa.c
+++ b/src/ipa.c
@@ -671,7 +671,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 74aee63..004add3 100644
--- a/src/local.c
+++ b/src/local.c
@@ -484,7 +484,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 11f9ae3..0dbdcd7 100644
--- a/src/scep.c
+++ b/src/scep.c
@@ -332,7 +332,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);
--
1.8.3.1