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

The following PR is the leading PR for refactoring podman machine with the following goals: * less duplication/more re-use * common configuration file between providers * more consistentency in how machines are handled by providers The goal of this PR is the rough refactor. There are still rough spots for sure, specifically around the podman socket and pipe. This implemention is only for Linux. All other providers are still present but will not compile or work. This is why tests for them have been temporarily suspended. The ready socket code is another area that needs to be smoothed over. Right now, the ready socket code is still in QEMU. Preferably it would be moved to a generic spot where all three approaches to readiness socket use can be defined. It should also be noted: * all machine related tests pass. * make validate for Linux passes * Apple QEMU was largely removed * More code pruning is possible; will become clearer when other providers are complete. the dir pkg/machine/p5 is not permanent. i had to seperate this from machine initially due to circular import problems. i think when all providers are done (or nearly done), it can be placed and named properly. Signed-off-by: Brent Baude <bbaude@redhat.com>
47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
//go:build dragonfly || freebsd || linux || netbsd || openbsd
|
|
|
|
package qemu
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"syscall"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
func isProcessAlive(pid int) bool {
|
|
err := unix.Kill(pid, syscall.Signal(0))
|
|
if err == nil || err == unix.EPERM {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func checkProcessStatus(processHint string, pid int, stderrBuf *bytes.Buffer) error {
|
|
var status syscall.WaitStatus
|
|
pid, err := syscall.Wait4(pid, &status, syscall.WNOHANG, nil)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to read qem%su process status: %w", processHint, err)
|
|
}
|
|
if pid > 0 {
|
|
// child exited
|
|
return fmt.Errorf("%s exited unexpectedly with exit code %d, stderr: %s", processHint, status.ExitStatus(), stderrBuf.String())
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func sigKill(pid int) error {
|
|
return unix.Kill(pid, unix.SIGKILL)
|
|
}
|
|
|
|
func findProcess(pid int) (int, error) {
|
|
if err := unix.Kill(pid, 0); err != nil {
|
|
if err == unix.ESRCH {
|
|
return -1, nil
|
|
}
|
|
return -1, fmt.Errorf("pinging QEMU process: %w", err)
|
|
}
|
|
return pid, nil
|
|
}
|