[lxc-devel] [lxd/master] util linux: guess size when sysconf() returns -1
corburn on Github
lxc-bot at linuxcontainers.org
Wed Sep 6 07:08:09 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 504 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170906/69022a75/attachment.bin>
-------------- next part --------------
From c2daf46b612d936191a63284173a2fe3ecb62d53 Mon Sep 17 00:00:00 2001
From: Jason Travis <JasonTravis at nau.edu>
Date: Wed, 6 Sep 2017 06:39:45 +0000
Subject: [PATCH] util linux: guess size when sysconf() returns -1
Signed-off-by: Jason Travis <JasonTravis at nau.edu>
---
shared/util_linux.go | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/shared/util_linux.go b/shared/util_linux.go
index bec5ad2dc..26389c7ee 100644
--- a/shared/util_linux.go
+++ b/shared/util_linux.go
@@ -355,12 +355,12 @@ func UserId(name string) (int, error) {
var pw C.struct_passwd
var result *C.struct_passwd
- bufSize := C.size_t(C.sysconf(C._SC_GETPW_R_SIZE_MAX))
+ bufSize := C.sysconf(C._SC_GETPW_R_SIZE_MAX)
if bufSize < 0 {
bufSize = 4096
}
- buf := C.malloc(bufSize)
+ buf := C.malloc(C.size_t(bufSize))
if buf == nil {
return -1, fmt.Errorf("allocation failed")
}
@@ -373,14 +373,14 @@ again:
rv, errno := C.getpwnam_r(cname,
&pw,
(*C.char)(buf),
- bufSize,
+ C.size_t(bufSize),
&result)
if rv < 0 {
// OOM killer will take care of us if we end up doing this too
// often.
if errno == syscall.ERANGE {
bufSize *= 2
- tmp := C.realloc(buf, bufSize)
+ tmp := C.realloc(buf, C.size_t(bufSize))
if tmp == nil {
return -1, fmt.Errorf("allocation failed")
}
@@ -402,12 +402,12 @@ func GroupId(name string) (int, error) {
var grp C.struct_group
var result *C.struct_group
- bufSize := C.size_t(C.sysconf(C._SC_GETGR_R_SIZE_MAX))
+ bufSize := C.sysconf(C._SC_GETGR_R_SIZE_MAX)
if bufSize < 0 {
bufSize = 4096
}
- buf := C.malloc(bufSize)
+ buf := C.malloc(C.size_t(bufSize))
if buf == nil {
return -1, fmt.Errorf("allocation failed")
}
@@ -419,14 +419,14 @@ again:
rv, errno := C.getgrnam_r(cname,
&grp,
(*C.char)(buf),
- bufSize,
+ C.size_t(bufSize),
&result)
if rv != 0 {
// OOM killer will take care of us if we end up doing this too
// often.
if errno == syscall.ERANGE {
bufSize *= 2
- tmp := C.realloc(buf, bufSize)
+ tmp := C.realloc(buf, C.size_t(bufSize))
if tmp == nil {
return -1, fmt.Errorf("allocation failed")
}
More information about the lxc-devel
mailing list