[PATCH 2/2] log: use freopen() to reopen standard streams

Simon Rowe <[email protected]>
Newsgroups gmane.linux.lvm.devel
Message-ID <[email protected]>
In glibc stdin, stdout & stderr are variables that can be assigned to
(https://www.gnu.org/software/libc/manual/html_node/Standard-Streams.html)
however this not necessarily true of other C libraries.

The gentoo musl porting notes
(https://wiki.gentoo.org/wiki/Musl_porting_notes)
recommend the substitution of

    stdX = fopen(...)

with

    freopen(..., stdX)

Signed-off-by: Simon Rowe <[email protected]>
---
 lib/log/log.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/log/log.c b/lib/log/log.c
index 118a3ba42..a94016d81 100644
--- a/lib/log/log.c
+++ b/lib/log/log.c
@@ -208,7 +208,11 @@ int reopen_standard_stream(FILE **stream, const char *mode)
 
 	_check_and_replace_standard_log_streams(old_stream, new_stream);
 
+#ifdef __GLIBC__
 	*stream = new_stream;
+#else
+	freopen(NULL, mode, *stream);
+#endif
 	return 1;
 }
 
-- 
2.22.3

--
lvm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/lvm-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.