From afcd61da21875fcbca270b9ae76c469e9c27f313 Mon Sep 17 00:00:00 2001 From: brl Date: Sun, 7 Jun 2015 19:40:53 -0400 Subject: [PATCH] log xpra client output instead of dumping it to stdout --- oz-daemon/launch.go | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/oz-daemon/launch.go b/oz-daemon/launch.go index e5888d2..e8fa4ec 100644 --- a/oz-daemon/launch.go +++ b/oz-daemon/launch.go @@ -7,7 +7,6 @@ import ( "github.com/subgraph/oz/fs" "github.com/subgraph/oz/xpra" "io" - "os" "os/exec" "os/user" "path" @@ -178,9 +177,34 @@ func (sbox *Sandbox) startXpraClient() { sbox.fs.Xpra(), sbox.profile.Name, sbox.daemon.log) - sbox.xpra.Process.Stdout = os.Stdout - sbox.xpra.Process.Stderr = os.Stdout + + if sbox.daemon.config.LogXpra { + sbox.setupXpraLogging() + } if err := sbox.xpra.Process.Start(); err != nil { sbox.daemon.Warning("Failed to start xpra client: %v", err) } } + +func (sbox *Sandbox) setupXpraLogging() { + stdout,err := sbox.xpra.Process.StdoutPipe() + if err != nil { + sbox.daemon.Warning("Failed to create xpra stdout pipe: %v", err) + return + } + stderr,err := sbox.xpra.Process.StderrPipe() + if err != nil { + stdout.Close() + sbox.daemon.Warning("Failed to create xpra stderr pipe: %v", err) + } + go sbox.logPipeOutput(stdout, "xpra-stdout") + go sbox.logPipeOutput(stderr, "xpra-stderr") +} + +func (sbox *Sandbox) logPipeOutput(p io.Reader, label string) { + scanner := bufio.NewScanner(p) + for scanner.Scan() { + line := scanner.Text() + sbox.daemon.log.Info("(%s) %s", label, line) + } +}