Skip to content

Commit

Permalink
Log gvproxy and server9 to file on log-level=debug
Browse files Browse the repository at this point in the history
Logging to os.Stdout and os.Stderr does not seem to work in
Powershell. I am not entirely certain why.

Logfiles are the best alternative I can think of.

Signed-off-by: Matt Heon <[email protected]>
  • Loading branch information
mheon committed Oct 31, 2023
1 parent d9c388e commit 7153124
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
12 changes: 4 additions & 8 deletions cmd/podman/machine/client9p.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,12 @@ func client9p(portNum uint32, mountPath string) error {
cmd := exec.Command("mount", "-t", "9p", "-o", "trans=fd,rfdno=3,wfdno=3,version=9p2000.L", "9p", mountPath)
cmd.ExtraFiles = []*os.File{vsock}

err := cmd.Run()
output, outErr := cmd.CombinedOutput()
switch {
case outErr != nil:
logrus.Errorf("Unable to obtain output of mount command: %v", err)
case err == nil:
output, err := cmd.CombinedOutput()
if err != nil {
err = fmt.Errorf("running mount: %w\nOutput: %s", err, string(output))
} else {
logrus.Debugf("Mount output: %s", string(output))
logrus.Infof("Mounted directory %s using 9p", mountPath)
default:
err = fmt.Errorf("running mount: %w\nOutput: %s", err, string(output))
}

errChan <- err
Expand Down
29 changes: 25 additions & 4 deletions pkg/machine/hyperv/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,9 @@ func (m *HyperVMachine) startHostNetworking() (string, machine.APIForwardingStat
c := cmd.Cmd(gvproxyBinary)

if logrus.IsLevelEnabled(logrus.DebugLevel) {
c.Stdout = os.Stdout
c.Stderr = os.Stderr
if err := logCommandToFile(c, "gvproxy.log"); err != nil {
return "", 0, err
}
}

logrus.Debugf("Starting gvproxy with command: %s %v", gvproxyBinary, c.Args)
Expand Down Expand Up @@ -809,8 +810,9 @@ func (m *HyperVMachine) startHostNetworking() (string, machine.APIForwardingStat
fsCmd := exec.Command(executable, args...)

if logrus.IsLevelEnabled(logrus.DebugLevel) {
fsCmd.Stdout = os.Stdout
fsCmd.Stderr = os.Stderr
if err := logCommandToFile(fsCmd, "podman-machine-server9.log"); err != nil {
return "", 0, err
}
}

if err := fsCmd.Start(); err != nil {
Expand All @@ -822,6 +824,25 @@ func (m *HyperVMachine) startHostNetworking() (string, machine.APIForwardingStat
return forwardSock, state, nil
}

func logCommandToFile(c *exec.Cmd, filename string) error {
dir, err := machine.GetDataDir(machine.HyperVVirt)
if err != nil {
return fmt.Errorf("obtain machine dir: %w", err)
}
path := filepath.Join(dir, filename)
logrus.Infof("Going to log to %s", path)
log, err := os.Create(path)
if err != nil {
return fmt.Errorf("create log file: %w", err)
}
defer log.Close()

c.Stdout = log
c.Stderr = log

return nil
}

func (m *HyperVMachine) setupAPIForwarding(cmd gvproxy.GvproxyCommand) (gvproxy.GvproxyCommand, string, machine.APIForwardingState) {
socket, err := m.forwardSocketPath()
if err != nil {
Expand Down

0 comments on commit 7153124

Please sign in to comment.