Commit c878ca45 authored by Shayan Pooya's avatar Shayan Pooya Committed by Han-Wen Nienhuys

Do not fork a new process to unmount if user is privileged

The root user can issue the umount syscall and does not need the
fusermount binary. Therefore, it is not necessary to fork and exec a new
process just to run the umount binary.

Golang has a global lock held for forking (See exec_unix.go in the golang
source tree):
"Acquire the fork lock so that no other threads create new fds that are
not yet close-on-exec before we fork."

So it would be best if processes would refrain from forking
unnecessarily.
Signed-off-by: default avatarShayan Pooya <shayan@arista.com>
parent 5690be47
......@@ -10,7 +10,6 @@ import (
"os"
"os/exec"
"path"
"path/filepath"
"strings"
"syscall"
"unsafe"
......@@ -75,29 +74,9 @@ func mount(mountPoint string, opts *MountOptions, ready chan<- error) (fd int, e
return fd, err
}
func privilegedUnmount(mountPoint string) error {
dir, _ := filepath.Split(mountPoint)
bin, err := umountBinary()
if err != nil {
return err
}
proc, err := os.StartProcess(bin,
[]string{bin, mountPoint},
&os.ProcAttr{Dir: dir, Files: []*os.File{nil, nil, os.Stderr}})
if err != nil {
return err
}
w, err := proc.Wait()
if !w.Success() {
return fmt.Errorf("umount exited with code %v\n", w.Sys())
}
return err
}
func unmount(mountPoint string) (err error) {
if os.Geteuid() == 0 {
return privilegedUnmount(mountPoint)
return syscall.Unmount(mountPoint, 0)
}
bin, err := fusermountBinary()
if err != nil {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment