0004-log-use-freopen-to-reopen-standard-streams.patch 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. From 6d6b953cf7d2b8d06e7b0363b1b06cb2e902aa0f Mon Sep 17 00:00:00 2001
  2. From: Simon Rowe <simon.rowe@nutanix.com>
  3. Date: Thu, 23 Mar 2023 10:07:02 +0000
  4. Subject: [PATCH] log: use freopen() to reopen standard streams
  5. In glibc stdin, stdout & stderr are variables that can be assigned to
  6. (https://www.gnu.org/software/libc/manual/html_node/Standard-Streams.html)
  7. however this not necessarily true of other C libraries.
  8. The gentoo musl porting notes
  9. (https://wiki.gentoo.org/wiki/Musl_porting_notes)
  10. recommend the substitution of
  11. stdX = fopen(...)
  12. with
  13. freopen(..., stdX)
  14. Taken from: https://github.com/gentoo/gentoo/blob/master/sys-fs/lvm2/files/lvm2-2.03.14-freopen_n2.patch
  15. Signed-off-by: Simon Rowe <simon.rowe@nutanix.com>
  16. ---
  17. lib/log/log.c | 4 ++++
  18. 1 file changed, 4 insertions(+)
  19. diff --git a/lib/log/log.c b/lib/log/log.c
  20. index 7b4d537b3..5f62c048c 100644
  21. --- a/lib/log/log.c
  22. +++ b/lib/log/log.c
  23. @@ -208,7 +208,11 @@ int reopen_standard_stream(FILE **stream, const char *mode)
  24. _check_and_replace_standard_log_streams(old_stream, new_stream);
  25. +#ifdef __GLIBC__
  26. *stream = new_stream;
  27. +#else
  28. + freopen(NULL, mode, *stream);
  29. +#endif
  30. return 1;
  31. }
  32. --
  33. 2.22.3