Skip to content

Commit

Permalink
Cleanup sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
quexten committed Feb 4, 2024
1 parent 4afd6ef commit f135e8b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
4 changes: 0 additions & 4 deletions agent/bitwarden/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"net/url"
"os"
"os/signal"
"time"

"github.com/awnumar/memguard"
Expand Down Expand Up @@ -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
Expand Down
25 changes: 18 additions & 7 deletions cmd/daemonize.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cmd

import (
"os"
"os/signal"
"fmt"
"syscall"

"github.com/awnumar/memguard"
"github.com/quexten/goldwarden/agent"
Expand All @@ -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()
},
}

Expand Down

0 comments on commit f135e8b

Please sign in to comment.