Fixed passing of pwd to command, fixed home environment variable to launchEnv, fixed PATH var

master
xSmurf 10 years ago
parent a5ddbf0166
commit 0f682806ab

@ -16,9 +16,9 @@ import (
"github.com/subgraph/oz/fs" "github.com/subgraph/oz/fs"
"github.com/subgraph/oz/network" "github.com/subgraph/oz/network"
"github.com/subgraph/oz/xpra" "github.com/subgraph/oz/xpra"
"github.com/subgraph/oz/oz-init"
"github.com/op/go-logging" "github.com/op/go-logging"
"github.com/subgraph/oz/oz-init"
) )
type Sandbox struct { type Sandbox struct {
@ -146,6 +146,7 @@ func (d *daemonState) launch(p *oz.Profile, pwd string, args, env []string, uid,
go sbox.startXpraClient() go sbox.startXpraClient()
}() }()
} }
d.nextSboxId += 1 d.nextSboxId += 1
d.sandboxes = append(d.sandboxes, sbox) d.sandboxes = append(d.sandboxes, sbox)
return sbox, nil return sbox, nil
@ -164,7 +165,7 @@ func (sbox *Sandbox) launchProgram(pwd string, args []string, log *logging.Logge
} }
} }
err := ozinit.RunProgram(sbox.addr, args) err := ozinit.RunProgram(sbox.addr, pwd, args)
if err != nil { if err != nil {
log.Error("start shell command failed: %v", err) log.Error("start shell command failed: %v", err)
} }

@ -41,12 +41,12 @@ func Ping(addr string) error {
} }
} }
func RunProgram(addr string, args []string) error { func RunProgram(addr, pwd string, args []string) error {
c, err := clientConnect(addr) c, err := clientConnect(addr)
if err != nil { if err != nil {
return err return err
} }
rr, err := c.ExchangeMsg(&RunProgramMsg{Args: args}) rr, err := c.ExchangeMsg(&RunProgramMsg{Args: args, Pwd: pwd})
resp := <-rr.Chan() resp := <-rr.Chan()
rr.Done() rr.Done()
c.Close() c.Close()

@ -145,6 +145,8 @@ func parseArgs() *initState {
} }
} }
env = append(env, "PATH=/usr/bin:/bin")
if p.XServer.Enabled { if p.XServer.Enabled {
env = append(env, "DISPLAY=:"+strconv.Itoa(display)) env = append(env, "DISPLAY=:"+strconv.Itoa(display))
} }
@ -169,6 +171,10 @@ func (st *initState) runInit() {
sigs := make(chan os.Signal) sigs := make(chan os.Signal)
signal.Notify(sigs, syscall.SIGTERM, os.Interrupt) signal.Notify(sigs, syscall.SIGTERM, os.Interrupt)
if homedir, _ := st.fs.GetHomeDir(); homedir != "" {
st.launchEnv = append(st.launchEnv, "HOME="+homedir)
}
if st.profile.Networking.Nettype != "host" { if st.profile.Networking.Nettype != "host" {
err := network.NetSetup(st.network) err := network.NetSetup(st.network)
if err != nil { if err != nil {
@ -271,7 +277,7 @@ func (st *initState) readXpraOutput(r io.ReadCloser) {
} }
} }
func (st *initState) launchApplication(cmdArgs []string) (*exec.Cmd, error) { func (st *initState) launchApplication(pwd string, cmdArgs []string) (*exec.Cmd, error) {
suffix := "" suffix := ""
if st.config.DivertSuffix != "" { if st.config.DivertSuffix != "" {
suffix = "."+st.config.DivertSuffix suffix = "."+st.config.DivertSuffix
@ -294,6 +300,7 @@ func (st *initState) launchApplication(cmdArgs []string) (*exec.Cmd, error) {
} }
cmd.Env = append(cmd.Env, st.launchEnv...) cmd.Env = append(cmd.Env, st.launchEnv...)
cmd.Args = append(cmd.Args, cmdArgs...) cmd.Args = append(cmd.Args, cmdArgs...)
cmd.Dir = pwd
if err := cmd.Start(); err != nil { if err := cmd.Start(); err != nil {
st.log.Warning("Failed to start application (%s): %v", st.profile.Path, err) st.log.Warning("Failed to start application (%s): %v", st.profile.Path, err)
return nil, err return nil, err
@ -333,7 +340,7 @@ func handlePing(ping *PingMsg, msg *ipc.Message) error {
func (st *initState) handleRunProgram(rp *RunProgramMsg, msg *ipc.Message) error { func (st *initState) handleRunProgram(rp *RunProgramMsg, msg *ipc.Message) error {
st.log.Info("Run program message received: %+v", rp) st.log.Info("Run program message received: %+v", rp)
_, err := st.launchApplication(rp.Args) _, err := st.launchApplication(rp.Pwd, rp.Args)
if err != nil { if err != nil {
err := msg.Respond(&ErrorMsg{Msg: err.Error()}) err := msg.Respond(&ErrorMsg{Msg: err.Error()})
return err return err
@ -364,10 +371,8 @@ func (st *initState) handleRunShell(rs *RunShellMsg, msg *ipc.Message) error {
if msg.Ucred.Uid != 0 && msg.Ucred.Gid != 0 { if msg.Ucred.Uid != 0 && msg.Ucred.Gid != 0 {
if homedir, _ := st.fs.GetHomeDir(); homedir != "" { if homedir, _ := st.fs.GetHomeDir(); homedir != "" {
cmd.Dir = homedir cmd.Dir = homedir
cmd.Env = append(cmd.Env, "HOME="+homedir)
} }
} }
cmd.Env = append(cmd.Env, "PATH=/usr/bin:/bin")
cmd.Env = append(cmd.Env, fmt.Sprintf("PS1=[%s] $ ", st.profile.Name)) cmd.Env = append(cmd.Env, fmt.Sprintf("PS1=[%s] $ ", st.profile.Name))
st.log.Info("Executing shell...") st.log.Info("Executing shell...")
f, err := ptyStart(cmd) f, err := ptyStart(cmd)

@ -20,6 +20,7 @@ type RunShellMsg struct {
type RunProgramMsg struct { type RunProgramMsg struct {
Args []string "RunProgram" Args []string "RunProgram"
Pwd string
} }
var messageFactory = ipc.NewMsgFactory( var messageFactory = ipc.NewMsgFactory(

Loading…
Cancel
Save