[lxc-devel] [lxd/master] Fix uname handling on some architectures

stgraber on Github lxc-bot at linuxcontainers.org
Sat Sep 23 20:35:57 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 431 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170923/6fbd3dfc/attachment.bin>
-------------- next part --------------
From a364b4d99ea6bacf6dabea42d584866746c2c380 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Sat, 23 Sep 2017 16:34:38 -0400
Subject: [PATCH] Fix uname handling on some architectures
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Some arches have the uname as [65]int8, some others have it as [65]uint8.

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 shared/util_linux.go | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/shared/util_linux.go b/shared/util_linux.go
index 369898eb1..7560e44ac 100644
--- a/shared/util_linux.go
+++ b/shared/util_linux.go
@@ -10,6 +10,7 @@ import (
 	"os"
 	"os/exec"
 	"path/filepath"
+	"reflect"
 	"strings"
 	"sync"
 	"sync/atomic"
@@ -806,13 +807,29 @@ func Uname() (*Utsname, error) {
 	}, nil
 }
 
-func intArrayToString(arr [65]int8) string {
+func intArrayToString(arr interface{}) string {
+	slice := reflect.ValueOf(arr)
 	s := ""
-	for _, c := range arr {
-		if c == 0 {
+	for i := 0; i < slice.Len(); i++ {
+		val := slice.Index(i)
+		valInt := int64(-1)
+
+		switch val.Kind() {
+		case reflect.Int:
+		case reflect.Int8:
+			valInt = int64(val.Int())
+		case reflect.Uint:
+		case reflect.Uint8:
+			valInt = int64(val.Uint())
+		default:
+			continue
+		}
+
+		if valInt == 0 {
 			break
 		}
-		s += string(byte(c))
+
+		s += string(byte(valInt))
 	}
 
 	return s


More information about the lxc-devel mailing list