From 927db378b403923a138df1b0fdd4b0ac2b66317e Mon Sep 17 00:00:00 2001 From: Maxton Huff Date: Wed, 27 Jan 2021 09:52:13 -0600 Subject: [PATCH] add linux OS check and the way mmap limit is read --- lattice | 2 +- server/server.go | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lattice b/lattice index 36f453c1e..28c2313ec 160000 --- a/lattice +++ b/lattice @@ -1 +1 @@ -Subproject commit 36f453c1ea3bf86c546a8ad4a88f2a926724d683 +Subproject commit 28c2313ecfcd7e083d42d4e409483e968b4c421b diff --git a/server/server.go b/server/server.go index ac06bc0fa..530e4102a 100644 --- a/server/server.go +++ b/server/server.go @@ -23,16 +23,16 @@ import ( "bytes" "context" "crypto/tls" - "encoding/binary" "io" + "io/ioutil" "log" "math/rand" "net" "os" - "os/exec" "os/signal" "runtime" "strconv" + "strings" "sync" "syscall" "time" @@ -154,13 +154,17 @@ func (m *Command) Start() (err error) { return errors.Wrap(err, "setting up server") } - result, err := exec.Command("sysctl", "vm.max_map_count").Output() - if err != nil { - m.logger.Printf("Tried unsuccessfully to check system mmap limit: %v", err) - } else { - sysMmapLimit := binary.BigEndian.Uint64(result) - if m.Config.MaxMapCount > sysMmapLimit { - m.logger.Printf("WARNING: Config max map limit (%v) is greater than current system limits (%v)", m.Config.MaxMapCount, sysMmapLimit) + if runtime.GOOS == "linux" { + result, err := ioutil.ReadFile("/proc/sys/vm/max_map_count") + if err != nil { + m.logger.Printf("Tried unsuccessfully to check system mmap limit: %v", err) + } else { + sysMmapLimit, err := strconv.ParseUint(strings.TrimSuffix(string(result), "\n"), 10, 64) + if err != nil { + m.logger.Printf("Tried unsuccessfully to check system mmap limit: %v", err) + } else if m.Config.MaxMapCount > sysMmapLimit { + m.logger.Printf("WARNING: Config max map limit (%v) is greater than current system limits (%v)", m.Config.MaxMapCount, sysMmapLimit) + } } }