aports/main/lvm2/fix-stdio-usage.patch
Kevin Daudt 906ac47bfe main/lvm2: restore patch for toolcontext
This was dropped in 197d22d7cb (main/lvm2: upgrade to 2.03.28, 2024-11-18), but
aparently still required.

Fixes #16628
2024-11-19 17:04:08 +00:00

67 lines
2 KiB
Diff

diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 60739af..8b3fdf7 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -1661,6 +1661,7 @@ struct cmd_context *create_toolcontext(unsigned is_clvmd,
reset_lvm_errno(1);
/* Set in/out stream buffering before glibc */
+#ifdef __GLIBC__
if (set_buffering
&& !cmd->running_on_valgrind /* Skipping within valgrind execution. */
#ifdef SYS_gettid
@@ -1704,6 +1705,7 @@ struct cmd_context *create_toolcontext(unsigned is_clvmd,
} else if (!set_buffering)
/* Without buffering, must not use stdin/stdout */
init_silent(1);
+#endif
/*
* Environment variable LVM_SYSTEM_DIR overrides this below.
@@ -2038,6 +2040,7 @@ void destroy_toolcontext(struct cmd_context *cmd)
if (cmd->cft_def_hash)
dm_hash_destroy(cmd->cft_def_hash);
+#ifdef __GLIBC__
if (!cmd->running_on_valgrind && cmd->linebuffer) {
int flags;
/* Reset stream buffering to defaults */
@@ -2061,6 +2064,7 @@ void destroy_toolcontext(struct cmd_context *cmd)
free(cmd->linebuffer);
}
+#endif
destroy_config_context(cmd);
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index 7209ebd..778c8c0 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -3378,7 +3378,7 @@ static int _check_standard_fds(void)
int err = is_valid_fd(STDERR_FILENO);
if (!is_valid_fd(STDIN_FILENO) &&
- !(stdin = fopen(_PATH_DEVNULL, "r"))) {
+ !freopen(_PATH_DEVNULL, "r", stdin)) {
if (err)
perror("stdin stream open");
else
@@ -3388,7 +3388,7 @@ static int _check_standard_fds(void)
}
if (!is_valid_fd(STDOUT_FILENO) &&
- !(stdout = fopen(_PATH_DEVNULL, "w"))) {
+ !freopen(_PATH_DEVNULL, "w", stdout)) {
if (err)
perror("stdout stream open");
/* else no stdout */
@@ -3396,7 +3396,7 @@ static int _check_standard_fds(void)
}
if (!is_valid_fd(STDERR_FILENO) &&
- !(stderr = fopen(_PATH_DEVNULL, "w"))) {
+ !freopen(_PATH_DEVNULL, "w", stderr)) {
printf("stderr stream open: %s\n",
strerror(errno));
return 0;