1diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
2index 56dc1f856..011ec2700 100644
3--- a/lib/commands/toolcontext.c
4+++ b/lib/commands/toolcontext.c
5@@ -1660,6 +1660,7 @@ struct cmd_context *create_toolcontext(unsigned is_clvmd,
6 /* FIXME Make this configurable? */
7 reset_lvm_errno(1);
8
9+#ifdef __GLIBC__
10 /* Set in/out stream buffering before glibc */
11 if (set_buffering
12 && !cmd->running_on_valgrind /* Skipping within valgrind execution. */
13@@ -1704,7 +1705,7 @@ struct cmd_context *create_toolcontext(unsigned is_clvmd,
14 } else if (!set_buffering)
15 /* Without buffering, must not use stdin/stdout */
16 init_silent(1);
17-
18+#endif
19 /*
20 * Environment variable LVM_SYSTEM_DIR overrides this below.
21 */
22@@ -2038,6 +2039,7 @@ void destroy_toolcontext(struct cmd_context *cmd)
23 if (cmd->cft_def_hash)
24 dm_hash_destroy(cmd->cft_def_hash);
25
26+#ifdef __GLIBC__
27 if (!cmd->running_on_valgrind && cmd->linebuffer) {
28 int flags;
29 /* Reset stream buffering to defaults */
30@@ -2061,6 +2063,7 @@ void destroy_toolcontext(struct cmd_context *cmd)
31
32 free(cmd->linebuffer);
33 }
34+#endif
35
36 destroy_config_context(cmd);
37
38diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
39index 1b2f7f47c..e0674d42d 100644
40--- a/tools/lvmcmdline.c
41+++ b/tools/lvmcmdline.c
42@@ -3378,7 +3378,7 @@ static int _check_standard_fds(void)
43 int err = is_valid_fd(STDERR_FILENO);
44
45 if (!is_valid_fd(STDIN_FILENO) &&
46- !(stdin = fopen(_PATH_DEVNULL, "r"))) {
47+ !freopen(_PATH_DEVNULL, "r", stdin)) {
48 if (err)
49 perror("stdin stream open");
50 else
51@@ -3388,7 +3388,7 @@ static int _check_standard_fds(void)
52 }
53
54 if (!is_valid_fd(STDOUT_FILENO) &&
55- !(stdout = fopen(_PATH_DEVNULL, "w"))) {
56+ !freopen(_PATH_DEVNULL, "w", stdout)) {
57 if (err)
58 perror("stdout stream open");
59 /* else no stdout */
60@@ -3396,7 +3396,7 @@ static int _check_standard_fds(void)
61 }
62
63 if (!is_valid_fd(STDERR_FILENO) &&
64- !(stderr = fopen(_PATH_DEVNULL, "w"))) {
65+ !freopen(_PATH_DEVNULL, "w", stderr)) {
66 printf("stderr stream open: %s\n",
67 strerror(errno));
68 return 0;