--- 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) */ }