pass display number to use for xpra instance to oz-init

networking
brl 9 years ago
parent e9be258644
commit 3bc8076a92

@ -16,6 +16,7 @@ type daemonState struct {
profiles oz.Profiles
sandboxes []*Sandbox
nextSboxId int
nextDisplay int
memBackend *logging.ChannelMemoryBackend
backends []logging.Backend
}
@ -47,6 +48,7 @@ func initialize() *daemonState {
d.profiles = ps
oz.ReapChildProcs(d.log, d.handleChildExit)
d.nextSboxId = 1
d.nextDisplay = 100
return d
}

@ -17,6 +17,7 @@ const initPath = "/usr/local/bin/oz-init"
type Sandbox struct {
daemon *daemonState
id int
display int
profile *oz.Profile
init *exec.Cmd
fs *fs.Filesystem
@ -36,7 +37,7 @@ func findSandbox(id int) *Sandbox {
*/
const initCloneFlags = syscall.CLONE_NEWNS | syscall.CLONE_NEWIPC | syscall.CLONE_NEWPID | syscall.CLONE_NEWUTS
func createInitCommand(addr, name, chroot string, uid uint32) *exec.Cmd {
func createInitCommand(addr, name, chroot string, uid uint32, display int) *exec.Cmd {
cmd := exec.Command(initPath)
cmd.Dir = "/"
cmd.SysProcAttr = &syscall.SysProcAttr{
@ -48,6 +49,9 @@ func createInitCommand(addr, name, chroot string, uid uint32) *exec.Cmd {
"INIT_PROFILE="+name,
fmt.Sprintf("INIT_UID=%d", uid),
}
if display > 0 {
cmd.Env = append(cmd.Env, fmt.Sprintf("INIT_DISPLAY=%d", display))
}
return cmd
}
@ -64,7 +68,13 @@ func (d *daemonState) launch(p *oz.Profile, uid uint32) (*Sandbox, error) {
if err != nil {
return nil, err
}
cmd := createInitCommand(addr, p.Name, fs.Root(), uid)
display := 0
if p.XServer.Enabled {
display = d.nextDisplay
d.nextDisplay += 1
}
cmd := createInitCommand(addr, p.Name, fs.Root(), uid, display)
pp,err := cmd.StderrPipe()
if err != nil {
fs.Cleanup()
@ -78,6 +88,7 @@ func (d *daemonState) launch(p *oz.Profile, uid uint32) (*Sandbox, error) {
sbox := &Sandbox{
daemon: d,
id: d.nextSboxId,
display: display,
profile: p,
init: cmd,
fs: fs,

@ -25,8 +25,6 @@ type initState struct {
fs *fs.Filesystem
}
//var log = createLogger()
// By convention oz-init writes log messages to stderr with a single character
// prefix indicating the logging level. These messages are read one line at a time
// over a pipe by oz-daemon and translated into appropriate log events.
@ -61,6 +59,10 @@ func Main() {
Name: "uid",
EnvVar: "INIT_UID",
},
cli.IntFlag{
Name: "display",
EnvVar: "INIT_DISPLAY",
},
}
app.Run(os.Args)
}
@ -71,6 +73,8 @@ func runInit(c *cli.Context) {
address := c.String("address")
profile := c.String("profile")
uid := uint32(c.Int("uid"))
disp := c.Int("display")
if address == "" {
st.log.Error("Error: missing required 'address' argument")
os.Exit(1)
@ -101,7 +105,11 @@ func runInit(c *cli.Context) {
}
st.fs = fs
if p.XServer.Enabled {
st.startXpraServer(&p.XServer, fs)
if disp == 0 {
st.log.Error("Cannot start xpra because no display number was passed to oz-init")
os.Exit(1)
}
st.startXpraServer(&p.XServer, fs, disp)
}
oz.ReapChildProcs(st.log, st.handleChildExit)
@ -116,7 +124,7 @@ func runInit(c *cli.Context) {
st.log.Info("oz-init exiting...")
}
func (is *initState) startXpraServer (config *oz.XServerConf, fs *fs.Filesystem) {
func (is *initState) startXpraServer (config *oz.XServerConf, fs *fs.Filesystem, display int) {
workdir := fs.Xpra()
if workdir == "" {
is.log.Warning("Xpra work directory not set")
@ -129,7 +137,7 @@ func (is *initState) startXpraServer (config *oz.XServerConf, fs *fs.Filesystem
return
}
defer f.Close()
xpra := xpra.NewServer(config, 123, workdir)
xpra := xpra.NewServer(config, uint64(display), workdir)
xpra.Process.Stdout = f
xpra.Process.Stderr = f
xpra.Process.Env = []string{

Loading…
Cancel
Save