Skip to content

Commit

Permalink
ignore EROFS and EPERM errors on config saving
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
xaurx authored and tklauser committed Oct 5, 2023
1 parent 7735672 commit 1f2bfd9
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"bufio"
"context"
"encoding/binary"
"errors"
"fmt"
"io"
"net"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 1f2bfd9

Please sign in to comment.