Blame SOURCES/0020-If-stderr-is-not-a-tty-log-to-syslog-so-the-helpers-.patch

7a8c6d
From 3364f76f5984ff4cbc8e7a1a455cedfa228adc4b Mon Sep 17 00:00:00 2001
7a8c6d
From: Rob Crittenden <rcritten@redhat.com>
7a8c6d
Date: Mon, 2 Apr 2018 13:26:39 -0400
7a8c6d
Subject: [PATCH 20/25] If stderr is not a tty log to syslog so the helpers can
7a8c6d
 log
7a8c6d
7a8c6d
All the helpers were configured to use the log method cm_log_stderr
7a8c6d
which when exececuted as a helper from the certmonger daemon would
7a8c6d
log nowhere.
7a8c6d
7a8c6d
If stderr is detected as a tty (e.g. the helper is run directly on
7a8c6d
the cli) then logging will go there. Otherwise it will log to
7a8c6d
syslog (honoring the log level).
7a8c6d
---
7a8c6d
 src/certmaster.c | 5 ++++-
7a8c6d
 src/dogtag.c     | 5 ++++-
7a8c6d
 src/ipa.c        | 5 ++++-
7a8c6d
 src/local.c      | 5 ++++-
7a8c6d
 src/scep.c       | 5 ++++-
7a8c6d
 5 files changed, 20 insertions(+), 5 deletions(-)
7a8c6d
7a8c6d
diff --git a/src/certmaster.c b/src/certmaster.c
7a8c6d
index 64662fa..dc68ecd 100644
7a8c6d
--- a/src/certmaster.c
7a8c6d
+++ b/src/certmaster.c
7a8c6d
@@ -86,7 +86,10 @@ main(int argc, const char **argv)
7a8c6d
 	bindtextdomain(PACKAGE, MYLOCALEDIR);
7a8c6d
 #endif
7a8c6d
 
7a8c6d
-	cm_log_set_method(cm_log_stderr);
7a8c6d
+    if (isatty(STDERR_FILENO))
7a8c6d
+		cm_log_set_method(cm_log_stderr);
7a8c6d
+	else
7a8c6d
+		cm_log_set_method(cm_log_syslog);
7a8c6d
 	pctx = poptGetContext(argv[0], argc, argv, popts, 0);
7a8c6d
 	if (pctx == NULL) {
7a8c6d
 		return CM_SUBMIT_STATUS_UNCONFIGURED;
7a8c6d
diff --git a/src/dogtag.c b/src/dogtag.c
7a8c6d
index 0247cf2..3780a2d 100644
7a8c6d
--- a/src/dogtag.c
7a8c6d
+++ b/src/dogtag.c
7a8c6d
@@ -296,7 +296,10 @@ main(int argc, const char **argv)
7a8c6d
 	}
7a8c6d
 
7a8c6d
 	umask(S_IRWXG | S_IRWXO);
7a8c6d
-	cm_log_set_method(cm_log_stderr);
7a8c6d
+	if (isatty(STDERR_FILENO))
7a8c6d
+		cm_log_set_method(cm_log_stderr);
7a8c6d
+	else
7a8c6d
+		cm_log_set_method(cm_log_syslog);
7a8c6d
 	cm_log_set_level(verbose);
7a8c6d
 
7a8c6d
 	nctx = NSS_InitContext(CM_DEFAULT_CERT_STORAGE_LOCATION,
7a8c6d
diff --git a/src/ipa.c b/src/ipa.c
7a8c6d
index 13ea4ca..1279d1c 100644
7a8c6d
--- a/src/ipa.c
7a8c6d
+++ b/src/ipa.c
7a8c6d
@@ -671,7 +671,10 @@ main(int argc, const char **argv)
7a8c6d
 	}
7a8c6d
 
7a8c6d
 	umask(S_IRWXG | S_IRWXO);
7a8c6d
-	cm_log_set_method(cm_log_stderr);
7a8c6d
+	if (isatty(STDERR_FILENO))
7a8c6d
+		cm_log_set_method(cm_log_stderr);
7a8c6d
+	else
7a8c6d
+		cm_log_set_method(cm_log_syslog);
7a8c6d
 	cm_log_set_level(verbose);
7a8c6d
 
7a8c6d
 	/* Start backfilling defaults, both hard-coded and from the IPA
7a8c6d
diff --git a/src/local.c b/src/local.c
7a8c6d
index 74aee63..004add3 100644
7a8c6d
--- a/src/local.c
7a8c6d
+++ b/src/local.c
7a8c6d
@@ -484,7 +484,10 @@ main(int argc, const char **argv)
7a8c6d
 
7a8c6d
 	umask(S_IRWXG | S_IRWXO);
7a8c6d
 
7a8c6d
-	cm_log_set_method(cm_log_stderr);
7a8c6d
+	if (isatty(STDERR_FILENO))
7a8c6d
+		cm_log_set_method(cm_log_stderr);
7a8c6d
+	else
7a8c6d
+		cm_log_set_method(cm_log_syslog);
7a8c6d
 	cm_log_set_level(verbose);
7a8c6d
 
7a8c6d
 	if (localdir == NULL) {
7a8c6d
diff --git a/src/scep.c b/src/scep.c
7a8c6d
index 11f9ae3..0dbdcd7 100644
7a8c6d
--- a/src/scep.c
7a8c6d
+++ b/src/scep.c
7a8c6d
@@ -332,7 +332,10 @@ main(int argc, const char **argv)
7a8c6d
 	}
7a8c6d
 
7a8c6d
 	umask(S_IRWXG | S_IRWXO);
7a8c6d
-	cm_log_set_method(cm_log_stderr);
7a8c6d
+	if (isatty(STDERR_FILENO))
7a8c6d
+		cm_log_set_method(cm_log_stderr);
7a8c6d
+	else
7a8c6d
+		cm_log_set_method(cm_log_syslog);
7a8c6d
 	cm_log_set_level(verbose);
7a8c6d
 
7a8c6d
 	ctx = talloc_new(NULL);
7a8c6d
-- 
7a8c6d
1.8.3.1
7a8c6d