Skip to content

Commit 2588b96

Browse files
committed
Fix logging podman machine server9 output
Command `podman machine init` for Hyper-V machines invokes the command `podman machine server9` and redirects it's output to a file. But the file descriptor was closed before beeing used and the output file was always empty. Signed-off-by: Mario Loriedo <[email protected]>
1 parent d03d994 commit 2588b96

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pkg/machine/hyperv/stubber.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,11 @@ func (h HyperVStubber) PostStartNetworking(mc *vmconfigs.MachineConfig, noInfo b
420420
fsCmd := exec.Command(executable, p9ServerArgs...)
421421

422422
if logrus.IsLevelEnabled(logrus.DebugLevel) {
423-
err = logCommandToFile(fsCmd, "podman-machine-server9.log")
423+
log, err := logCommandToFile(fsCmd, "podman-machine-server9.log")
424424
if err != nil {
425425
return err
426426
}
427+
defer log.Close()
427428
}
428429

429430
err = fsCmd.Start()
@@ -501,23 +502,22 @@ func removeIgnitionFromRegistry(vm *hypervctl.VirtualMachine) error {
501502
return nil
502503
}
503504

504-
func logCommandToFile(c *exec.Cmd, filename string) error {
505+
func logCommandToFile(c *exec.Cmd, filename string) (*os.File, error) {
505506
dir, err := env.GetDataDir(define.HyperVVirt)
506507
if err != nil {
507-
return fmt.Errorf("obtain machine dir: %w", err)
508+
return nil, fmt.Errorf("obtain machine dir: %w", err)
508509
}
509510
path := filepath.Join(dir, filename)
510511
logrus.Infof("Going to log to %s", path)
511512
log, err := os.Create(path)
512513
if err != nil {
513-
return fmt.Errorf("create log file: %w", err)
514+
return nil, fmt.Errorf("create log file: %w", err)
514515
}
515-
defer log.Close()
516516

517517
c.Stdout = log
518518
c.Stderr = log
519519

520-
return nil
520+
return log, nil
521521
}
522522

523523
const hyperVVsockNMConnection = `

0 commit comments

Comments
 (0)