|
|
|
@ -9,13 +9,14 @@ import (
|
|
|
|
|
"path"
|
|
|
|
|
"sync"
|
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/subgraph/oz"
|
|
|
|
|
"github.com/subgraph/oz/fs"
|
|
|
|
|
"github.com/subgraph/oz/xpra"
|
|
|
|
|
"github.com/subgraph/oz/network"
|
|
|
|
|
|
|
|
|
|
"github.com/subgraph/oz/xpra"
|
|
|
|
|
|
|
|
|
|
"github.com/op/go-logging"
|
|
|
|
|
"github.com/subgraph/oz/oz-init"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const initPath = "/usr/local/bin/oz-init"
|
|
|
|
@ -46,7 +47,7 @@ func findSandbox(id int) *Sandbox {
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
func createInitCommand(name, chroot string, uid uint32, display int, stn *network.SandboxNetwork, nettype string) *exec.Cmd {
|
|
|
|
|
func createInitCommand(name, chroot string, env []string, uid uint32, display int, stn *network.SandboxNetwork, nettype string) *exec.Cmd {
|
|
|
|
|
cmd := exec.Command(initPath)
|
|
|
|
|
cmd.Dir = "/"
|
|
|
|
|
|
|
|
|
@ -54,11 +55,11 @@ func createInitCommand(name, chroot string, uid uint32, display int, stn *networ
|
|
|
|
|
cloneFlags |= syscall.CLONE_NEWIPC
|
|
|
|
|
cloneFlags |= syscall.CLONE_NEWPID
|
|
|
|
|
cloneFlags |= syscall.CLONE_NEWUTS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if nettype != "host" {
|
|
|
|
|
cloneFlags |= syscall.CLONE_NEWNET
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cmd.SysProcAttr = &syscall.SysProcAttr{
|
|
|
|
|
Chroot: chroot,
|
|
|
|
|
Cloneflags: cloneFlags,
|
|
|
|
@ -67,20 +68,24 @@ func createInitCommand(name, chroot string, uid uint32, display int, stn *networ
|
|
|
|
|
"INIT_PROFILE=" + name,
|
|
|
|
|
fmt.Sprintf("INIT_UID=%d", uid),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if stn.Ip != "" {
|
|
|
|
|
cmd.Env = append(cmd.Env, "INIT_ADDR=" + stn.Ip)
|
|
|
|
|
cmd.Env = append(cmd.Env, "INIT_VHOST=" + stn.VethHost)
|
|
|
|
|
cmd.Env = append(cmd.Env, "INIT_VGUEST=" + stn.VethGuest)
|
|
|
|
|
cmd.Env = append(cmd.Env, "INIT_GATEWAY=" + stn.Gateway.String() + "/" + stn.Class)
|
|
|
|
|
cmd.Env = append(cmd.Env, "INIT_ADDR="+stn.Ip)
|
|
|
|
|
cmd.Env = append(cmd.Env, "INIT_VHOST="+stn.VethHost)
|
|
|
|
|
cmd.Env = append(cmd.Env, "INIT_VGUEST="+stn.VethGuest)
|
|
|
|
|
cmd.Env = append(cmd.Env, "INIT_GATEWAY="+stn.Gateway.String()+"/"+stn.Class)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cmd.Env = append(cmd.Env, fmt.Sprintf("INIT_DISPLAY=%d", display))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, e := range env {
|
|
|
|
|
cmd.Env = append(cmd.Env, ozinit.EnvPrefix+e)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (d *daemonState) launch(p *oz.Profile, uid, gid uint32, log *logging.Logger) (*Sandbox, error) {
|
|
|
|
|
func (d *daemonState) launch(p *oz.Profile, env []string, uid, gid uint32, log *logging.Logger) (*Sandbox, error) {
|
|
|
|
|
u, err := user.LookupId(fmt.Sprintf("%d", uid))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("failed to lookup user for uid=%d: %v", uid, err)
|
|
|
|
@ -90,11 +95,11 @@ func (d *daemonState) launch(p *oz.Profile, uid, gid uint32, log *logging.Logger
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
display := 0
|
|
|
|
|
if p.XServer.Enabled && p.Networking.Nettype == "host" {
|
|
|
|
|
if p.XServer.Enabled && p.Networking.Nettype == "host" {
|
|
|
|
|
display = d.nextDisplay
|
|
|
|
|
d.nextDisplay += 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stn := new(network.SandboxNetwork)
|
|
|
|
|
if p.Networking.Nettype == "bridge" {
|
|
|
|
|
stn, err = network.PrepareSandboxNetwork(d.network, log)
|
|
|
|
@ -102,8 +107,8 @@ func (d *daemonState) launch(p *oz.Profile, uid, gid uint32, log *logging.Logger
|
|
|
|
|
return nil, fmt.Errorf("Unable to prepare veth network: %+v", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmd := createInitCommand(p.Name, fs.Root(), uid, display, stn, p.Networking.Nettype)
|
|
|
|
|
|
|
|
|
|
cmd := createInitCommand(p.Name, fs.Root(), env, uid, display, stn, p.Networking.Nettype)
|
|
|
|
|
log.Debug("Command environment: %+v", cmd.Env)
|
|
|
|
|
pp, err := cmd.StderrPipe()
|
|
|
|
|
if err != nil {
|
|
|
|
@ -111,13 +116,12 @@ func (d *daemonState) launch(p *oz.Profile, uid, gid uint32, log *logging.Logger
|
|
|
|
|
return nil, fmt.Errorf("error creating stderr pipe for init process: %v", err)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := cmd.Start(); err != nil {
|
|
|
|
|
fs.Cleanup()
|
|
|
|
|
return nil, fmt.Errorf("Unable to start process: %+v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sbox := &Sandbox{
|
|
|
|
|
daemon: d,
|
|
|
|
|
id: d.nextSboxId,
|
|
|
|
@ -130,7 +134,7 @@ func (d *daemonState) launch(p *oz.Profile, uid, gid uint32, log *logging.Logger
|
|
|
|
|
stderr: pp,
|
|
|
|
|
network: stn,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if p.Networking.Nettype == "bridge" {
|
|
|
|
|
if err := network.NetInit(stn, d.network, cmd.Process.Pid, log); err != nil {
|
|
|
|
|
cmd.Process.Kill()
|
|
|
|
@ -138,7 +142,7 @@ func (d *daemonState) launch(p *oz.Profile, uid, gid uint32, log *logging.Logger
|
|
|
|
|
return nil, fmt.Errorf("Unable to create veth networking: %+v", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sbox.ready.Add(1)
|
|
|
|
|
go sbox.logMessages()
|
|
|
|
|
if sbox.profile.XServer.Enabled {
|
|
|
|
|