pkg/osutil: replace UmountAll with RemoveAll

In pkg/ipc we don't just want to UmountAll,
we want to remove all handling as many cases as possible
(mounts, read-only files, etc, similar to executor's remove_dir).
So unmounting and removing needs to be a single function,
so that it can handle all these cases.
This commit is contained in:
Dmitry Vyukov 2018-08-04 15:50:40 +02:00
parent df7f6947ba
commit 3476a2dfb9
7 changed files with 17 additions and 9 deletions

View File

@ -573,8 +573,7 @@ func (c *command) close() {
c.cmd.Process.Kill()
c.wait()
}
osutil.UmountAll(c.dir)
os.RemoveAll(c.dir)
osutil.RemoveAll(c.dir)
if c.inrp != nil {
c.inrp.Close()
}

View File

@ -13,7 +13,8 @@ import (
func HandleInterrupts(shutdown chan struct{}) {
}
func UmountAll(dir string) {
func RemoveAll(dir string) error {
return os.RemoveAll(dir)
}
func prolongPipe(r, w *os.File) {

View File

@ -10,7 +10,8 @@ import (
"os/exec"
)
func UmountAll(dir string) {
func RemoveAll(dir string) error {
return os.RemoveAll(dir)
}
func prolongPipe(r, w *os.File) {

View File

@ -10,6 +10,10 @@ import (
"os/exec"
)
func RemoveAll(dir string) error {
return os.RemoveAll(dir)
}
func prolongPipe(r, w *os.File) {
}

View File

@ -14,7 +14,8 @@ import (
func HandleInterrupts(shutdown chan struct{}) {
}
func UmountAll(dir string) {
func RemoveAll(dir string) error {
return os.RemoveAll(dir)
}
func CreateMemMappedFile(size int) (f *os.File, mem []byte, err error) {

View File

@ -19,17 +19,18 @@ import (
"unsafe"
)
// UmountAll recurusively unmounts all mounts in dir.
func UmountAll(dir string) {
// RemoveAll is similar to os.RemoveAll, but can handle more cases.
func RemoveAll(dir string) error {
files, _ := ioutil.ReadDir(dir)
for _, f := range files {
name := filepath.Join(dir, f.Name())
if f.IsDir() {
UmountAll(name)
RemoveAll(name)
}
fn := []byte(name + "\x00")
syscall.Syscall(syscall.SYS_UMOUNT2, uintptr(unsafe.Pointer(&fn[0])), syscall.MNT_FORCE, 0)
}
return os.RemoveAll(dir)
}
func Sandbox(cmd *exec.Cmd, user, net bool) error {

View File

@ -15,7 +15,8 @@ import (
func HandleInterrupts(shutdown chan struct{}) {
}
func UmountAll(dir string) {
func RemoveAll(dir string) error {
return os.RemoveAll(dir)
}
func prolongPipe(r, w *os.File) {