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

networking
brl 10 years ago
parent e9be258644
commit 3bc8076a92

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

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

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

Loading…
Cancel
Save