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

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