forked from containers/podman
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved Windows compatibility for machine command
Signed-off-by: Arthur Sengileyev <[email protected]>
- Loading branch information
Showing
8 changed files
with
101 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package machine | ||
|
||
import ( | ||
"syscall" | ||
) | ||
|
||
func GetProcessState(pid int) (active bool, exitCode int) { | ||
const da = syscall.STANDARD_RIGHTS_READ | syscall.PROCESS_QUERY_INFORMATION | syscall.SYNCHRONIZE | ||
handle, err := syscall.OpenProcess(da, false, uint32(pid)) | ||
if err != nil { | ||
return false, int(syscall.ERROR_PROC_NOT_FOUND) | ||
} | ||
|
||
var code uint32 | ||
syscall.GetExitCodeProcess(handle, &code) | ||
return code == 259, int(code) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd | ||
// +build darwin 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//go:build (!amd64 && !arm64) || windows | ||
// +build !amd64,!arm64 windows | ||
//go:build (!amd64 && !arm64) | ||
// +build !amd64,!arm64 | ||
|
||
package qemu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package qemu | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
|
||
"github.com/containers/podman/v4/pkg/machine" | ||
) | ||
|
||
func isProcessAlive(pid int) bool { | ||
if checkProcessStatus("process", pid, nil) == nil { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
func checkProcessStatus(processHint string, pid int, stderrBuf *bytes.Buffer) error { | ||
active, exitCode := machine.GetProcessState(pid) | ||
if !active { | ||
if stderrBuf != nil { | ||
return fmt.Errorf("%s exited unexpectedly, exit code: %d stderr: %s", processHint, exitCode, stderrBuf.String()) | ||
} else { | ||
return fmt.Errorf("%s exited unexpectedly, exit code: %d", processHint, exitCode) | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package qemu | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
func getRuntimeDir() (string, error) { | ||
tmpDir, ok := os.LookupEnv("TEMP") | ||
if !ok { | ||
tmpDir = os.Getenv("LOCALAPPDATA") + "\\Temp" | ||
} | ||
return tmpDir, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters