mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-21 23:01:03 +00:00
set pgid and send kill signal on exit
This commit is contained in:
parent
7f68d01181
commit
892fc090b6
2 changed files with 18 additions and 1 deletions
2
main.go
2
main.go
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/go-errors/errors"
|
||||
"github.com/integrii/flaggy"
|
||||
"github.com/jesseduffield/lazydocker/pkg/app"
|
||||
"github.com/jesseduffield/lazydocker/pkg/commands"
|
||||
"github.com/jesseduffield/lazydocker/pkg/config"
|
||||
"github.com/jesseduffield/yaml"
|
||||
)
|
||||
|
|
@ -73,6 +74,7 @@ func main() {
|
|||
if err == nil {
|
||||
err = app.Run()
|
||||
}
|
||||
commands.CloseDockerSocketConnection()
|
||||
|
||||
if err != nil {
|
||||
if errMessage, known := app.KnownError(err); known {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import (
|
|||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/acarl005/stripansi"
|
||||
|
|
@ -151,16 +152,30 @@ func tryDial(ctx context.Context, socketPath string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// CloseDockerSocketConnection kills the docker socket SSH forwarding process, if it exists.
|
||||
//
|
||||
// If will exist when DOCKER_HOST has the protocol scheme `ssh://`.
|
||||
func CloseDockerSocketConnection() {
|
||||
if dockerSSHConnection != nil {
|
||||
syscall.Kill(-dockerSSHConnection.Process.Pid, syscall.SIGKILL)
|
||||
}
|
||||
}
|
||||
|
||||
// dockerSSHConnection holds package-level state for the last-opened SSH tunnel to a remote docker socket.
|
||||
var dockerSSHConnection *exec.Cmd
|
||||
|
||||
func tunnelSSH(ctx context.Context, host, localSocket string) error {
|
||||
cmd := exec.CommandContext(ctx, "ssh", "-L", localSocket+":/var/run/docker.sock", host, "-N")
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
||||
err := cmd.Start()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dockerSSHConnection = cmd
|
||||
return nil
|
||||
}
|
||||
|
||||
// Build a new docker client from the enviornment.
|
||||
// Build a new docker client from the environment.
|
||||
//
|
||||
// Handle special cases including `ssh://` host schemes.
|
||||
func clientBuilder(c *client.Client) error {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue