aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ipc
diff options
context:
space:
mode:
authorJason Cox <me@jasoncarloscox.com>2024-02-22 20:25:16 -0500
committerRobin Jarry <robin@jarry.cc>2024-04-13 21:46:35 +0200
commit4a0bb5d1840f282989bb6b4e3ec16d3da4d5c7f7 (patch)
tree4440ae9566d38fb52ce0f12ac3fccbcf9bd10f32 /lib/ipc
parent8312b46f144cc1bcf5b6838854df2a9b167c1c3a (diff)
downloadaerc-4a0bb5d1840f282989bb6b4e3ec16d3da4d5c7f7.tar.gz
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 <me@jasoncarloscox.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/ipc')
-rw-r--r--lib/ipc/handler.go6
-rw-r--r--lib/ipc/receive.go46
2 files changed, 6 insertions, 46 deletions
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{}
}