From dae615bb91f9b37c8865f7b135a819a4ff754b25 Mon Sep 17 00:00:00 2001 From: Alex Lyashko Date: Fri, 19 May 2023 17:21:27 -0400 Subject: [PATCH] ignore EROFS and EPERM errors on config saving agent still works in remote mode and executable environment may not allow to save any data at all (e.g. in k8s container), so be robust. Signed-off-by: Alex Lyashko --- agent/agent.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/agent/agent.go b/agent/agent.go index 5675b422..c35702d5 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -10,6 +10,7 @@ import ( "bufio" "context" "encoding/binary" + "errors" "fmt" "io" "net" @@ -145,12 +146,18 @@ func saveConfig(opts Options, port int) (err error) { } err = os.MkdirAll(gopsdir, os.ModePerm) + if errors.Is(err, syscall.EROFS) || errors.Is(err, syscall.EPERM) { // ignore and work in remote mode only + return nil + } if err != nil { return err } portfile = filepath.Join(gopsdir, strconv.Itoa(os.Getpid())) err = os.WriteFile(portfile, []byte(strconv.Itoa(port)), os.ModePerm) + if errors.Is(err, syscall.EROFS) || errors.Is(err, syscall.EPERM) { // ignore and work in remote mode only + return nil + } if err != nil { return err }