Merge pull request #237 from ijc25/diagnostics

Fixup diagnostics logging
This commit is contained in:
Justin Cormack 2016-07-04 11:13:42 +01:00 committed by GitHub
commit 480bcf1be2

View File

@ -5,16 +5,18 @@ import (
"bytes"
"io"
"log"
"log/syslog"
"net"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
"syscall"
"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) {
@ -22,11 +24,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
@ -111,8 +113,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"
@ -125,24 +127,36 @@ 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")
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)
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: %#v", 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)
}
@ -152,7 +166,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) {