[lxc-devel] [go-lxc/v2] 2017 10 12/support new api call

brauner on Github lxc-bot at linuxcontainers.org
Thu Oct 12 15:40:10 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 302 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20171012/c16d56de/attachment.bin>
-------------- next part --------------
From 455e6233ce2e4d58ef3828f465f9b80fa9fc2195 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Thu, 12 Oct 2017 17:39:01 +0200
Subject: [PATCH 1/2] binginds: add missing import

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 lxc-binding.go | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lxc-binding.go b/lxc-binding.go
index 29aaf80..2fb4fd9 100644
--- a/lxc-binding.go
+++ b/lxc-binding.go
@@ -19,6 +19,7 @@ import "C"
 import (
 	"fmt"
 	"runtime"
+	"strings"
 	"unsafe"
 )
 
@@ -67,7 +68,7 @@ func Version() string {
 
 	// New liblxc versions append "-devel" when LXC_DEVEL is set.
 	if strings.HasSuffix(version, "-devel") {
-		return fmt.Sprintf("%s (devel)", version[:(len(version) - len("-devel"))])
+		return fmt.Sprintf("%s (devel)", version[:(len(version)-len("-devel"))])
 	} else if C.LXC_DEVEL == 1 {
 		version = fmt.Sprintf("%s (devel)", version)
 	}

From 5646c1b2c23ada2cc2657423987aa3429f5136cd Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Thu, 12 Oct 2017 17:39:21 +0200
Subject: [PATCH 2/2] bindings: support set_running_config_item()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 container.go  | 18 ++++++++++++++++++
 lxc-binding.c |  8 ++++++++
 lxc-binding.h |  2 ++
 3 files changed, 28 insertions(+)

diff --git a/container.go b/container.go
index bbcfa1d..f859d3d 100644
--- a/container.go
+++ b/container.go
@@ -1707,3 +1707,21 @@ func (c *Container) DetachInterfaceRename(source, target string) error {
 	}
 	return nil
 }
+
+// SetRunningConfigItem sets the value of the given config item in the
+// container's in-memory config.
+func (c *Container) SetRunningConfigItem(key string, value string) error {
+	c.mu.Lock()
+	defer c.mu.Unlock()
+
+	ckey := C.CString(key)
+	defer C.free(unsafe.Pointer(ckey))
+
+	cvalue := C.CString(value)
+	defer C.free(unsafe.Pointer(cvalue))
+
+	if !bool(C.go_lxc_set_running_config_item(c.container, ckey, cvalue)) {
+		return ErrSettingConfigItemFailed
+	}
+	return nil
+}
diff --git a/lxc-binding.c b/lxc-binding.c
index 406801c..60206b9 100644
--- a/lxc-binding.c
+++ b/lxc-binding.c
@@ -455,3 +455,11 @@ bool go_lxc_config_item_is_supported(const char *key)
 	return false;
 #endif
 }
+
+bool go_lxc_set_running_config_item(struct lxc_container *c, const char *key, const char *value) {
+#if VERSION_AT_LEAST(2, 1, 0)
+	return c->set_running_config_item(c, key, value);
+#else
+	return false;
+#endif
+}
diff --git a/lxc-binding.h b/lxc-binding.h
index 11a22df..cbf9ce2 100644
--- a/lxc-binding.h
+++ b/lxc-binding.h
@@ -78,6 +78,8 @@ extern pid_t go_lxc_init_pid(struct lxc_container *c);
 extern bool go_lxc_checkpoint(struct lxc_container *c, char *directory, bool stop, bool verbose);
 extern bool go_lxc_restore(struct lxc_container *c, char *directory, bool verbose);
 extern bool go_lxc_config_item_is_supported(const char *key);
+extern bool go_lxc_set_running_config_item(struct lxc_container *c,
+					   const char *key, const char *value);
 
 /* n.b. that we're just adding the fields here to shorten the definition
  * of go_lxc_migrate; in the case where we don't have the ->migrate API call,


More information about the lxc-devel mailing list