From 4a0bb5d1840f282989bb6b4e3ec16d3da4d5c7f7 Mon Sep 17 00:00:00 2001 From: Jason Cox Date: Thu, 22 Feb 2024 20:25:16 -0500 Subject: ipc: retry failed command directly, not over IPC If IPC fails the first time we try it, we know that no other aerc instance is running. When we retry, run the command directly instead of going through the current instance's own IPC server. Signed-off-by: Jason Cox Acked-by: Robin Jarry --- lib/ipc/handler.go | 6 +----- lib/ipc/receive.go | 46 +++++----------------------------------------- 2 files changed, 6 insertions(+), 46 deletions(-) (limited to 'lib/ipc') diff --git a/lib/ipc/handler.go b/lib/ipc/handler.go index 10f42753..9ed81be0 100644 --- a/lib/ipc/handler.go +++ b/lib/ipc/handler.go @@ -1,9 +1,5 @@ package ipc -import "net/url" - type Handler interface { - Mailto(addr *url.URL) error - Mbox(source string) error - Command(cmdline string) error + Command(args []string) error } diff --git a/lib/ipc/receive.go b/lib/ipc/receive.go index 4f6258ad..ff837d0f 100644 --- a/lib/ipc/receive.go +++ b/lib/ipc/receive.go @@ -5,14 +5,10 @@ import ( "context" "errors" "net" - "net/url" "os" - "strings" "sync/atomic" "time" - "git.sr.ht/~rjarry/go-opt" - "git.sr.ht/~rjarry/aerc/config" "git.sr.ht/~rjarry/aerc/lib/log" "git.sr.ht/~rjarry/aerc/lib/xdg" @@ -101,44 +97,12 @@ func (as *AercServer) Serve() { } func (as *AercServer) handleMessage(req *Request) *Response { - if len(req.Arguments) == 0 { - return &Response{} // send noop success message, i.e. ping + if config.General.DisableIPC { + return &Response{Error: "command rejected: IPC is disabled"} } - var err error - switch { - case strings.HasPrefix(req.Arguments[0], "mailto:"): - mailto, err := url.Parse(req.Arguments[0]) - if err != nil { - return &Response{Error: err.Error()} - } - err = as.handler.Mailto(mailto) - if err != nil { - return &Response{ - Error: err.Error(), - } - } - case strings.HasPrefix(req.Arguments[0], "mbox:"): - err = as.handler.Mbox(req.Arguments[0]) - if err != nil { - return &Response{Error: err.Error()} - } - case strings.HasPrefix(req.Arguments[0], ":"): - if config.General.DisableIPC { - return &Response{ - Error: "command rejected: IPC is disabled", - } - } - cmdline := req.Arguments[0] - if len(req.Arguments) > 1 { - cmdline = opt.QuoteArgs(req.Arguments...).String() - } - err = as.handler.Command(cmdline) - if err != nil { - return &Response{Error: err.Error()} - } - - default: - return &Response{Error: "command not understood"} + err := as.handler.Command(req.Arguments) + if err != nil { + return &Response{Error: err.Error()} } return &Response{} } -- cgit