mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-25 08:31: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/go-errors/errors"
|
||||||
"github.com/integrii/flaggy"
|
"github.com/integrii/flaggy"
|
||||||
"github.com/jesseduffield/lazydocker/pkg/app"
|
"github.com/jesseduffield/lazydocker/pkg/app"
|
||||||
|
"github.com/jesseduffield/lazydocker/pkg/commands"
|
||||||
"github.com/jesseduffield/lazydocker/pkg/config"
|
"github.com/jesseduffield/lazydocker/pkg/config"
|
||||||
"github.com/jesseduffield/yaml"
|
"github.com/jesseduffield/yaml"
|
||||||
)
|
)
|
||||||
|
|
@ -73,6 +74,7 @@ func main() {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = app.Run()
|
err = app.Run()
|
||||||
}
|
}
|
||||||
|
commands.CloseDockerSocketConnection()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errMessage, known := app.KnownError(err); known {
|
if errMessage, known := app.KnownError(err); known {
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/acarl005/stripansi"
|
"github.com/acarl005/stripansi"
|
||||||
|
|
@ -151,16 +152,30 @@ func tryDial(ctx context.Context, socketPath string) error {
|
||||||
return nil
|
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 {
|
func tunnelSSH(ctx context.Context, host, localSocket string) error {
|
||||||
cmd := exec.CommandContext(ctx, "ssh", "-L", localSocket+":/var/run/docker.sock", host, "-N")
|
cmd := exec.CommandContext(ctx, "ssh", "-L", localSocket+":/var/run/docker.sock", host, "-N")
|
||||||
|
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
||||||
err := cmd.Start()
|
err := cmd.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
dockerSSHConnection = cmd
|
||||||
return nil
|
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.
|
// Handle special cases including `ssh://` host schemes.
|
||||||
func clientBuilder(c *client.Client) error {
|
func clientBuilder(c *client.Client) error {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue