[engine] Simplify subprocess running code
Separate calls to Start() and Wait() can be collapsed into Run().
Change-Id: I89cb2324d2210617914aeb3f88ff6978d9f8eb49
Reviewed-on: https://fuchsia-review.googlesource.com/c/shac-project/shac/+/930375
Commit-Queue: Auto-Submit <auto-submit@fuchsia-infra.iam.gserviceaccount.com>
Reviewed-by: Ina Huh <ihuh@google.com>
Fuchsia-Auto-Submit: Oliver Newman <olivernewman@google.com>
diff --git a/internal/engine/runtime_ctx_os.go b/internal/engine/runtime_ctx_os.go
index 6a68f11..e6c7ea1 100644
--- a/internal/engine/runtime_ctx_os.go
+++ b/internal/engine/runtime_ctx_os.go
@@ -401,17 +401,16 @@
cmd.Stdin = stdin
errs := make(chan error, 1)
+ // Run the command in a non-blocking goroutine so exec() calls don't block
+ // if there's already the maximum number of subprocesses running. wait()
+ // will block until the subprocess starts *and* finishes.
go func() {
errs <- func() error {
if err := s.subprocessSem.Acquire(ctx, 1); err != nil {
return err
}
defer s.subprocessSem.Release(1)
-
- if err := execsupport.Start(cmd); err != nil {
- return err
- }
- return cmd.Wait()
+ return execsupport.Run(cmd)
}()
// Signals to subprocess.wait() that the subprocess is done, whether or
// not it was successful.