diff --git a/agent/bitwarden/websocket.go b/agent/bitwarden/websocket.go index f735a9b..5afa8eb 100644 --- a/agent/bitwarden/websocket.go +++ b/agent/bitwarden/websocket.go @@ -5,7 +5,6 @@ import ( "context" "net/url" "os" - "os/signal" "time" "github.com/awnumar/memguard" @@ -71,9 +70,6 @@ func RunWebsocketDaemon(ctx context.Context, vault *vault.Vault, cfg *config.Con } func connectToWebsocket(ctx context.Context, vault *vault.Vault, cfg *config.Config) error { - interrupt := make(chan os.Signal, 1) - signal.Notify(interrupt, os.Interrupt) - url, err := url.Parse(cfg.ConfigFile.NotificationsUrl) if err != nil { return err diff --git a/cmd/daemonize.go b/cmd/daemonize.go index c2fef56..8f8dde1 100644 --- a/cmd/daemonize.go +++ b/cmd/daemonize.go @@ -1,8 +1,8 @@ package cmd import ( - "os" - "os/signal" + "fmt" + "syscall" "github.com/awnumar/memguard" "github.com/quexten/goldwarden/agent" @@ -26,16 +26,27 @@ var daemonizeCmd = &cobra.Command{ println("SSH agent disabled") } - go func() { - signalChannel := make(chan os.Signal, 1) - signal.Notify(signalChannel, os.Interrupt) - <-signalChannel + cleanup := func() { + fmt.Println("removing sockets and exiting") + fmt.Println("unlinking", runtimeConfig.GoldwardenSocketPath) + err := syscall.Unlink(runtimeConfig.GoldwardenSocketPath) + if err != nil { + fmt.Println(err) + } + fmt.Println("unlinking", runtimeConfig.SSHAgentSocketPath) + err = syscall.Unlink(runtimeConfig.SSHAgentSocketPath) + if err != nil { + fmt.Println(err) + } + fmt.Println("memguard wiping memory and exiting") memguard.SafeExit(0) - }() + } + err := agent.StartUnixAgent(runtimeConfig.GoldwardenSocketPath, runtimeConfig) if err != nil { panic(err) } + cleanup() }, }