[lxc-devel] [lxd/master] DO NOT MERGE (jenkins failure debugging)
stgraber on Github
lxc-bot at linuxcontainers.org
Fri Mar 3 23:26:37 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170303/a91a0a5b/attachment.bin>
-------------- next part --------------
From 0cd61ff147e3853f8fcfa18e7a0fcc11b0688ced Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.andersen at canonical.com>
Date: Thu, 13 Oct 2016 19:17:17 -0600
Subject: [PATCH] Log errors from `lxd netcat` to a temp file
Hopefully this will help with debugging.
Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
lxd/main_netcat.go | 31 +++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/lxd/main_netcat.go b/lxd/main_netcat.go
index f5be1b3..00833f8 100644
--- a/lxd/main_netcat.go
+++ b/lxd/main_netcat.go
@@ -3,11 +3,26 @@ package main
import (
"fmt"
"io"
+ "io/ioutil"
"net"
"os"
"sync"
)
+type logErrorReader struct {
+ r io.Reader
+ f *os.File
+}
+
+func (le logErrorReader) Read(p []byte) (int, error) {
+ n, err := le.r.Read(p)
+ if err != nil {
+ fmt.Fprintf(le.f, "Error reading netcat stream: %v", err)
+ }
+
+ return n, err
+}
+
// Netcat is called with:
//
// lxd netcat /path/to/unix/socket
@@ -20,6 +35,12 @@ func cmdNetcat(args []string) error {
return fmt.Errorf("Bad arguments %q", args)
}
+ f, err := ioutil.TempFile("", "lxd_netcat_")
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+
uAddr, err := net.ResolveUnixAddr("unix", args[1])
if err != nil {
return err
@@ -34,13 +55,19 @@ func cmdNetcat(args []string) error {
wg.Add(1)
go func() {
- io.Copy(os.Stdout, conn)
+ _, err := io.Copy(os.Stdout, logErrorReader{conn, f})
+ if err != nil {
+ fmt.Fprintf(f, "Error netcatting to stdout: %v", err)
+ }
conn.Close()
wg.Done()
}()
go func() {
- io.Copy(conn, os.Stdin)
+ _, err := io.Copy(conn, os.Stdin)
+ if err != nil {
+ fmt.Fprintf(f, "Error netcatting to stdout: %v", err)
+ }
}()
wg.Wait()
More information about the lxc-devel
mailing list