From e3bb1532741cd8cdf542fe4e70020679987c5ee8 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sat, 10 Apr 2021 13:04:49 +0200 Subject: [PATCH] gpu/internal/convertshaders: don't wait for winepath to exit Apparently, exec.Command.Output waits for winepath's grandchildren to exit. However, that may take several seconds if wineserver was started by winepath. exec.Command.StdoutPipe works better, in that it is closed when the winepath process exits. A similar change may help run the fxc.exe tool under Wine, if that ever turns out to have the same problem. Signed-off-by: Elias Naur --- gpu/internal/convertshaders/hlsl.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/gpu/internal/convertshaders/hlsl.go b/gpu/internal/convertshaders/hlsl.go index 9ccefdb5..107fa271 100644 --- a/gpu/internal/convertshaders/hlsl.go +++ b/gpu/internal/convertshaders/hlsl.go @@ -3,7 +3,9 @@ package main import ( + "bytes" "fmt" + "io" "io/ioutil" "os/exec" "path/filepath" @@ -121,11 +123,20 @@ func winepath(paths ...*string) error { for _, path := range paths { winepath.Args = append(winepath.Args, *path) } - out, err := winepath.Output() + // Use a pipe instead of Output, because winepath may have left wineserver + // running for several seconds as a grandchild. + out, err := winepath.StdoutPipe() if err != nil { - return fmt.Errorf("unable to run `winepath --windows`: %w", err) + return fmt.Errorf("unable to start winepath: %w", err) } - winPaths := strings.Split(strings.TrimSpace(string(out)), "\n") + if err := winepath.Start(); err != nil { + return fmt.Errorf("unable to start winepath: %w", err) + } + var buf bytes.Buffer + if _, err := io.Copy(&buf, out); err != nil { + return fmt.Errorf("unable to run winepath: %w", err) + } + winPaths := strings.Split(strings.TrimSpace(buf.String()), "\n") for i, path := range paths { *path = winPaths[i] }