[lxc-devel] [lxd/master] shared: Switch ParseNumberFromFile to simple read
stgraber on Github
lxc-bot at linuxcontainers.org
Wed Mar 13 20:19:12 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 406 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190313/a266aa02/attachment.bin>
-------------- next part --------------
From 5796954f6b6a132036714c67d84e0320133bb6d5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 13 Mar 2019 15:59:02 -0400
Subject: [PATCH] shared: Switch ParseNumberFromFile to simple read
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This should avoid some issues with polling /proc
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
shared/util.go | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/shared/util.go b/shared/util.go
index 6ff230361e..060b576563 100644
--- a/shared/util.go
+++ b/shared/util.go
@@ -1100,12 +1100,19 @@ func DownloadFileHash(httpClient *http.Client, useragent string, progress func(p
}
func ParseNumberFromFile(file string) (int64, error) {
- buf, err := ioutil.ReadFile(file)
+ f, err := os.Open(file)
+ if err != nil {
+ return int64(0), err
+ }
+ defer f.Close()
+
+ buf := make ([]byte, 4096)
+ n, err := f.Read(buf)
if err != nil {
return int64(0), err
}
- str := strings.TrimSpace(string(buf))
+ str := strings.TrimSpace(string(buf[0:n]))
nr, err := strconv.Atoi(str)
if err != nil {
return int64(0), err
More information about the lxc-devel
mailing list