ash_remove_unnecessary_code_in_backquote_expansion.patch 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. From: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
  2. Date: Thu, 19 Apr 2018 18:16:12 +0800
  3. > ash originally had support for omitting the fork when expanding a
  4. > builtin in backquotes. dash has gradually been removing this support,
  5. > most recently in commit 66b614e29038e31745c4a5d296f64f8d64f5c377
  6. > ("[EVAL] Remove unused EV_BACKCMD flag").
  7. >
  8. > Some traces still remain, however. Remove:
  9. >
  10. > - the buf and nleft elements of the backcmd structure;
  11. > - a misleading comment regarding handling of builtins.
  12. >
  13. > Signed-off-by: Ron Yorston <rmy@xxxxxxxxxxxx>
  14. Unfortunately we may need this at some point in the future due
  15. to changes in POSIX. So let's keep it around for now until we
  16. get things such as `jobs -p` to work.
  17. *************************************
  18. From: Ron Yorston <rmy@xxxxxxxxxxxx>
  19. Date: Thu, 19 Apr 2018 17:18:47 +0100
  20. >Unfortunately we may need this at some point in the future due
  21. >to changes in POSIX. So let's keep it around for now until we
  22. >get things such as `jobs -p` to work.
  23. As you wish.
  24. Something even more trivial I noticed later: the TRACE at the end of
  25. expbackq incorrectly refers to the function as evalbackq.
  26. *************************************
  27. Date: Tue, 10 Apr 2018 13:23:35 +0100
  28. From: Ron Yorston <rmy@pobox.com>
  29. To: busybox@busybox.net
  30. Subject: [PATCH] ash: remove unnecessary code in backquote expansion
  31. Some traces remain of ash's ancient support for omitting the fork when
  32. expanding a builtin command in backquotes.
  33. Remove:
  34. - the buf and nleft elements of the backcmd structure;
  35. - a misleading comment regarding handling of builtins.
  36. I've submitted a similar patch to dash.
  37. Signed-off-by: Ron Yorston <rmy@pobox.com>
  38. ---
  39. shell/ash.c | 37 +++++++++----------------------------
  40. 1 file changed, 9 insertions(+), 28 deletions(-)
  41. diff --git a/shell/ash.c b/shell/ash.c
  42. index 45c747dbc..6f1458722 100644
  43. --- a/shell/ash.c
  44. +++ b/shell/ash.c
  45. @@ -6356,15 +6356,12 @@ exptilde(char *startp, char *p, int flags)
  46. }
  47. /*
  48. - * Execute a command inside back quotes. If it's a builtin command, we
  49. - * want to save its output in a block obtained from malloc. Otherwise
  50. - * we fork off a subprocess and get the output of the command via a pipe.
  51. - * Should be called with interrupts off.
  52. + * Execute a command inside back quotes. We fork off a subprocess and
  53. + * get the output of the command via a pipe. Should be called with
  54. + * interrupts off.
  55. */
  56. struct backcmd { /* result of evalbackcmd */
  57. int fd; /* file descriptor to read from */
  58. - int nleft; /* number of chars in buffer */
  59. - char *buf; /* buffer */
  60. struct job *jp; /* job structure for command */
  61. };
  62. @@ -6394,8 +6391,6 @@ evalbackcmd(union node *n, struct backcmd *result)
  63. struct job *jp;
  64. result->fd = -1;
  65. - result->buf = NULL;
  66. - result->nleft = 0;
  67. result->jp = NULL;
  68. if (n == NULL) {
  69. goto out;
  70. @@ -6432,8 +6427,7 @@ evalbackcmd(union node *n, struct backcmd *result)
  71. result->jp = jp;
  72. out:
  73. - TRACE(("evalbackcmd done: fd=%d buf=0x%x nleft=%d jp=0x%x\n",
  74. - result->fd, result->buf, result->nleft, result->jp));
  75. + TRACE(("evalbackcmd done: fd=%d jp=0x%x\n", result->fd, result->jp));
  76. }
  77. /*
  78. @@ -6445,7 +6439,6 @@ expbackq(union node *cmd, int flag)
  79. struct backcmd in;
  80. int i;
  81. char buf[128];
  82. - char *p;
  83. char *dest;
  84. int startloc;
  85. int syntax = flag & EXP_QUOTED ? DQSYNTAX : BASESYNTAX;
  86. @@ -6457,24 +6450,12 @@ expbackq(union node *cmd, int flag)
  87. evalbackcmd(cmd, &in);
  88. popstackmark(&smark);
  89. - p = in.buf;
  90. - i = in.nleft;
  91. - if (i == 0)
  92. - goto read;
  93. - for (;;) {
  94. - memtodest(p, i, syntax, flag & QUOTES_ESC);
  95. - read:
  96. - if (in.fd < 0)
  97. - break;
  98. - i = nonblock_immune_read(in.fd, buf, sizeof(buf));
  99. - TRACE(("expbackq: read returns %d\n", i));
  100. - if (i <= 0)
  101. - break;
  102. - p = buf;
  103. - }
  104. -
  105. - free(in.buf);
  106. if (in.fd >= 0) {
  107. + while ((i = nonblock_immune_read(in.fd, buf, sizeof(buf))) > 0) {
  108. + TRACE(("expbackq: read returns %d\n", i));
  109. + memtodest(buf, i, syntax, flag & QUOTES_ESC);
  110. + }
  111. +
  112. close(in.fd);
  113. back_exitstatus = waitforjob(in.jp);
  114. }