Cleanup sockets

This commit is contained in:
Bernd Schoolmann 2024-02-04 01:58:04 +01:00
parent 4afd6ef9b1
commit f135e8b302
No known key found for this signature in database
2 changed files with 18 additions and 11 deletions

View File

@ -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

View File

@ -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()
},
}