patch-lib_commands_toolcontext_c 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. --- LVM2.2.02.106.orig/lib/commands/toolcontext.c 2014-04-10 17:38:44.000000000 +0200
  2. +++ LVM2.2.02.106/lib/commands/toolcontext.c 2014-05-29 17:55:05.101305501 +0200
  3. @@ -1334,6 +1334,8 @@ struct cmd_context *create_toolcontext(u
  4. {
  5. struct cmd_context *cmd;
  6. FILE *new_stream;
  7. + FILE *stdin_stream = stdin;
  8. + FILE *stdout_stream = stdout;
  9. int flags;
  10. #ifdef M_MMAP_MAX
  11. @@ -1383,10 +1385,10 @@ struct cmd_context *create_toolcontext(u
  12. if (is_valid_fd(STDIN_FILENO) &&
  13. ((flags = fcntl(STDIN_FILENO, F_GETFL)) > 0) &&
  14. (flags & O_ACCMODE) != O_WRONLY) {
  15. - if (!_reopen_stream(stdin, STDIN_FILENO, "r", "stdin", &new_stream))
  16. + if (!_reopen_stream(stdin_stream, STDIN_FILENO, "r", "stdin", &new_stream))
  17. goto_out;
  18. - stdin = new_stream;
  19. - if (setvbuf(stdin, cmd->linebuffer, _IOLBF, linebuffer_size)) {
  20. + stdin_stream = new_stream;
  21. + if (setvbuf(stdin_stream, cmd->linebuffer, _IOLBF, linebuffer_size)) {
  22. log_sys_error("setvbuf", "");
  23. goto out;
  24. }
  25. @@ -1395,10 +1397,10 @@ struct cmd_context *create_toolcontext(u
  26. if (is_valid_fd(STDOUT_FILENO) &&
  27. ((flags = fcntl(STDOUT_FILENO, F_GETFL)) > 0) &&
  28. (flags & O_ACCMODE) != O_RDONLY) {
  29. - if (!_reopen_stream(stdout, STDOUT_FILENO, "w", "stdout", &new_stream))
  30. + if (!_reopen_stream(stdout_stream, STDOUT_FILENO, "w", "stdout", &new_stream))
  31. goto_out;
  32. - stdout = new_stream;
  33. - if (setvbuf(stdout, cmd->linebuffer + linebuffer_size,
  34. + stdout_stream = new_stream;
  35. + if (setvbuf(stdout_stream, cmd->linebuffer + linebuffer_size,
  36. _IOLBF, linebuffer_size)) {
  37. log_sys_error("setvbuf", "");
  38. goto out;
  39. @@ -1681,6 +1683,8 @@ void destroy_toolcontext(struct cmd_cont
  40. {
  41. struct dm_config_tree *cft_cmdline;
  42. FILE *new_stream;
  43. + FILE *stdin_stream = stdin;
  44. + FILE *stdout_stream = stdout;
  45. int flags;
  46. if (cmd->dump_filter && cmd->filter && cmd->filter->dump &&
  47. @@ -1717,9 +1721,9 @@ void destroy_toolcontext(struct cmd_cont
  48. if (is_valid_fd(STDIN_FILENO) &&
  49. ((flags = fcntl(STDIN_FILENO, F_GETFL)) > 0) &&
  50. (flags & O_ACCMODE) != O_WRONLY) {
  51. - if (_reopen_stream(stdin, STDIN_FILENO, "r", "stdin", &new_stream)) {
  52. - stdin = new_stream;
  53. - setlinebuf(stdin);
  54. + if (_reopen_stream(stdin_stream, STDIN_FILENO, "r", "stdin", &new_stream)) {
  55. + stdin_stream = new_stream;
  56. + setlinebuf(stdin_stream);
  57. } else
  58. cmd->linebuffer = NULL; /* Leave buffer in place (deliberate leak) */
  59. }
  60. @@ -1727,9 +1731,9 @@ void destroy_toolcontext(struct cmd_cont
  61. if (is_valid_fd(STDOUT_FILENO) &&
  62. ((flags = fcntl(STDOUT_FILENO, F_GETFL)) > 0) &&
  63. (flags & O_ACCMODE) != O_RDONLY) {
  64. - if (_reopen_stream(stdout, STDOUT_FILENO, "w", "stdout", &new_stream)) {
  65. - stdout = new_stream;
  66. - setlinebuf(stdout);
  67. + if (_reopen_stream(stdout_stream, STDOUT_FILENO, "w", "stdout", &new_stream)) {
  68. + stdout_stream = new_stream;
  69. + setlinebuf(stdout_stream);
  70. } else
  71. cmd->linebuffer = NULL; /* Leave buffer in place (deliberate leak) */
  72. }