lvm2-2.03.20-freopen-musl.patch 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. From 4cf08811e112100a2b10c60047f3c537ad21d674 Mon Sep 17 00:00:00 2001
  2. From: David Seifert <soap@gentoo.org>
  3. Date: Sat, 28 Jan 2023 14:22:42 +0100
  4. Subject: [PATCH] Use `freopen()` on {stdin,stdout,stderr}
  5. * ISO C does not guarantee that the standard streams are modifiable
  6. lvalues. Glibc even calls out this behaviour as non-portable:
  7. https://www.gnu.org/software/libc/manual/html_node/Standard-Streams.html
  8. --- a/lib/log/log.c
  9. +++ b/lib/log/log.c
  10. @@ -208,7 +208,11 @@ int reopen_standard_stream(FILE **stream, const char *mode)
  11. _check_and_replace_standard_log_streams(old_stream, new_stream);
  12. +#ifdef __GLIBC__
  13. *stream = new_stream;
  14. +#else
  15. + freopen(NULL, mode, *stream);
  16. +#endif
  17. return 1;
  18. }
  19. --- a/tools/lvmcmdline.c
  20. +++ b/tools/lvmcmdline.c
  21. @@ -3422,7 +3422,7 @@ static int _check_standard_fds(void)
  22. int err = is_valid_fd(STDERR_FILENO);
  23. if (!is_valid_fd(STDIN_FILENO) &&
  24. - !(stdin = fopen(_PATH_DEVNULL, "r"))) {
  25. + !freopen(_PATH_DEVNULL, "r", stdin)) {
  26. if (err)
  27. perror("stdin stream open");
  28. else
  29. @@ -3432,7 +3432,7 @@ static int _check_standard_fds(void)
  30. }
  31. if (!is_valid_fd(STDOUT_FILENO) &&
  32. - !(stdout = fopen(_PATH_DEVNULL, "w"))) {
  33. + !freopen(_PATH_DEVNULL, "w", stdout)) {
  34. if (err)
  35. perror("stdout stream open");
  36. /* else no stdout */
  37. @@ -3440,7 +3440,7 @@ static int _check_standard_fds(void)
  38. }
  39. if (!is_valid_fd(STDERR_FILENO) &&
  40. - !(stderr = fopen(_PATH_DEVNULL, "w"))) {
  41. + !freopen(_PATH_DEVNULL, "w", stderr)) {
  42. printf("stderr stream open: %s\n",
  43. strerror(errno));
  44. return 0;
  45. --
  46. 2.39.2