|
|
@ -19,10 +19,10 @@ import (
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
const profileDirectory = "/var/lib/oz/cells.d"
|
|
|
|
const profileDirectory = "/var/lib/oz/cells.d"
|
|
|
|
|
|
|
|
const socketAddress = "/tmp/oz-init-control"
|
|
|
|
|
|
|
|
|
|
|
|
type initState struct {
|
|
|
|
type initState struct {
|
|
|
|
log *logging.Logger
|
|
|
|
log *logging.Logger
|
|
|
|
address string
|
|
|
|
|
|
|
|
profile *oz.Profile
|
|
|
|
profile *oz.Profile
|
|
|
|
uid int
|
|
|
|
uid int
|
|
|
|
gid int
|
|
|
|
gid int
|
|
|
@ -61,7 +61,6 @@ func parseArgs() *initState {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return val
|
|
|
|
return val
|
|
|
|
}
|
|
|
|
}
|
|
|
|
addr := getvar("INIT_ADDRESS")
|
|
|
|
|
|
|
|
pname := getvar("INIT_PROFILE")
|
|
|
|
pname := getvar("INIT_PROFILE")
|
|
|
|
uidval := getvar("INIT_UID")
|
|
|
|
uidval := getvar("INIT_UID")
|
|
|
|
dispval := os.Getenv("INIT_DISPLAY")
|
|
|
|
dispval := os.Getenv("INIT_DISPLAY")
|
|
|
@ -98,7 +97,6 @@ func parseArgs() *initState {
|
|
|
|
|
|
|
|
|
|
|
|
return &initState{
|
|
|
|
return &initState{
|
|
|
|
log: log,
|
|
|
|
log: log,
|
|
|
|
address: addr,
|
|
|
|
|
|
|
|
profile: p,
|
|
|
|
profile: p,
|
|
|
|
uid: uid,
|
|
|
|
uid: uid,
|
|
|
|
gid: gid,
|
|
|
|
gid: gid,
|
|
|
@ -110,7 +108,6 @@ func parseArgs() *initState {
|
|
|
|
|
|
|
|
|
|
|
|
func (st *initState) runInit() {
|
|
|
|
func (st *initState) runInit() {
|
|
|
|
st.log.Info("Starting oz-init for profile: %s", st.profile.Name)
|
|
|
|
st.log.Info("Starting oz-init for profile: %s", st.profile.Name)
|
|
|
|
st.log.Info("Socket address: %s", st.address)
|
|
|
|
|
|
|
|
if syscall.Sethostname([]byte(st.profile.Name)) != nil {
|
|
|
|
if syscall.Sethostname([]byte(st.profile.Name)) != nil {
|
|
|
|
st.log.Error("Failed to set hostname to (%s)", st.profile.Name)
|
|
|
|
st.log.Error("Failed to set hostname to (%s)", st.profile.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -130,12 +127,20 @@ func (st *initState) runInit() {
|
|
|
|
|
|
|
|
|
|
|
|
oz.ReapChildProcs(st.log, st.handleChildExit)
|
|
|
|
oz.ReapChildProcs(st.log, st.handleChildExit)
|
|
|
|
|
|
|
|
|
|
|
|
err := ipc.RunServer(st.address, messageFactory, st.log,
|
|
|
|
s,err := ipc.NewServer(socketAddress, messageFactory, st.log,
|
|
|
|
handlePing,
|
|
|
|
handlePing,
|
|
|
|
st.handleRunShell,
|
|
|
|
st.handleRunShell,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
st.log.Warning("RunServer returned err: %v", err)
|
|
|
|
st.log.Error("NewServer failed: %v", err)
|
|
|
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := os.Chown(socketAddress, st.uid, st.gid); err != nil {
|
|
|
|
|
|
|
|
st.log.Warning("Failed to chown oz-init control socket: %v", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := s.Run(); err != nil {
|
|
|
|
|
|
|
|
st.log.Warning("MsgServer.Run() return err: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
st.log.Info("oz-init exiting...")
|
|
|
|
st.log.Info("oz-init exiting...")
|
|
|
|
}
|
|
|
|
}
|
|
|
|