[lxc-devel] [go-lxc/v2] add ErrorNum to return the last error from the container
tych0 on Github
lxc-bot at linuxcontainers.org
Fri Jan 19 04:29:17 UTC 2018
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 544 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180119/fecd537d/attachment.bin>
-------------- next part --------------
From 1b32b677d52eb5bc5551c1b7d70f2ac001470d1f Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho at tycho.ws>
Date: Wed, 17 Jan 2018 16:00:31 +0000
Subject: [PATCH] add ErrorNum to return the last error from the container
As it stands right now, there is no way to figure out what the exit code of
a container spawned by StartExecute() was. liblxc stores the value in
c->error_num, so let's make that accessible.
Signed-off-by: Tycho Andersen <tycho at tycho.ws>
---
container.go | 6 ++++++
lxc-binding.c | 9 +++++++++
lxc-binding.h | 1 +
3 files changed, 16 insertions(+)
diff --git a/container.go b/container.go
index 174bd4b..3041c6b 100644
--- a/container.go
+++ b/container.go
@@ -1892,3 +1892,9 @@ func (c *Container) ConsoleLog(opt ConsoleLogOptions) ([]byte, error) {
return C.GoBytes(unsafe.Pointer(cl.data), numBytes), nil
}
+
+// ErrorNum returns the error_num field of the container.
+func (c *Container) ErrorNum() int {
+ cError := C.go_lxc_error_num(c.container)
+ return int(cError)
+}
diff --git a/lxc-binding.c b/lxc-binding.c
index 2be6c97..a1b5b19 100644
--- a/lxc-binding.c
+++ b/lxc-binding.c
@@ -454,6 +454,15 @@ bool go_lxc_config_item_is_supported(const char *key)
#endif
}
+int go_lxc_error_num(struct lxc_container *c)
+{
+#if VERSION_AT_LEAST(2, 1, 0)
+ return c->error_num;
+#else
+ return -1;
+#endif
+}
+
int go_lxc_console_log(struct lxc_container *c, struct lxc_console_log *log) {
#if VERSION_AT_LEAST(3, 0, 0)
return c->console_log(c, log);
diff --git a/lxc-binding.h b/lxc-binding.h
index 7170748..05131a1 100644
--- a/lxc-binding.h
+++ b/lxc-binding.h
@@ -124,3 +124,4 @@ struct lxc_console_log {
#endif
extern int go_lxc_console_log(struct lxc_container *c, struct lxc_console_log *log);
+extern int go_lxc_error_num(struct lxc_container *c);
More information about the lxc-devel
mailing list