Merge changes from upstream

networking
user 10 years ago
commit 478cb65192

@ -42,13 +42,13 @@ func NewServer(address string, factory MsgFactory, log *logging.Logger, handlers
} }
listener, err := net.ListenUnix("unix", &net.UnixAddr{address, "unix"}) listener, err := net.ListenUnix("unix", &net.UnixAddr{address, "unix"})
if err := setPassCred(listener); err != nil {
return nil, errors.New("Failed to set SO_PASSCRED on listening socket: " + err.Error())
}
if err != nil { if err != nil {
md.close() md.close()
return nil, err return nil, err
} }
if err := setPassCred(listener); err != nil {
return nil, errors.New("Failed to set SO_PASSCRED on listening socket: " + err.Error())
}
done := make(chan bool) done := make(chan bool)
idGen := newIdGen(done) idGen := newIdGen(done)
return &MsgServer{ return &MsgServer{
@ -64,8 +64,6 @@ func (s *MsgServer) Run() error {
for { for {
conn, err := s.listener.AcceptUnix() conn, err := s.listener.AcceptUnix()
if err != nil { if err != nil {
s.disp.close()
s.listener.Close()
return err return err
} }
if err := setPassCred(conn); err != nil { if err := setPassCred(conn); err != nil {
@ -84,6 +82,12 @@ func (s *MsgServer) Run() error {
return nil return nil
} }
func (s *MsgServer) Close() error {
s.disp.close()
close(s.done)
return s.listener.Close()
}
func Connect(address string, factory MsgFactory, log *logging.Logger, handlers ...interface{}) (*MsgConn, error) { func Connect(address string, factory MsgFactory, log *logging.Logger, handlers ...interface{}) (*MsgConn, error) {
md, err := createDispatcher(log, handlers...) md, err := createDispatcher(log, handlers...)
if err != nil { if err != nil {

@ -11,7 +11,7 @@ type TestMsg struct {
} }
type testConnection struct { type testConnection struct {
server *MsgConn server *MsgServer
client *MsgConn client *MsgConn
wg sync.WaitGroup wg sync.WaitGroup
called bool called bool
@ -27,27 +27,23 @@ const testSocket = "@test"
var testFactory = NewMsgFactory(new(TestMsg)) var testFactory = NewMsgFactory(new(TestMsg))
func testConnect(handler func(*TestMsg, *Message) error) (*testConnection, error) { func testConnect(handler func(*TestMsg, *Message) error) (*testConnection, error) {
s := NewMsgConn(testFactory, testSocket) tc := &testConnection{}
c := NewMsgConn(testFactory, testSocket)
tc := &testConnection{
server: s,
client: c,
}
wrapper := func(tm *TestMsg, msg *Message) error { wrapper := func(tm *TestMsg, msg *Message) error {
err := handler(tm, msg) err := handler(tm, msg)
tc.called = true tc.called = true
tc.wg.Done() tc.wg.Done()
return err return err
} }
if err := s.AddHandlers(wrapper); err != nil { s, err := NewServer(testSocket, testFactory, nil, wrapper)
return nil, err if err != nil {
}
if err := s.Listen(); err != nil {
return nil, err return nil, err
} }
if err := c.Connect(); err != nil { c, err := Connect(testSocket, testFactory, nil)
if err != nil {
return nil, err return nil, err
} }
tc.server = s
tc.client = c
tc.wg.Add(1) tc.wg.Add(1)
go tc.server.Run() go tc.server.Run()
return tc, nil return tc, nil

@ -4,7 +4,6 @@ import (
"bufio" "bufio"
"fmt" "fmt"
"io" "io"
"os"
"os/exec" "os/exec"
"os/user" "os/user"
"path" "path"
@ -226,9 +225,34 @@ func (sbox *Sandbox) startXpraClient() {
sbox.fs.Xpra(), sbox.fs.Xpra(),
sbox.profile.Name, sbox.profile.Name,
sbox.daemon.log) 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 { if err := sbox.xpra.Process.Start(); err != nil {
sbox.daemon.Warning("Failed to start xpra client: %v", err) 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)
}
}

Loading…
Cancel
Save