From c9c9994d89a864854ce914b35d538a038f086c40 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Fri, 1 Jul 2016 15:19:18 +0100 Subject: [PATCH 1/4] diagnostics: run "gofmt -w" over go code Signed-off-by: Ian Campbell --- alpine/packages/diagnostics/main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/alpine/packages/diagnostics/main.go b/alpine/packages/diagnostics/main.go index 77be9448e..e36d19e08 100644 --- a/alpine/packages/diagnostics/main.go +++ b/alpine/packages/diagnostics/main.go @@ -13,8 +13,8 @@ import ( "strings" "time" - "github.com/rneugeba/virtsock/go/vsock" "github.com/rneugeba/virtsock/go/hvsock" + "github.com/rneugeba/virtsock/go/vsock" ) func run(timeout time.Duration, w *tar.Writer, command string, args ...string) { @@ -111,8 +111,8 @@ func capture(w *tar.Writer) { run(t, w, "/usr/bin/dig", "@8.8.8.8", "docker.com") run(t, w, "/usr/bin/wget", "-O", "-", "http://www.docker.com/") run(t, w, "/usr/bin/wget", "-O", "-", "http://104.239.220.248/") // a www.docker.com address - run(t, w, "/usr/bin/wget", "-O", "-", "http://216.58.213.68/") // a www.google.com address - run(t, w, "/usr/bin/wget", "-O", "-", "http://91.198.174.192/") // a www.wikipedia.com address + run(t, w, "/usr/bin/wget", "-O", "-", "http://216.58.213.68/") // a www.google.com address + run(t, w, "/usr/bin/wget", "-O", "-", "http://91.198.174.192/") // a www.wikipedia.com address // Dump the database dbBase := "/Database/branch/master/ro" From 421dee55d08727a0d62c0e8ee1d1274b161870da Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Fri, 1 Jul 2016 15:14:12 +0100 Subject: [PATCH 2/4] diagnostics: Correct error formatting They should be formatted as %s not %#v (which prints all sorts of opaque pointers). Signed-off-by: Ian Campbell --- alpine/packages/diagnostics/main.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/alpine/packages/diagnostics/main.go b/alpine/packages/diagnostics/main.go index e36d19e08..39291ab7d 100644 --- a/alpine/packages/diagnostics/main.go +++ b/alpine/packages/diagnostics/main.go @@ -22,11 +22,11 @@ func run(timeout time.Duration, w *tar.Writer, command string, args ...string) { c := exec.Command(command, args...) stdoutPipe, err := c.StdoutPipe() if err != nil { - log.Fatalf("Failed to create stdout pipe: %#v", err) + log.Fatalf("Failed to create stdout pipe: %s", err) } stderrPipe, err := c.StderrPipe() if err != nil { - log.Fatalf("Failed to create stderr pipe: %#v", err) + log.Fatalf("Failed to create stderr pipe: %s", err) } var stdoutBuffer bytes.Buffer var stderrBuffer bytes.Buffer @@ -129,20 +129,20 @@ func main() { ip, err := net.Listen("tcp", ":62374") if err != nil { - log.Printf("Failed to bind to TCP port 62374: %#v", err) + log.Printf("Failed to bind to TCP port 62374: %s", err) } else { listeners = append(listeners, ip) } vsock, err := vsock.Listen(uint(62374)) if err != nil { - log.Printf("Failed to bind to vsock port 62374: %#v", err) + log.Printf("Failed to bind to vsock port 62374: %s", err) } else { listeners = append(listeners, vsock) } svcid, _ := hvsock.GuidFromString("445BA2CB-E69B-4912-8B42-D7F494D007EA") hvsock, err := hvsock.Listen(hvsock.HypervAddr{VmId: hvsock.GUID_WILDCARD, ServiceId: svcid}) if err != nil { - log.Printf("Failed to bind to hvsock port: %#v", err) + log.Printf("Failed to bind to hvsock port: %s", err) } else { listeners = append(listeners, hvsock) } @@ -152,7 +152,7 @@ func main() { for { conn, err := l.Accept() if err != nil { - log.Printf("Error accepting connection: %#v", err) + log.Printf("Error accepting connection: %s", err) return // no more listening } go func(conn net.Conn) { From d9288f5bba5a74247390321343de58800211074c Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Fri, 1 Jul 2016 15:20:34 +0100 Subject: [PATCH 3/4] diagnostics: Log over syslog Instead of spamming the console. Signed-off-by: Ian Campbell --- alpine/packages/diagnostics/main.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/alpine/packages/diagnostics/main.go b/alpine/packages/diagnostics/main.go index 39291ab7d..c62d89ac1 100644 --- a/alpine/packages/diagnostics/main.go +++ b/alpine/packages/diagnostics/main.go @@ -5,6 +5,7 @@ import ( "bytes" "io" "log" + "log/syslog" "net" "os" "os/exec" @@ -125,6 +126,14 @@ func capture(w *tar.Writer) { } func main() { + syslog, err := syslog.New(syslog.LOG_INFO|syslog.LOG_DAEMON, "diagnostics") + if err != nil { + log.Fatalln("Failed to open syslog", err) + } + + log.SetOutput(syslog) + log.SetFlags(0) + listeners := make([]net.Listener, 0) ip, err := net.Listen("tcp", ":62374") From dd41c21021c581ae1def106b36377d55d2ee929e Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Fri, 1 Jul 2016 15:33:01 +0100 Subject: [PATCH 4/4] diagnostics: Only log connection failure if not EAFNOTSUPPORT EAFNOTSUPPORT likely means we are running on a hypervisor which doesn't support that particular socket type. Signed-off-by: Ian Campbell --- alpine/packages/diagnostics/main.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/alpine/packages/diagnostics/main.go b/alpine/packages/diagnostics/main.go index c62d89ac1..1e7f42747 100644 --- a/alpine/packages/diagnostics/main.go +++ b/alpine/packages/diagnostics/main.go @@ -12,6 +12,7 @@ import ( "path" "path/filepath" "strings" + "syscall" "time" "github.com/rneugeba/virtsock/go/hvsock" @@ -144,14 +145,18 @@ func main() { } vsock, err := vsock.Listen(uint(62374)) if err != nil { - log.Printf("Failed to bind to vsock port 62374: %s", err) + if errno, ok := err.(syscall.Errno); !ok || errno != syscall.EAFNOSUPPORT { + log.Printf("Failed to bind to vsock port 62374: %s", err) + } } else { listeners = append(listeners, vsock) } svcid, _ := hvsock.GuidFromString("445BA2CB-E69B-4912-8B42-D7F494D007EA") hvsock, err := hvsock.Listen(hvsock.HypervAddr{VmId: hvsock.GUID_WILDCARD, ServiceId: svcid}) if err != nil { - log.Printf("Failed to bind to hvsock port: %s", err) + if errno, ok := err.(syscall.Errno); !ok || errno != syscall.EAFNOSUPPORT { + log.Printf("Failed to bind to hvsock port: %s", err) + } } else { listeners = append(listeners, hvsock) }