|
|
|
@ -12,10 +12,11 @@ import (
|
|
|
|
|
|
|
|
|
|
"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 = "/"
|
|
|
|
|
|
|
|
|
@ -69,18 +70,22 @@ func createInitCommand(name, chroot string, uid uint32, display int, stn *networ
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
@ -103,7 +108,7 @@ func (d *daemonState) launch(p *oz.Profile, uid, gid uint32, log *logging.Logger
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 {
|
|
|
|
@ -117,7 +122,6 @@ func (d *daemonState) launch(p *oz.Profile, uid, gid uint32, log *logging.Logger
|
|
|
|
|
return nil, fmt.Errorf("Unable to start process: %+v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sbox := &Sandbox{
|
|
|
|
|
daemon: d,
|
|
|
|
|
id: d.nextSboxId,
|
|
|
|
|