[lxc-devel] [go-lxc/v2] Do not suppress stderr if Execute command exits nonzero

sethdmoore on Github lxc-bot at linuxcontainers.org
Tue Apr 19 03:49:39 UTC 2016


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/20160419/6bfa4a0a/attachment.bin>
-------------- next part --------------
From 8e94eb6493dd368fa208b52899b9f7690aa7e41f Mon Sep 17 00:00:00 2001
From: Seth Moore <sethdmoore at gmail.com>
Date: Mon, 18 Apr 2016 22:01:19 -0400
Subject: [PATCH] Do not suppress stderr if Execute command exits nonzero

---
 container.go | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/container.go b/container.go
index 9b047ca..c6ef292 100644
--- a/container.go
+++ b/container.go
@@ -458,6 +458,8 @@ func (c *Container) Execute(args ...string) ([]byte, error) {
 		return nil, err
 	}
 
+	var output []byte
+	var err error
 	cargs := []string{"lxc-execute", "-n", c.Name(), "-P", c.ConfigPath(), "--"}
 	cargs = append(cargs, args...)
 
@@ -466,9 +468,14 @@ func (c *Container) Execute(args ...string) ([]byte, error) {
 
 	// FIXME: Go runtime and src/lxc/start.c signal_handler are not playing nice together so use lxc-execute for now
 	// go-nuts thread: https://groups.google.com/forum/#!msg/golang-nuts/h9GbvfYv83w/5Ly_jvOr86wJ
-	output, err := exec.Command(cargs[0], cargs[1:]...).CombinedOutput()
+	output, err = exec.Command(cargs[0], cargs[1:]...).CombinedOutput()
 	if err != nil {
-		return nil, ErrExecuteFailed
+		// Do not suppress stderr if the exit code != 0. Return with err.
+		if len(output) > 1 {
+			return output, ErrExecuteFailed
+		} else {
+			return nil, ErrExecuteFailed
+		}
 	}
 
 	return output, nil


More information about the lxc-devel mailing list