[lxc-devel] [lxd/master] drop \n from IdmapSet's ToLxcString

tych0 on Github lxc-bot at linuxcontainers.org
Tue Jan 9 00:13:26 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 568 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180109/3e72efff/attachment.bin>
-------------- next part --------------
From 422751d77dfa13363552caac756de46910ae780c Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho at tycho.ws>
Date: Mon, 8 Jan 2018 17:01:48 -0700
Subject: [PATCH] drop \n from IdmapSet's ToLxcString

1. We just strip the newline everywhere we use this anyways, so we can drop
   the stripping code too.
2. liblxc itself doesn't even accept this string with a newline on the end,
   so it's not even an LxcString :)

Signed-off-by: Tycho Andersen <tycho at tycho.ws>
---
 lxd/container_lxc.go           | 2 +-
 lxd/util/sys.go                | 4 ++--
 shared/idmap/idmapset_linux.go | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 687363d6b..daf1d4d85 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -1135,7 +1135,7 @@ func (c *containerLXC) initLXC(config bool) error {
 	if idmapset != nil {
 		lines := idmapset.ToLxcString()
 		for _, line := range lines {
-			err := lxcSetConfigItem(cc, "lxc.idmap", strings.TrimSuffix(line, "\n"))
+			err := lxcSetConfigItem(cc, "lxc.idmap", line)
 			if err != nil {
 				return err
 			}
diff --git a/lxd/util/sys.go b/lxd/util/sys.go
index 5532f8704..9e40ea998 100644
--- a/lxd/util/sys.go
+++ b/lxd/util/sys.go
@@ -50,7 +50,7 @@ func GetIdmapSet() *idmap.IdmapSet {
 		if err == nil {
 			logger.Infof("Kernel uid/gid map:")
 			for _, lxcmap := range kernelIdmapSet.ToLxcString() {
-				logger.Infof(strings.TrimRight(" - "+lxcmap, "\n"))
+				logger.Infof(" - " + lxcmap)
 			}
 		}
 
@@ -68,7 +68,7 @@ func GetIdmapSet() *idmap.IdmapSet {
 				}
 
 				for _, lxcEntry := range lxcmap.ToLxcString() {
-					logger.Infof(" - %s%s", strings.TrimRight(lxcEntry, "\n"), suffix)
+					logger.Infof(" - %s%s", lxcEntry, suffix)
 				}
 			}
 
diff --git a/shared/idmap/idmapset_linux.go b/shared/idmap/idmapset_linux.go
index d9edc8a97..b4f01e769 100644
--- a/shared/idmap/idmapset_linux.go
+++ b/shared/idmap/idmapset_linux.go
@@ -402,8 +402,8 @@ func (m IdmapSet) ToLxcString() []string {
 	var lines []string
 	for _, e := range m.Idmap {
 		for _, l := range e.ToLxcString() {
-			if !shared.StringInSlice(l+"\n", lines) {
-				lines = append(lines, l+"\n")
+			if !shared.StringInSlice(l, lines) {
+				lines = append(lines, l)
 			}
 		}
 	}


More information about the lxc-devel mailing list