fix(felhomsshd): persist claimed port in agent StateDir (non-root can't write /etc)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PSK5g6qYLknKj8u3QAFEr6
This commit is contained in:
@@ -1,11 +1,6 @@
|
||||
package felhomsshd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
import "fmt"
|
||||
|
||||
// Candidates is the ordered OOB-port candidate list (spike §2). First free wins; NEVER :22 or a
|
||||
// random port. Package-var (not const) so tests can shrink it.
|
||||
@@ -42,24 +37,3 @@ func claimPort(candidates []int, isFree portProbe, readPersisted func() (int, bo
|
||||
}
|
||||
return 0, ErrPortsExhausted
|
||||
}
|
||||
|
||||
// readPortFile parses PortFile → (port, ok). A missing/garbage file → (0,false).
|
||||
func readPortFile() (int, bool) {
|
||||
raw, err := os.ReadFile(PortFile)
|
||||
if err != nil {
|
||||
return 0, false
|
||||
}
|
||||
p, err := strconv.Atoi(strings.TrimSpace(string(raw)))
|
||||
if err != nil || p < 1 || p > 65535 {
|
||||
return 0, false
|
||||
}
|
||||
return p, true
|
||||
}
|
||||
|
||||
// writePortFile persists the claimed port (0644 — a port is not a secret).
|
||||
func writePortFile(port int) error {
|
||||
if err := os.MkdirAll(ConfDir, 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(PortFile, []byte(strconv.Itoa(port)+"\n"), 0o644)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user