networking
brl 10 years ago
parent e28f599224
commit eee260576b

@ -1,10 +1,10 @@
package oz package oz
import ( import (
"syscall"
"github.com/op/go-logging" "github.com/op/go-logging"
"os" "os"
"os/signal" "os/signal"
"syscall"
) )
func ReapChildProcs(log *logging.Logger, callback func(int, syscall.WaitStatus)) chan os.Signal { func ReapChildProcs(log *logging.Logger, callback func(int, syscall.WaitStatus)) chan os.Signal {

@ -1,4 +1,5 @@
package main package main
import ( import (
"github.com/subgraph/oz/oz-daemon" "github.com/subgraph/oz/oz-daemon"
) )

@ -1,7 +1,7 @@
package main package main
import "github.com/subgraph/oz/oz-init" import "github.com/subgraph/oz/oz-init"
func main() { func main() {
ozinit.Main() ozinit.Main()
} }

@ -1,12 +1,12 @@
package fs package fs
import ( import (
"errors"
"github.com/op/go-logging"
"io/ioutil" "io/ioutil"
"sort" "sort"
"strings" "strings"
"syscall" "syscall"
"errors"
"github.com/op/go-logging"
) )
func (fs *Filesystem) Cleanup() error { func (fs *Filesystem) Cleanup() error {

@ -2,12 +2,12 @@ package fs
import ( import (
"fmt" "fmt"
"github.com/op/go-logging"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
"strings" "strings"
"syscall" "syscall"
"github.com/op/go-logging"
) )
type MountFlag int type MountFlag int

@ -1,13 +1,13 @@
package fs package fs
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
"path"
"syscall"
"os/user" "os/user"
"path"
"strconv" "strconv"
"errors" "syscall"
) )
var basicBindDirs = []string{ var basicBindDirs = []string{

@ -1,9 +1,10 @@
package ipc package ipc
import ( import (
"reflect"
"errors" "errors"
"fmt" "fmt"
"github.com/op/go-logging" "github.com/op/go-logging"
"reflect"
) )
type handlerMap map[string]reflect.Value type handlerMap map[string]reflect.Value
@ -125,5 +126,3 @@ func typeCheckHandler(h interface{}) (string, error) {
} }
return string(in0.Field(0).Tag), nil return string(in0.Field(0).Tag), nil
} }

@ -1,8 +1,9 @@
package ipc package ipc
import ( import (
"testing"
"reflect"
"errors" "errors"
"reflect"
"testing"
) )
func TestTypeCheckHandler(t *testing.T) { func TestTypeCheckHandler(t *testing.T) {
@ -48,8 +49,12 @@ func TestAddHandler(t *testing.T) {
} }
func TestDispatch(t *testing.T) { func TestDispatch(t *testing.T) {
type testStruct struct{ t int "tester"} type testStruct struct {
type testStruct2 struct{ t int "tester2"} t int "tester"
}
type testStruct2 struct {
t int "tester2"
}
count := 0 count := 0
h1 := func(ts *testStruct, m *Message) error { h1 := func(ts *testStruct, m *Message) error {
count += 1 count += 1

@ -6,10 +6,10 @@ import (
"net" "net"
"syscall" "syscall"
"github.com/op/go-logging"
"reflect"
"fmt" "fmt"
"github.com/op/go-logging"
"io" "io"
"reflect"
) )
const maxFdCount = 3 const maxFdCount = 3
@ -216,7 +216,6 @@ func (mc *MsgConn) readMessage() (*Message, error) {
// conn.AddHandlers(fooHandler, simpleHandler) // conn.AddHandlers(fooHandler, simpleHandler)
// //
func (mc *MsgConn) AddHandlers(args ...interface{}) error { func (mc *MsgConn) AddHandlers(args ...interface{}) error {
for len(args) > 0 { for len(args) > 0 {
if err := mc.disp.hmap.addHandler(args[0]); err != nil { if err := mc.disp.hmap.addHandler(args[0]); err != nil {
@ -272,7 +271,6 @@ func getMessageType(msg interface{}) (string, error) {
return string(t.Field(0).Tag), nil return string(t.Field(0).Tag), nil
} }
func (mc *MsgConn) newBaseMessage(msgType string, msgID int, body interface{}) (*BaseMsg, error) { func (mc *MsgConn) newBaseMessage(msgType string, msgID int, body interface{}) (*BaseMsg, error) {
bodyBytes, err := json.Marshal(body) bodyBytes, err := json.Marshal(body)
if err != nil { if err != nil {
@ -298,4 +296,3 @@ func (mc *MsgConn) sendWithFds(data []byte, fds []int) error {
_, _, err := mc.conn.WriteMsgUnix(data, oob, nil) _, _, err := mc.conn.WriteMsgUnix(data, oob, nil)
return err return err
} }

@ -1,8 +1,9 @@
package ipc package ipc
import ( import (
"testing"
"sync"
"os" "os"
"sync"
"testing"
) )
type TestMsg struct { type TestMsg struct {
@ -20,7 +21,9 @@ type testServer struct {
conn *MsgConn conn *MsgConn
wg sync.WaitGroup wg sync.WaitGroup
} }
const testSocket = "@test" 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) {

@ -2,14 +2,12 @@ package ipc
import ( import (
"encoding/json" "encoding/json"
"syscall" "errors"
"fmt" "fmt"
"reflect" "reflect"
"errors" "syscall"
) )
func NewMsgFactory(msgTypes ...interface{}) MsgFactory { func NewMsgFactory(msgTypes ...interface{}) MsgFactory {
mf := (MsgFactory)(make(map[string]func() interface{})) mf := (MsgFactory)(make(map[string]func() interface{}))
for _, mt := range msgTypes { for _, mt := range msgTypes {

@ -1,7 +1,8 @@
package ipc package ipc
import ( import (
"time"
"sync" "sync"
"time"
) )
type ResponseReader interface { type ResponseReader interface {
@ -75,4 +76,3 @@ func (rm *responseManager) removeById(id int, klose bool) *responseWaiter{
} }
return rw return rw
} }

@ -1,4 +1,5 @@
package ipc package ipc
import ( import (
"testing" "testing"
) )

@ -1,9 +1,10 @@
package daemon package daemon
import ( import (
"github.com/subgraph/oz/ipc"
"errors" "errors"
"strconv"
"fmt" "fmt"
"github.com/subgraph/oz/ipc"
"strconv"
) )
func clientConnect() (*ipc.MsgConn, error) { func clientConnect() (*ipc.MsgConn, error) {

@ -1,6 +1,5 @@
package daemon package daemon
type Config struct { type Config struct {
profileDir string `json:"profile_dir"` profileDir string `json:"profile_dir"`
} }

@ -5,10 +5,10 @@ import (
"github.com/op/go-logging" "github.com/op/go-logging"
"github.com/subgraph/oz" "github.com/subgraph/oz"
"github.com/subgraph/oz/ipc"
"syscall"
"github.com/subgraph/oz/fs" "github.com/subgraph/oz/fs"
"github.com/subgraph/oz/ipc"
"os/user" "os/user"
"syscall"
) )
type daemonState struct { type daemonState struct {
@ -53,7 +53,6 @@ func initialize() *daemonState {
return d return d
} }
func (d *daemonState) handleChildExit(pid int, wstatus syscall.WaitStatus) { func (d *daemonState) handleChildExit(pid int, wstatus syscall.WaitStatus) {
d.Debug("Child process pid=%d exited with status %d", pid, wstatus.ExitStatus()) d.Debug("Child process pid=%d exited with status %d", pid, wstatus.ExitStatus())
@ -160,4 +159,3 @@ func (d *daemonState) handleLogs(logs *LogsMsg, msg *ipc.Message) error {
msg.Respond(&OkMsg{}) msg.Respond(&OkMsg{})
return nil return nil
} }

@ -1,21 +1,21 @@
package daemon package daemon
import ( import (
"bufio"
"fmt"
"github.com/subgraph/oz" "github.com/subgraph/oz"
"github.com/subgraph/oz/fs" "github.com/subgraph/oz/fs"
"os/exec"
"syscall"
"fmt"
"io"
"bufio"
"os/user"
"github.com/subgraph/oz/xpra" "github.com/subgraph/oz/xpra"
"io"
"os" "os"
"os/exec"
"os/user"
"path" "path"
"syscall"
) )
const initPath = "/usr/local/bin/oz-init" const initPath = "/usr/local/bin/oz-init"
type Sandbox struct { type Sandbox struct {
daemon *daemonState daemon *daemonState
id int id int
@ -142,7 +142,7 @@ func (sbox *Sandbox) logLine(line string) {
func (sbox *Sandbox) getLogFunc(c byte) func(string, ...interface{}) { func (sbox *Sandbox) getLogFunc(c byte) func(string, ...interface{}) {
log := sbox.daemon.log log := sbox.daemon.log
switch(c) { switch c {
case 'D': case 'D':
return log.Debug return log.Debug
case 'I': case 'I':

@ -1,12 +1,12 @@
package daemon package daemon
import ( import (
"github.com/op/go-logging" "github.com/op/go-logging"
"github.com/subgraph/oz/ipc"
"log" "log"
"os" "os"
"github.com/subgraph/oz/ipc"
) )
func (d *daemonState) Debug(format string, args ...interface{}) { func (d *daemonState) Debug(format string, args ...interface{}) {
d.log.Debug(format, args...) d.log.Debug(format, args...)
} }
@ -38,9 +38,11 @@ func (d *daemonState) initializeLogging() {
} }
d.installBackends() d.installBackends()
} }
var format = logging.MustStringFormatter( var format = logging.MustStringFormatter(
"%{color}%{time:15:04:05} â–¶ %{level:.4s} %{id:03x}%{color:reset} %{message}", "%{color}%{time:15:04:05} â–¶ %{level:.4s} %{id:03x}%{color:reset} %{message}",
) )
func (d *daemonState) addBackend(be logging.Backend) { func (d *daemonState) addBackend(be logging.Backend) {
d.backends = append(d.backends, be) d.backends = append(d.backends, be)
d.installBackends() d.installBackends()

@ -1,4 +1,5 @@
package daemon package daemon
import "github.com/subgraph/oz/ipc" import "github.com/subgraph/oz/ipc"
const SocketName = "@oz-control" const SocketName = "@oz-control"
@ -75,4 +76,3 @@ var messageFactory = ipc.NewMsgFactory(
new(LogsMsg), new(LogsMsg),
new(LogData), new(LogData),
) )

@ -1,8 +1,9 @@
package ozinit package ozinit
import ( import (
"github.com/subgraph/oz/ipc"
"errors" "errors"
"fmt" "fmt"
"github.com/subgraph/oz/ipc"
) )
func clientConnect(addr string) (*ipc.MsgConn, error) { func clientConnect(addr string) (*ipc.MsgConn, error) {
@ -64,5 +65,3 @@ func RunShell(addr, term string) (int, error) {
return 0, fmt.Errorf("Unexpected message type received: %+v", body) return 0, fmt.Errorf("Unexpected message type received: %+v", body)
} }
} }

@ -1,21 +1,21 @@
package ozinit package ozinit
import ( import (
"os" "bufio"
"fmt"
"github.com/kr/pty"
"github.com/op/go-logging"
"github.com/subgraph/oz" "github.com/subgraph/oz"
"github.com/subgraph/oz/fs" "github.com/subgraph/oz/fs"
"github.com/subgraph/oz/ipc" "github.com/subgraph/oz/ipc"
"os/exec"
"syscall"
"github.com/op/go-logging"
"github.com/kr/pty"
"fmt"
"github.com/subgraph/oz/xpra" "github.com/subgraph/oz/xpra"
"io"
"os"
"os/exec"
"os/user" "os/user"
"strconv" "strconv"
"io"
"bufio"
"strings" "strings"
"syscall"
) )
const profileDirectory = "/var/lib/oz/cells.d" const profileDirectory = "/var/lib/oz/cells.d"
@ -261,4 +261,3 @@ func ptyStart(c *exec.Cmd) (ptty *os.File, err error) {
func (is *initState) handleChildExit(pid int, wstatus syscall.WaitStatus) { func (is *initState) handleChildExit(pid int, wstatus syscall.WaitStatus) {
is.log.Debug("Child process pid=%d exited with status %d", pid, wstatus.ExitStatus()) is.log.Debug("Child process pid=%d exited with status %d", pid, wstatus.ExitStatus())
} }

@ -1,4 +1,5 @@
package ozinit package ozinit
import "github.com/subgraph/oz/ipc" import "github.com/subgraph/oz/ipc"
type OkMsg struct { type OkMsg struct {
@ -23,4 +24,3 @@ var messageFactory = ipc.NewMsgFactory(
new(PingMsg), new(PingMsg),
new(RunShellMsg), new(RunShellMsg),
) )

@ -3,11 +3,11 @@ package main
import ( import (
"fmt" "fmt"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"os"
"github.com/subgraph/oz/oz-daemon" "github.com/subgraph/oz/oz-daemon"
"strconv"
"io"
"github.com/subgraph/oz/oz-init" "github.com/subgraph/oz/oz-init"
"io"
"os"
"strconv"
) )
func main() { func main() {
@ -41,7 +41,6 @@ func main() {
{ {
Name: "clean", Name: "clean",
Action: handleClean, Action: handleClean,
}, },
{ {
Name: "logs", Name: "logs",
@ -50,7 +49,6 @@ func main() {
cli.BoolFlag{ cli.BoolFlag{
Name: "f", Name: "f",
}, },
}, },
}, },
} }
@ -130,7 +128,6 @@ func handleShell(c *cli.Context) {
fmt.Println("done..") fmt.Println("done..")
} }
func getSandboxById(id int) (*daemon.SandboxInfo, error) { func getSandboxById(id int) (*daemon.SandboxInfo, error) {
sboxes, err := daemon.ListSandboxes() sboxes, err := daemon.ListSandboxes()
if err != nil { if err != nil {

@ -1,10 +1,11 @@
package main package main
import ( import (
"syscall" "fmt"
"unsafe"
"os" "os"
"os/signal" "os/signal"
"fmt" "syscall"
"unsafe"
) )
type winsize struct { type winsize struct {

@ -1,9 +1,10 @@
package xpra package xpra
import ( import (
"github.com/subgraph/oz"
"fmt" "fmt"
"os"
"github.com/op/go-logging" "github.com/op/go-logging"
"github.com/subgraph/oz"
"os"
"os/exec" "os/exec"
"syscall" "syscall"
) )

@ -1,7 +1,8 @@
package xpra package xpra
import ( import (
"github.com/subgraph/oz"
"fmt" "fmt"
"github.com/subgraph/oz"
"os" "os"
"os/exec" "os/exec"
) )
@ -37,4 +38,3 @@ func prepareServerArgs(config *oz.XServerConf, display uint64, workdir string) [
) )
return args return args
} }

@ -1,7 +1,8 @@
package xpra package xpra
import ( import (
"os/exec"
"github.com/subgraph/oz" "github.com/subgraph/oz"
"os/exec"
) )
type Xpra struct { type Xpra struct {
@ -18,7 +19,6 @@ type Xpra struct {
// Arguments passed to xpra command // Arguments passed to xpra command
xpraArgs []string xpraArgs []string
} }
var xpraDefaultArgs = []string{ var xpraDefaultArgs = []string{
@ -52,4 +52,3 @@ func getDefaultArgs(config *oz.XServerConf) []string {
return args return args
} }

Loading…
Cancel
Save