From: Jim Porter Date: Sat, 25 May 2024 20:46:24 +0000 (-0700) Subject: Fix a race condition when evaluating Eshell commands X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b4aae2a191d956e964cda241c332b0ed4cd0fe16;p=emacs.git 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. (cherry picked from commit 57dc1ed665d72bc58befa4853fa479b770fe4fcc) --- 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." (setcdr form (cdr new-form))) (eshell-do-eval form synchronous-p)) (if-let (((memq (car form) eshell-deferrable-commands)) - (procs (eshell-make-process-list result))) + (procs (eshell-make-process-list result)) + (active (seq-some #'eshell-process-active-p procs))) (if synchronous-p (apply #'eshell/wait procs) (eshell-manipulate form "inserting ignore form" (setcar form 'ignore) (setcdr form nil)) - (throw 'eshell-defer procs)) + (when active + (throw 'eshell-defer procs))) (list 'quote result)))))))))))) ;; 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." (eshell-match-command-output "echo ${*echo hi | *cat} | *cat" "hi"))) +(ert-deftest esh-cmd-test/pipeline-wait/nested-pipes () + "Check that piping a subcommand with its own pipe works. +This should also wait for the subcommand." + (skip-unless (and (executable-find "echo") + (executable-find "cat") + (executable-find "sh") + (executable-find "sleep"))) + (with-temp-eshell + (eshell-match-command-output + "{ sh -c 'sleep 1; echo goodbye 1>&2' | *echo hello } | *cat" + "hello\ngoodbye\n"))) + (ert-deftest esh-cmd-test/reset-in-pipeline/subcommand () "Check that subcommands reset `eshell-in-pipeline-p'." (skip-unless (executable-find "cat"))