0005-bash50-005.patch 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. From https://ftp.gnu.org/gnu/bash/bash-5.0-patches/bash50-005
  2. Signed-off-by: Pascal de Bruijn <p.debruijn@unilogic.nl>
  3. BASH PATCH REPORT
  4. =================
  5. Bash-Release: 5.0
  6. Patch-ID: bash50-005
  7. Bug-Reported-by: Brad Spencer <bspencer@blackberry.com>
  8. Bug-Reference-ID: <1b993ff2-ce4f-662a-6be4-393457362e47@blackberry.com>
  9. Bug-Reference-URL: http://lists.gnu.org/archive/html/bug-bash/2019-01/msg00250.html
  10. Bug-Description:
  11. In certain cases, bash optimizes out a fork() call too early and prevents
  12. traps from running.
  13. Patch (apply with `patch -p0'):
  14. *** ../bash-5.0-patched/command.h 2018-07-20 21:16:31.000000000 -0400
  15. --- b/command.h 2019-02-20 11:09:36.000000000 -0500
  16. ***************
  17. *** 187,190 ****
  18. --- 188,192 ----
  19. #define CMD_LASTPIPE 0x2000
  20. #define CMD_STDPATH 0x4000 /* use standard path for command lookup */
  21. + #define CMD_TRY_OPTIMIZING 0x8000 /* try to optimize this simple command */
  22. /* What a command looks like. */
  23. *** ../bash-5.0-patched/builtins/evalstring.c 2018-12-26 11:19:21.000000000 -0500
  24. --- b/builtins/evalstring.c 2019-01-29 14:15:19.000000000 -0500
  25. ***************
  26. *** 101,104 ****
  27. --- 101,113 ----
  28. }
  29. + int
  30. + can_optimize_connection (command)
  31. + COMMAND *command;
  32. + {
  33. + return (*bash_input.location.string == '\0' &&
  34. + (command->value.Connection->connector == AND_AND || command->value.Connection->connector == OR_OR || command->value.Connection->connector == ';') &&
  35. + command->value.Connection->second->type == cm_simple);
  36. + }
  37. +
  38. void
  39. optimize_fork (command)
  40. ***************
  41. *** 106,110 ****
  42. {
  43. if (command->type == cm_connection &&
  44. ! (command->value.Connection->connector == AND_AND || command->value.Connection->connector == OR_OR) &&
  45. should_suppress_fork (command->value.Connection->second))
  46. {
  47. --- 115,120 ----
  48. {
  49. if (command->type == cm_connection &&
  50. ! (command->value.Connection->connector == AND_AND || command->value.Connection->connector == OR_OR || command->value.Connection->connector == ';') &&
  51. ! (command->value.Connection->second->flags & CMD_TRY_OPTIMIZING) &&
  52. should_suppress_fork (command->value.Connection->second))
  53. {
  54. ***************
  55. *** 413,418 ****
  56. command->value.Simple->flags |= CMD_NO_FORK;
  57. }
  58. ! else if (command->type == cm_connection)
  59. ! optimize_fork (command);
  60. #endif /* ONESHOT */
  61. --- 423,438 ----
  62. command->value.Simple->flags |= CMD_NO_FORK;
  63. }
  64. !
  65. ! /* Can't optimize forks out here execept for simple commands.
  66. ! This knows that the parser sets up commands as left-side heavy
  67. ! (&& and || are left-associative) and after the single parse,
  68. ! if we are at the end of the command string, the last in a
  69. ! series of connection commands is
  70. ! command->value.Connection->second. */
  71. ! else if (command->type == cm_connection && can_optimize_connection (command))
  72. ! {
  73. ! command->value.Connection->second->flags |= CMD_TRY_OPTIMIZING;
  74. ! command->value.Connection->second->value.Simple->flags |= CMD_TRY_OPTIMIZING;
  75. ! }
  76. #endif /* ONESHOT */
  77. *** ../bash-5.0-patched/execute_cmd.c 2018-12-05 09:05:14.000000000 -0500
  78. --- b/execute_cmd.c 2019-01-25 15:59:00.000000000 -0500
  79. ***************
  80. *** 2768,2771 ****
  81. --- 2768,2773 ----
  82. (exec_result != EXECUTION_SUCCESS)))
  83. {
  84. + optimize_fork (command);
  85. +
  86. second = command->value.Connection->second;
  87. if (ignore_return && second)
  88. *** ../bash-5.0/patchlevel.h 2016-06-22 14:51:03.000000000 -0400
  89. --- b/patchlevel.h 2016-10-01 11:01:28.000000000 -0400
  90. ***************
  91. *** 26,30 ****
  92. looks for to find the patch level (for the sccs version string). */
  93. ! #define PATCHLEVEL 4
  94. #endif /* _PATCHLEVEL_H_ */
  95. --- 26,30 ----
  96. looks for to find the patch level (for the sccs version string). */
  97. ! #define PATCHLEVEL 5
  98. #endif /* _PATCHLEVEL_H_ */