Skip to content

Commit

Permalink
agent: move check for EROFS/EPERM outside of saveConfig
Browse files Browse the repository at this point in the history
Rather than duplicating the check in saveConfig, check for EROFS or
EPERM on the error returned by saveConfig.
  • Loading branch information
tklauser committed Oct 24, 2023
1 parent 6b856f0 commit 582fc28
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions agent/agent.go
Expand Up @@ -102,7 +102,10 @@ func Listen(opts Options) error {
port := listener.Addr().(*net.TCPAddr).Port
err = saveConfig(opts, port)
if err != nil {
return err
// ignore and work in remote mode only
if !errors.Is(err, syscall.EROFS) && !errors.Is(err, syscall.EPERM) {
return err
}
}

if opts.ShutdownCleanup {
Expand Down Expand Up @@ -149,23 +152,12 @@ func saveConfig(opts Options, port int) 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
}

return nil
return os.WriteFile(portfile, []byte(strconv.Itoa(port)), os.ModePerm)
}

func gracefulShutdown() {
Expand Down

0 comments on commit 582fc28

Please sign in to comment.