Close listener when daemon is killed due to failed RPC auth

This commit is contained in:
2025-05-08 16:03:36 +00:00
parent e8403315a8
commit 6a40f9e627
2 changed files with 6 additions and 5 deletions
+3 -3
View File
@@ -61,7 +61,7 @@ func Start(passphrase string) {
continue
}
// use a goroutine to check the client's identity
go handleConn(conn)
go handleConn(conn, sigChan)
}
}
@@ -71,7 +71,7 @@ func Start(passphrase string) {
// The passphrase is only returned if the client's executable hash matches the daemon's hash
// and if the request is coming from the same user.
// This ensures that only the binary the daemon is embedded in can retrieve the passphrase.
func handleConn(conn net.Conn) {
func handleConn(conn net.Conn, sigChan chan os.Signal) {
ucred := peercred.Get(conn)
// check if the RPC call is coming from an identical binary and from the same user
@@ -84,6 +84,6 @@ func handleConn(conn net.Conn) {
// log the client's path, and kill the daemon
conn.Close()
log.Printf("Request received from invalid client: PID(%d), UID(%s), Path(%s)", ucred.PID, ucred.UID, callingBinPath) // TODO log to file
os.Exit(2)
sigChan <- syscall.SIGTERM
}
}