summaryrefslogtreecommitdiff
path: root/package/lvm/patches/patch-lib_commands_toolcontext_c
blob: 7a4bbd7cd8824397dea8a93feac1ba5382456fc7 (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
69
70
71
72
73
74
--- LVM2.2.02.114.orig/lib/commands/toolcontext.c	2014-11-29 00:07:42.000000000 +0100
+++ LVM2.2.02.114/lib/commands/toolcontext.c	2015-02-28 09:27:09.000000000 +0100
@@ -1433,6 +1433,8 @@ struct cmd_context *create_toolcontext(u
 {
 	struct cmd_context *cmd;
 	FILE *new_stream;
+	FILE *stdin_stream = stdin;
+	FILE *stdout_stream = stdout;
 	int flags;
 
 #ifdef M_MMAP_MAX
@@ -1482,10 +1484,10 @@ struct cmd_context *create_toolcontext(u
 		if (is_valid_fd(STDIN_FILENO) &&
 		    ((flags = fcntl(STDIN_FILENO, F_GETFL)) > 0) &&
 		    (flags & O_ACCMODE) != O_WRONLY) {
-			if (!_reopen_stream(stdin, STDIN_FILENO, "r", "stdin", &new_stream))
+			if (!_reopen_stream(stdin_stream, STDIN_FILENO, "r", "stdin", &new_stream))
 				goto_out;
-			stdin = new_stream;
-			if (setvbuf(stdin, cmd->linebuffer, _IOLBF, linebuffer_size)) {
+			stdin_stream = new_stream;
+			if (setvbuf(stdin_stream, cmd->linebuffer, _IOLBF, linebuffer_size)) {
 				log_sys_error("setvbuf", "");
 				goto out;
 			}
@@ -1494,10 +1496,10 @@ struct cmd_context *create_toolcontext(u
 		if (is_valid_fd(STDOUT_FILENO) &&
 		    ((flags = fcntl(STDOUT_FILENO, F_GETFL)) > 0) &&
 		    (flags & O_ACCMODE) != O_RDONLY) {
-			if (!_reopen_stream(stdout, STDOUT_FILENO, "w", "stdout", &new_stream))
+			if (!_reopen_stream(stdout_stream, STDOUT_FILENO, "w", "stdout", &new_stream))
 				goto_out;
-			stdout = new_stream;
-			if (setvbuf(stdout, cmd->linebuffer + linebuffer_size,
+			stdout_stream = new_stream;
+			if (setvbuf(stdout_stream, cmd->linebuffer + linebuffer_size,
 				     _IOLBF, linebuffer_size)) {
 				log_sys_error("setvbuf", "");
 				goto out;
@@ -1805,6 +1807,8 @@ void destroy_toolcontext(struct cmd_cont
 {
 	struct dm_config_tree *cft_cmdline;
 	FILE *new_stream;
+	FILE *stdin_stream = stdin;
+	FILE *stdout_stream = stdout;
 	int flags;
 
 	if (cmd->dump_filter && cmd->filter && cmd->filter->dump &&
@@ -1840,9 +1844,9 @@ void destroy_toolcontext(struct cmd_cont
 		if (is_valid_fd(STDIN_FILENO) &&
 		    ((flags = fcntl(STDIN_FILENO, F_GETFL)) > 0) &&
 		    (flags & O_ACCMODE) != O_WRONLY) {
-			if (_reopen_stream(stdin, STDIN_FILENO, "r", "stdin", &new_stream)) {
-				stdin = new_stream;
-				setlinebuf(stdin);
+			if (_reopen_stream(stdin_stream, STDIN_FILENO, "r", "stdin", &new_stream)) {
+				stdin_stream = new_stream;
+				setlinebuf(stdin_stream);
 			} else
 				cmd->linebuffer = NULL;	/* Leave buffer in place (deliberate leak) */
 		}
@@ -1850,9 +1854,9 @@ void destroy_toolcontext(struct cmd_cont
 		if (is_valid_fd(STDOUT_FILENO) &&
 		    ((flags = fcntl(STDOUT_FILENO, F_GETFL)) > 0) &&
 		    (flags & O_ACCMODE) != O_RDONLY) {
-			if (_reopen_stream(stdout, STDOUT_FILENO, "w", "stdout", &new_stream)) {
-				stdout = new_stream;
-				setlinebuf(stdout);
+			if (_reopen_stream(stdout_stream, STDOUT_FILENO, "w", "stdout", &new_stream)) {
+				stdout_stream = new_stream;
+				setlinebuf(stdout_stream);
 			} else
 				cmd->linebuffer = NULL;	/* Leave buffer in place (deliberate leak) */
 		}