summaryrefslogtreecommitdiff
path: root/pkgs/os-specific/linux/lvm2/fix-stdio-usage.patch
blob: 7b9989bc25909d9ed6a4bbda8425de6d999a4c7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 56dc1f856..011ec2700 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -1660,6 +1660,7 @@ struct cmd_context *create_toolcontext(unsigned is_clvmd,
 	/* FIXME Make this configurable? */
 	reset_lvm_errno(1);
 
+#ifdef __GLIBC__
 	/* Set in/out stream buffering before glibc */
 	if (set_buffering
 	    && !cmd->running_on_valgrind /* Skipping within valgrind execution. */
@@ -1704,7 +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 +2039,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 +2063,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 1b2f7f47c..e0674d42d 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;