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.
Merge pull request containers#21597 from n1hility/wsl-refactor
Complete WSL implementation in Podman 5
- Loading branch information
Showing
52 changed files
with
2,551 additions
and
1,245 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
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
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
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
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
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,41 @@ | ||
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd | ||
|
||
package machine | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"syscall" | ||
|
||
psutil "github.com/shirou/gopsutil/v3/process" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// / waitOnProcess takes a pid and sends a sigterm to it. it then waits for the | ||
// process to not exist. if the sigterm does not end the process after an interval, | ||
// then sigkill is sent. it also waits for the process to exit after the sigkill too. | ||
func waitOnProcess(processID int) error { | ||
logrus.Infof("Going to stop gvproxy (PID %d)", processID) | ||
|
||
p, err := psutil.NewProcess(int32(processID)) | ||
if err != nil { | ||
return fmt.Errorf("looking up PID %d: %w", processID, err) | ||
} | ||
|
||
running, err := p.IsRunning() | ||
if err != nil { | ||
return fmt.Errorf("checking if gvproxy is running: %w", err) | ||
} | ||
if !running { | ||
return nil | ||
} | ||
|
||
if err := p.Kill(); err != nil { | ||
if errors.Is(err, syscall.ESRCH) { | ||
logrus.Debugf("Gvproxy already dead, exiting cleanly") | ||
return nil | ||
} | ||
return err | ||
} | ||
return backoffForProcess(p) | ||
} |
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,45 @@ | ||
package machine | ||
|
||
import ( | ||
"os" | ||
"time" | ||
|
||
"github.com/containers/winquit/pkg/winquit" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func waitOnProcess(processID int) error { | ||
logrus.Infof("Going to stop gvproxy (PID %d)", processID) | ||
|
||
p, err := os.FindProcess(processID) | ||
if err != nil { | ||
// FindProcess on Windows will return an error when the process is not found | ||
// if a process can not be found then it has already exited and there is | ||
// nothing left to do, so return without error | ||
return nil | ||
} | ||
|
||
// Gracefully quit and force kill after 30 seconds | ||
if err := winquit.QuitProcess(processID, 30*time.Second); err != nil { | ||
return err | ||
} | ||
|
||
logrus.Debugf("completed grace quit || kill of gvproxy (PID %d)", processID) | ||
|
||
// Make sure the process is gone (Hard kills are async) | ||
done := make(chan struct{}) | ||
go func() { | ||
_, _ = p.Wait() | ||
done <- struct{}{} | ||
}() | ||
|
||
select { | ||
case <-done: | ||
logrus.Debugf("verified gvproxy termination (PID %d)", processID) | ||
case <-time.After(10 * time.Second): | ||
// Very unlikely but track just in case | ||
logrus.Errorf("was not able to kill gvproxy (PID %d)", processID) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.