aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/ipc/receive.go2
-rw-r--r--lib/ipc/send.go19
2 files changed, 8 insertions, 13 deletions
diff --git a/lib/ipc/receive.go b/lib/ipc/receive.go
index 79618f50..4f6258ad 100644
--- a/lib/ipc/receive.go
+++ b/lib/ipc/receive.go
@@ -27,7 +27,7 @@ type AercServer struct {
func StartServer(handler Handler, startup context.Context) (*AercServer, error) {
sockpath := xdg.RuntimePath("aerc.sock")
// remove the socket if it is not connected to a session
- if err := ConnectAndExec(nil); err != nil {
+ if _, err := ConnectAndExec(nil); err != nil {
os.Remove(sockpath)
}
log.Debugf("Starting Unix server: %s", sockpath)
diff --git a/lib/ipc/send.go b/lib/ipc/send.go
index fbe67413..d5138bf8 100644
--- a/lib/ipc/send.go
+++ b/lib/ipc/send.go
@@ -9,36 +9,31 @@ import (
"git.sr.ht/~rjarry/aerc/lib/xdg"
)
-func ConnectAndExec(args []string) error {
+func ConnectAndExec(args []string) (*Response, error) {
sockpath := xdg.RuntimePath("aerc.sock")
conn, err := net.Dial("unix", sockpath)
if err != nil {
- return err
+ return nil, err
}
defer conn.Close()
req, err := (&Request{Arguments: args}).Encode()
if err != nil {
- return fmt.Errorf("failed to encode request: %w", err)
+ return nil, fmt.Errorf("failed to encode request: %w", err)
}
_, err = conn.Write(append(req, '\n'))
if err != nil {
- return fmt.Errorf("failed to send message: %w", err)
+ return nil, fmt.Errorf("failed to send message: %w", err)
}
scanner := bufio.NewScanner(conn)
if !scanner.Scan() {
- return errors.New("No response from server")
+ return nil, errors.New("No response from server")
}
resp, err := DecodeResponse(scanner.Bytes())
if err != nil {
- return err
+ return nil, err
}
- // TODO: handle this in a more elegant manner
- if resp.Error != "" {
- fmt.Println("result: ", resp.Error)
- }
-
- return nil
+ return resp, nil
}