mirror of https://github.com/status-im/consul.git
sdk: read procfs instead of using sysctl command
This drops the dependency of sysctl command
This commit is contained in:
parent
d3d9cb1d50
commit
b931e989b8
|
@ -4,18 +4,17 @@ package freeport
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
"io/ioutil"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
const ephemeralPortRangeSysctlKey = "net.ipv4.ip_local_port_range"
|
const ephemeralPortRangeProcFile = "/proc/sys/net/ipv4/ip_local_port_range"
|
||||||
|
|
||||||
var ephemeralPortRangePatt = regexp.MustCompile(`^\s*(\d+)\s+(\d+)\s*$`)
|
var ephemeralPortRangePatt = regexp.MustCompile(`^\s*(\d+)\s+(\d+)\s*$`)
|
||||||
|
|
||||||
func getEphemeralPortRange() (int, int, error) {
|
func getEphemeralPortRange() (int, int, error) {
|
||||||
cmd := exec.Command("/sbin/sysctl", "-n", ephemeralPortRangeSysctlKey)
|
out, err := ioutil.ReadFile(ephemeralPortRangeProcFile)
|
||||||
out, err := cmd.Output()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
|
@ -32,5 +31,5 @@ func getEphemeralPortRange() (int, int, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0, 0, fmt.Errorf("unexpected sysctl value %q for key %q", val, ephemeralPortRangeSysctlKey)
|
return 0, 0, fmt.Errorf("unexpected sysctl value %q for key %q", val, ephemeralPortRangeProcFile)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue