mirror of
https://github.com/containers/podman.git
synced 2025-06-28 06:18:57 +08:00
Expose Podman named pipe in Inspect output
Signed-off-by: Arthur Sengileyev <arthur.sengileyev@gmail.com>
This commit is contained in:
@ -373,4 +373,6 @@ type SSHConfig struct {
|
|||||||
type ConnectionConfig struct {
|
type ConnectionConfig struct {
|
||||||
// PodmanSocket is the exported podman service socket
|
// PodmanSocket is the exported podman service socket
|
||||||
PodmanSocket *VMFile `json:"PodmanSocket"`
|
PodmanSocket *VMFile `json:"PodmanSocket"`
|
||||||
|
// PodmanPipe is the exported podman service named pipe (Windows hosts only)
|
||||||
|
PodmanPipe *VMFile `json:"PodmanPipe"`
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,9 @@
|
|||||||
package machine
|
package machine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetProcessState(pid int) (active bool, exitCode int) {
|
func GetProcessState(pid int) (active bool, exitCode int) {
|
||||||
@ -18,3 +20,24 @@ func GetProcessState(pid int) (active bool, exitCode int) {
|
|||||||
syscall.GetExitCodeProcess(handle, &code)
|
syscall.GetExitCodeProcess(handle, &code)
|
||||||
return code == 259, int(code)
|
return code == 259, int(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PipeNameAvailable(pipeName string) bool {
|
||||||
|
_, err := os.Stat(`\\.\pipe\` + pipeName)
|
||||||
|
return os.IsNotExist(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func WaitPipeExists(pipeName string, retries int, checkFailure func() error) error {
|
||||||
|
var err error
|
||||||
|
for i := 0; i < retries; i++ {
|
||||||
|
_, err = os.Stat(`\\.\pipe\` + pipeName)
|
||||||
|
if err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if fail := checkFailure(); fail != nil {
|
||||||
|
return fail
|
||||||
|
}
|
||||||
|
time.Sleep(250 * time.Millisecond)
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
@ -1053,12 +1053,12 @@ func (v *MachineVM) Start(name string, opts machine.StartOptions) error {
|
|||||||
|
|
||||||
func launchWinProxy(v *MachineVM) (bool, string, error) {
|
func launchWinProxy(v *MachineVM) (bool, string, error) {
|
||||||
machinePipe := toDist(v.Name)
|
machinePipe := toDist(v.Name)
|
||||||
if !pipeAvailable(machinePipe) {
|
if !machine.PipeNameAvailable(machinePipe) {
|
||||||
return false, "", fmt.Errorf("could not start api proxy since expected pipe is not available: %s", machinePipe)
|
return false, "", fmt.Errorf("could not start api proxy since expected pipe is not available: %s", machinePipe)
|
||||||
}
|
}
|
||||||
|
|
||||||
globalName := false
|
globalName := false
|
||||||
if pipeAvailable(globalPipe) {
|
if machine.PipeNameAvailable(globalPipe) {
|
||||||
globalName = true
|
globalName = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1099,7 +1099,7 @@ func launchWinProxy(v *MachineVM) (bool, string, error) {
|
|||||||
return globalName, "", err
|
return globalName, "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return globalName, pipePrefix + waitPipe, waitPipeExists(waitPipe, 80, func() error {
|
return globalName, pipePrefix + waitPipe, machine.WaitPipeExists(waitPipe, 80, func() error {
|
||||||
active, exitCode := machine.GetProcessState(cmd.Process.Pid)
|
active, exitCode := machine.GetProcessState(cmd.Process.Pid)
|
||||||
if !active {
|
if !active {
|
||||||
return fmt.Errorf("win-sshproxy.exe failed to start, exit code: %d (see windows event logs)", exitCode)
|
return fmt.Errorf("win-sshproxy.exe failed to start, exit code: %d (see windows event logs)", exitCode)
|
||||||
@ -1122,27 +1122,6 @@ func getWinProxyStateDir(v *MachineVM) (string, error) {
|
|||||||
return stateDir, nil
|
return stateDir, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func pipeAvailable(pipeName string) bool {
|
|
||||||
_, err := os.Stat(`\\.\pipe\` + pipeName)
|
|
||||||
return os.IsNotExist(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func waitPipeExists(pipeName string, retries int, checkFailure func() error) error {
|
|
||||||
var err error
|
|
||||||
for i := 0; i < retries; i++ {
|
|
||||||
_, err = os.Stat(`\\.\pipe\` + pipeName)
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if fail := checkFailure(); fail != nil {
|
|
||||||
return fail
|
|
||||||
}
|
|
||||||
time.Sleep(250 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func IsWSLInstalled() bool {
|
func IsWSLInstalled() bool {
|
||||||
cmd := SilentExecCmd("wsl", "--status")
|
cmd := SilentExecCmd("wsl", "--status")
|
||||||
out, err := cmd.StdoutPipe()
|
out, err := cmd.StdoutPipe()
|
||||||
@ -1611,10 +1590,14 @@ func (v *MachineVM) Inspect() (*machine.InspectInfo, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
created, lastUp, _ := v.updateTimeStamps(state == machine.Running)
|
connInfo := new(machine.ConnectionConfig)
|
||||||
|
machinePipe := toDist(v.Name)
|
||||||
|
connInfo.PodmanPipe = &machine.VMFile{Path: `\\.\pipe\` + machinePipe}
|
||||||
|
|
||||||
|
created, lastUp, _ := v.updateTimeStamps(state == machine.Running)
|
||||||
return &machine.InspectInfo{
|
return &machine.InspectInfo{
|
||||||
ConfigPath: machine.VMFile{Path: v.ConfigPath},
|
ConfigPath: machine.VMFile{Path: v.ConfigPath},
|
||||||
|
ConnectionInfo: *connInfo,
|
||||||
Created: created,
|
Created: created,
|
||||||
Image: machine.ImageConfig{
|
Image: machine.ImageConfig{
|
||||||
ImagePath: machine.VMFile{Path: v.ImagePath},
|
ImagePath: machine.VMFile{Path: v.ImagePath},
|
||||||
|
Reference in New Issue
Block a user