aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Porter2024-05-25 13:46:24 -0700
committerJim Porter2024-05-25 13:46:24 -0700
commit57dc1ed665d72bc58befa4853fa479b770fe4fcc (patch)
tree8940f319ceab957830ef5092a6dc888a729f50b0
parent91509d5d2a2dc818830cff63f13d6efcb229dc0c (diff)
downloademacs-57dc1ed665d72bc58befa4853fa479b770fe4fcc.tar.gz
emacs-57dc1ed665d72bc58befa4853fa479b770fe4fcc.zip
Fix a race condition when evaluating Eshell commands
* lisp/eshell/esh-cmd.el (eshell-do-eval): Don't defer when all the processes are done. * test/lisp/eshell/esh-cmd-tests.el (esh-cmd-test/pipeline-wait/nested-pipes): New test.
-rw-r--r--lisp/eshell/esh-cmd.el6
-rw-r--r--test/lisp/eshell/esh-cmd-tests.el12
2 files changed, 16 insertions, 2 deletions
diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el
index dae1a77552f..57aeff59266 100644
--- a/lisp/eshell/esh-cmd.el
+++ b/lisp/eshell/esh-cmd.el
@@ -1287,13 +1287,15 @@ have been replaced by constants."
1287 (setcdr form (cdr new-form))) 1287 (setcdr form (cdr new-form)))
1288 (eshell-do-eval form synchronous-p)) 1288 (eshell-do-eval form synchronous-p))
1289 (if-let (((memq (car form) eshell-deferrable-commands)) 1289 (if-let (((memq (car form) eshell-deferrable-commands))
1290 (procs (eshell-make-process-list result))) 1290 (procs (eshell-make-process-list result))
1291 (active (seq-some #'eshell-process-active-p procs)))
1291 (if synchronous-p 1292 (if synchronous-p
1292 (apply #'eshell/wait procs) 1293 (apply #'eshell/wait procs)
1293 (eshell-manipulate form "inserting ignore form" 1294 (eshell-manipulate form "inserting ignore form"
1294 (setcar form 'ignore) 1295 (setcar form 'ignore)
1295 (setcdr form nil)) 1296 (setcdr form nil))
1296 (throw 'eshell-defer procs)) 1297 (when active
1298 (throw 'eshell-defer procs)))
1297 (list 'quote result)))))))))))) 1299 (list 'quote result))))))))))))
1298 1300
1299;; command invocation 1301;; command invocation
diff --git a/test/lisp/eshell/esh-cmd-tests.el b/test/lisp/eshell/esh-cmd-tests.el
index ef965a896c1..d84f8802bdc 100644
--- a/test/lisp/eshell/esh-cmd-tests.el
+++ b/test/lisp/eshell/esh-cmd-tests.el
@@ -213,6 +213,18 @@ This should also wait for the subcommand."
213 (eshell-match-command-output "echo ${*echo hi | *cat} | *cat" 213 (eshell-match-command-output "echo ${*echo hi | *cat} | *cat"
214 "hi"))) 214 "hi")))
215 215
216(ert-deftest esh-cmd-test/pipeline-wait/nested-pipes ()
217 "Check that piping a subcommand with its own pipe works.
218This should also wait for the subcommand."
219 (skip-unless (and (executable-find "echo")
220 (executable-find "cat")
221 (executable-find "sh")
222 (executable-find "sleep")))
223 (with-temp-eshell
224 (eshell-match-command-output
225 "{ sh -c 'sleep 1; echo goodbye 1>&2' | *echo hello } | *cat"
226 "hello\ngoodbye\n")))
227
216(ert-deftest esh-cmd-test/reset-in-pipeline/subcommand () 228(ert-deftest esh-cmd-test/reset-in-pipeline/subcommand ()
217 "Check that subcommands reset `eshell-in-pipeline-p'." 229 "Check that subcommands reset `eshell-in-pipeline-p'."
218 (skip-unless (executable-find "cat")) 230 (skip-unless (executable-find "cat"))