Add high-level function for calling the daemon if it is open

This commit is contained in:
2025-05-04 19:38:45 -04:00
parent 0479447f14
commit 9314852f06
6 changed files with 36 additions and 39 deletions
+3 -15
View File
@@ -14,15 +14,10 @@ import (
peercred "github.com/rwinkhart/peercred-mini"
)
// Run should be called to start an RPC server.
func Start(inputPassphrase string) {
// ensure daemon is not already running
if daemonIsOpen() {
return
}
// Start should be called to serve the given passphrase through an RPC daemon.
func Start(passphrase string) {
// store passphrase to be referenced by GetPass method
passphrase = inputPassphrase
globalPassphrase = passphrase
// register RCWService with the RPC package
if err := rpc.Register(&RCWService{}); err != nil {
@@ -32,13 +27,6 @@ func Start(inputPassphrase string) {
// store the hash of the daemon binary
daemonHash = getFileHash(binPath)
// remove the socket file if it already exists
if _, err := os.Stat(socketPath); err == nil {
if err := os.Remove(socketPath); err != nil {
log.Fatalf("Failed to remove existing socket: %v", err)
}
}
// listen on the Unix domain socket
listener, err := net.Listen("unix", socketPath)
if err != nil {