Hi,

While hacking my way around a different patch (better option handling
for pg_test_fsync), I got surprised by the fact that if we run the TAP
tests, logging initialization could return with errno set to ENOTTY
because we call isatty() to check for output coloring.  I found that
this can be possible with Debian gid that uses a recent version of
IPC::Run.

Some system calls may not set errno even if they succeed, like
strtol() on Linux for example, so in this case it can cause option
handling to fail because of the error set by logging initialization.
Shouldn't we reset errno to 0 once logging initialization is done?  It
seems to me that this code path should finish with a clean sheet, and
attached is a proposal of patch to address this issue.

Thoughts?
--
Michael
diff --git a/src/common/logging.c b/src/common/logging.c
index d9632fffc8..13913a71ac 100644
--- a/src/common/logging.c
+++ b/src/common/logging.c
@@ -149,6 +149,12 @@ pg_logging_init(const char *argv0)
 			sgr_locus = SGR_LOCUS_DEFAULT;
 		}
 	}
+
+	/*
+	 * isatty() may fail, setting errno to ENOTTY if running for example
+	 * TAP tests that depend on IPC::Run, so reset properly.
+	 */
+	errno = 0;
 }
 
 void

Attachment: signature.asc
Description: PGP signature

Reply via email to