1diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
2index 296618686..96343eeb7 100644
3--- a/lib/commands/toolcontext.c
4+++ b/lib/commands/toolcontext.c
5@@ -1619,7 +1619,7 @@ struct cmd_context *create_toolcontext(unsigned is_clvmd,
6 /* FIXME Make this configurable? */
7 reset_lvm_errno(1);
8
9-#ifndef VALGRIND_POOL
10+#if !defined(VALGRIND_POOL) && defined(__GLIBC__)
11 /* Set in/out stream buffering before glibc */
12 if (set_buffering
13 #ifdef SYS_gettid
14@@ -2006,7 +2006,7 @@ void destroy_toolcontext(struct cmd_context *cmd)
15
16 if (cmd->pending_delete_mem)
17 dm_pool_destroy(cmd->pending_delete_mem);
18-#ifndef VALGRIND_POOL
19+#if !defined(VALGRIND_POOL) && defined(__GLIBC__)
20 if (cmd->linebuffer) {
21 /* Reset stream buffering to defaults */
22 if (is_valid_fd(STDIN_FILENO) &&
23diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
24index d97ff5720..bbbda82bd 100644
25--- a/tools/lvmcmdline.c
26+++ b/tools/lvmcmdline.c
27@@ -3342,7 +3342,7 @@ static int _check_standard_fds(void)
28 int err = is_valid_fd(STDERR_FILENO);
29
30 if (!is_valid_fd(STDIN_FILENO) &&
31- !(stdin = fopen(_PATH_DEVNULL, "r"))) {
32+ !freopen(_PATH_DEVNULL, "r", stdin)) {
33 if (err)
34 perror("stdin stream open");
35 else
36@@ -3352,7 +3352,7 @@ static int _check_standard_fds(void)
37 }
38
39 if (!is_valid_fd(STDOUT_FILENO) &&
40- !(stdout = fopen(_PATH_DEVNULL, "w"))) {
41+ !freopen(_PATH_DEVNULL, "w", stdout)) {
42 if (err)
43 perror("stdout stream open");
44 /* else no stdout */
45@@ -3360,7 +3360,7 @@ static int _check_standard_fds(void)
46 }
47
48 if (!is_valid_fd(STDERR_FILENO) &&
49- !(stderr = fopen(_PATH_DEVNULL, "w"))) {
50+ !freopen(_PATH_DEVNULL, "w", stderr)) {
51 printf("stderr stream open: %s\n",
52 strerror(errno));
53 return 0;