From 40d540637168fd5781e0c4a9cbd91959b7407d96 Mon Sep 17 00:00:00 2001 From: Michal Minar Date: Fri, 13 Mar 2015 09:34:27 +0100 Subject: [PATCH] Pass buffered file reader to Fscanf instead of string reader Unless `file` is wrapped with buffered reader, `fmt.Fscanf` will read just one byte and terminate with `EOF`. Signed-off-by: Michal Minar --- daemon/networkdriver/portallocator/portallocator.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/daemon/networkdriver/portallocator/portallocator.go b/daemon/networkdriver/portallocator/portallocator.go index 17d8a2a29e..4ae4beb106 100644 --- a/daemon/networkdriver/portallocator/portallocator.go +++ b/daemon/networkdriver/portallocator/portallocator.go @@ -1,11 +1,11 @@ package portallocator import ( + "bufio" "errors" "fmt" - "io/ioutil" "net" - "strings" + "os" "sync" log "github.com/Sirupsen/logrus" @@ -71,13 +71,13 @@ func NewErrPortAlreadyAllocated(ip string, port int) ErrPortAlreadyAllocated { func init() { const param = "/proc/sys/net/ipv4/ip_local_port_range" - line, err := ioutil.ReadFile(param) + file, err := os.Open(param) if err != nil { log.Errorf("Failed to read %s kernel parameter: %s", param, err.Error()) return } var start, end int - n, err := fmt.Fscanf(strings.NewReader(string(line)), "%d\t%d", &start, &end) + n, err := fmt.Fscanf(bufio.NewReader(file), "%d\t%d", &start, &end) if n != 2 || err != nil { if err == nil { err = fmt.Errorf("unexpected count of parsed numbers (%d)", n)