mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00

When gvproxy exits it will delete the pidfile itself so we need to account for that and juts ignore the case, it just means gvproxy was able to exit successfully on its own. Also remove the useless defer and return the error so we can get an error exit code not just a print on stderr. Currently it shows this error which is not helpful to any user: unable to clean up gvproxy: "unable to read gvproxy pid file /run/user/1000/podman/gvproxy.pid: open /run/user/1000/podman/gvproxy.pid: no such file or directory" [NO NEW TESTS NEEDED] TODO: make machine tests check stderr for such things. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
32 lines
747 B
Go
32 lines
747 B
Go
package machine
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"io/fs"
|
|
"strconv"
|
|
|
|
"github.com/containers/podman/v5/pkg/machine/define"
|
|
)
|
|
|
|
// CleanupGVProxy reads the --pid-file for gvproxy attempts to stop it
|
|
func CleanupGVProxy(f define.VMFile) error {
|
|
gvPid, err := f.Read()
|
|
if err != nil {
|
|
// The file will also be removed by gvproxy when it exits so
|
|
// we need to account for the race and can just ignore it here.
|
|
if errors.Is(err, fs.ErrNotExist) {
|
|
return nil
|
|
}
|
|
return fmt.Errorf("unable to read gvproxy pid file: %v", err)
|
|
}
|
|
proxyPid, err := strconv.Atoi(string(gvPid))
|
|
if err != nil {
|
|
return fmt.Errorf("unable to convert pid to integer: %v", err)
|
|
}
|
|
if err := waitOnProcess(proxyPid); err != nil {
|
|
return err
|
|
}
|
|
return f.Delete()
|
|
}
|