From b95bd5f9ef9ee7223ac8e6e65dd56e41b9825d8a Mon Sep 17 00:00:00 2001 From: Bella Khizgiyaev Date: Mon, 20 May 2024 12:48:12 +0300 Subject: [PATCH] close the shared pipe so the virt-v2v commad will finish. Signed-off-by: Bella Khizgiyaev --- cmd/virt-v2v-monitor/virt-v2v-monitor.go | 2 ++ virt-v2v/cold/entrypoint.go | 43 +++++++++++++++--------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/cmd/virt-v2v-monitor/virt-v2v-monitor.go b/cmd/virt-v2v-monitor/virt-v2v-monitor.go index 43b4dd45e..5e4a8fbf2 100644 --- a/cmd/virt-v2v-monitor/virt-v2v-monitor.go +++ b/cmd/virt-v2v-monitor/virt-v2v-monitor.go @@ -91,6 +91,7 @@ func main() { err := scanner.Err() if err != nil { fmt.Println("virt-v2v monitoring: Output monitoring failed! ", err) + os.Exit(1) } if match := COPY_DISK_RE.FindSubmatch(line); match != nil { @@ -120,5 +121,6 @@ func main() { err := scanner.Err() if err != nil { fmt.Println("virt-v2v monitoring: Output monitoring failed! ", err) + os.Exit(1) } } diff --git a/virt-v2v/cold/entrypoint.go b/virt-v2v/cold/entrypoint.go index be2a37667..2b74eb345 100644 --- a/virt-v2v/cold/entrypoint.go +++ b/virt-v2v/cold/entrypoint.go @@ -207,36 +207,47 @@ func executeVirtV2v(source string, args []string) (err error) { virtV2vMonitorCmd := exec.Command("/usr/local/bin/virt-v2v-monitor") virtV2vMonitorCmd.Stdin = r virtV2vMonitorCmd.Stdout = os.Stdout + virtV2vMonitorCmd.Stderr = os.Stderr if err = virtV2vMonitorCmd.Start(); err != nil { fmt.Printf("Error executing monitor command: %v\n", err) return } - if source == OVA { - scanner := bufio.NewScanner(r) - const maxCapacity = 1024 * 1024 - buf := make([]byte, 0, 64*1024) - scanner.Buffer(buf, maxCapacity) - - for scanner.Scan() { - line := scanner.Bytes() - if match := UEFI_RE.FindSubmatch(line); match != nil { - fmt.Println("UEFI firmware detected") - firmware = "efi" + done := make(chan error, 1) + go func() { + if source == OVA { + scanner := bufio.NewScanner(r) + const maxCapacity = 1024 * 1024 + buf := make([]byte, 0, 64*1024) + scanner.Buffer(buf, maxCapacity) + + for scanner.Scan() { + line := scanner.Bytes() + if match := UEFI_RE.FindSubmatch(line); match != nil { + fmt.Println("UEFI firmware detected") + firmware = "efi" + } } - } - if err = scanner.Err(); err != nil { - fmt.Println("Output query failed:", err) - return err + if err := scanner.Err(); err != nil { + fmt.Println("Output query failed:", err) + done <- err + return + } } - } + done <- nil + }() if err = virtV2vCmd.Wait(); err != nil { fmt.Printf("Error waiting for virt-v2v to finish: %v\n", err) return } + w.Close() + + if err = <-done; err != nil { + return err + } return }