mirror of
https://github.com/criyle/go-sandbox.git
synced 2025-11-04 14:49:53 +08:00
Fix work dir
This commit is contained in:
parent
c832edba58
commit
64df5951ed
@ -13,8 +13,6 @@ const (
|
||||
|
||||
initArg = "container_init"
|
||||
|
||||
currentExec = "/proc/self/exe"
|
||||
|
||||
containerUID = 1000
|
||||
containerGID = 1000
|
||||
|
||||
|
||||
@ -52,11 +52,13 @@ func (c *containerServer) handleDelete(delete *deleteCmd) error {
|
||||
}
|
||||
|
||||
func (c *containerServer) handleReset() error {
|
||||
if err := removeContents("/tmp"); err != nil {
|
||||
return c.sendErrorReply("reset: /tmp %v", err)
|
||||
}
|
||||
if err := removeContents("/w"); err != nil {
|
||||
return c.sendErrorReply("reset: /w %v", err)
|
||||
for _, m := range c.Mounts {
|
||||
if !m.IsTmpFs() {
|
||||
continue
|
||||
}
|
||||
if err := removeContents(m.Target); err != nil {
|
||||
return c.sendErrorReply("reset: %v %v", m.Target, err)
|
||||
}
|
||||
}
|
||||
return c.sendReply(&reply{}, nil)
|
||||
}
|
||||
|
||||
@ -71,7 +71,7 @@ func (c *containerServer) handleExecve(cmd *execCmd, msg *unixsocket.Msg) error
|
||||
ExecFile: execFile,
|
||||
RLimits: cmd.RLimits,
|
||||
Files: files,
|
||||
WorkDir: "/w",
|
||||
WorkDir: c.WorkDir,
|
||||
NoNewPrivs: true,
|
||||
DropCaps: true,
|
||||
SyncFunc: syncFunc,
|
||||
|
||||
@ -212,19 +212,6 @@ func (c *container) Destroy() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// exec prepares executable
|
||||
func (b *Builder) exec() (*os.File, error) {
|
||||
if b.ExecFile != "" {
|
||||
return os.Open(b.ExecFile)
|
||||
}
|
||||
return OpenCurrentExec()
|
||||
}
|
||||
|
||||
// OpenCurrentExec opens current executable (/proc/self/exe)
|
||||
func OpenCurrentExec() (*os.File, error) {
|
||||
return os.Open(currentExec)
|
||||
}
|
||||
|
||||
// newPassCredSocketPair creates socket pair and let the first socket to receive credential information
|
||||
func newPassCredSocketPair() (*unixsocket.Socket, *unixsocket.Socket, error) {
|
||||
ins, outs, err := unixsocket.NewSocketPair()
|
||||
|
||||
@ -35,6 +35,11 @@ func (m Mount) IsReadOnly() bool {
|
||||
return m.Flags&syscall.MS_RDONLY == syscall.MS_RDONLY
|
||||
}
|
||||
|
||||
// IsTmpFs returns if the fsType is tmpfs
|
||||
func (m Mount) IsTmpFs() bool {
|
||||
return m.FsType == "tmpfs"
|
||||
}
|
||||
|
||||
func ensureMountTargetExists(source, target string) error {
|
||||
isFile := false
|
||||
if fi, err := os.Stat(source); err == nil {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user