mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-23 19:05:37 +00:00
Merge pull request #2796 from pcfdev-forks/master
Ensure VPNKit process is properly killed when errors occur
This commit is contained in:
commit
86f12e15f0
@ -241,14 +241,10 @@ func runHyperKit(args []string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln("Unable to start vpnkit: ", err)
|
log.Fatalln("Unable to start vpnkit: ", err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer shutdownVPNKit(vpnkitProcess)
|
||||||
if vpnkitProcess != nil {
|
log.RegisterExitHandler(func() {
|
||||||
err := vpnkitProcess.Kill()
|
shutdownVPNKit(vpnkitProcess)
|
||||||
if err != nil {
|
})
|
||||||
log.Println(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
// The guest will use this 9P mount to configure which ports to forward
|
// The guest will use this 9P mount to configure which ports to forward
|
||||||
h.Sockets9P = []hyperkit.Socket9P{{Path: vpnkitPortSocket, Tag: "port"}}
|
h.Sockets9P = []hyperkit.Socket9P{{Path: vpnkitPortSocket, Tag: "port"}}
|
||||||
// VSOCK port 62373 is used to pass traffic from host->guest
|
// VSOCK port 62373 is used to pass traffic from host->guest
|
||||||
@ -296,6 +292,7 @@ func runHyperKit(args []string) {
|
|||||||
log.Fatalf("Publish ports failed with: %v", err)
|
log.Fatalf("Publish ports failed with: %v", err)
|
||||||
}
|
}
|
||||||
defer f()
|
defer f()
|
||||||
|
log.RegisterExitHandler(f)
|
||||||
default:
|
default:
|
||||||
log.Fatalf("Port publishing requires %q or %q networking mode", hyperkitNetworkingDockerForMac, hyperkitNetworkingVPNKit)
|
log.Fatalf("Port publishing requires %q or %q networking mode", hyperkitNetworkingDockerForMac, hyperkitNetworkingVPNKit)
|
||||||
}
|
}
|
||||||
@ -307,6 +304,16 @@ func runHyperKit(args []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func shutdownVPNKit(process *os.Process) {
|
||||||
|
if process == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := process.Kill(); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// createListenSocket creates a new unix domain socket and returns the open file
|
// createListenSocket creates a new unix domain socket and returns the open file
|
||||||
func createListenSocket(path string) (*os.File, error) {
|
func createListenSocket(path string) (*os.File, error) {
|
||||||
os.Remove(path)
|
os.Remove(path)
|
||||||
|
Loading…
Reference in New Issue
Block a user