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.106.orig/lib/commands/toolcontext.c 2014-04-10 17:38:44.000000000 +0200
+++ LVM2.2.02.106/lib/commands/toolcontext.c 2014-05-29 17:55:05.101305501 +0200
@@ -1334,6 +1334,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
@@ -1383,10 +1385,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;
}
@@ -1395,10 +1397,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;
@@ -1681,6 +1683,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 &&
@@ -1717,9 +1721,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) */
}
@@ -1727,9 +1731,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) */
}
|