aboutsummaryrefslogtreecommitdiff
path: root/pkg/osutil/osutil_linux.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/osutil/osutil_linux.go')
-rw-r--r--pkg/osutil/osutil_linux.go58
1 files changed, 10 insertions, 48 deletions
diff --git a/pkg/osutil/osutil_linux.go b/pkg/osutil/osutil_linux.go
index eee0a9009..f4b30b195 100644
--- a/pkg/osutil/osutil_linux.go
+++ b/pkg/osutil/osutil_linux.go
@@ -11,7 +11,6 @@ import (
"os"
"os/exec"
"path/filepath"
- "runtime"
"strconv"
"strings"
"sync"
@@ -31,47 +30,10 @@ func RemoveAll(dir string) error {
fn := []byte(name + "\x00")
syscall.Syscall(syscall.SYS_UMOUNT2, uintptr(unsafe.Pointer(&fn[0])), syscall.MNT_FORCE, 0)
}
- if err := os.RemoveAll(dir); err != nil {
- removeImmutable(dir)
- return os.RemoveAll(dir)
- }
- return nil
-}
-
-func SystemMemorySize() uint64 {
- var info syscall.Sysinfo_t
- syscall.Sysinfo(&info)
- return info.Totalram
-}
-
-func removeImmutable(fname string) error {
- // Reset FS_XFLAG_IMMUTABLE/FS_XFLAG_APPEND.
- fd, err := syscall.Open(fname, syscall.O_RDONLY, 0)
- if err != nil {
- return err
- }
- defer syscall.Close(fd)
- flags := 0
- var cmd uint64 // FS_IOC_SETFLAGS
- switch runtime.GOARCH {
- case "386", "arm":
- cmd = 1074030082
- case "amd64", "arm64":
- cmd = 1074292226
- case "ppc64le":
- cmd = 2148034050
- default:
- panic("unknown arch")
- }
- _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), uintptr(cmd), uintptr(unsafe.Pointer(&flags)))
- return errno
+ return os.RemoveAll(dir)
}
func Sandbox(cmd *exec.Cmd, user, net bool) error {
- enabled, uid, gid, err := initSandbox()
- if err != nil || !enabled {
- return err
- }
if cmd.SysProcAttr == nil {
cmd.SysProcAttr = new(syscall.SysProcAttr)
}
@@ -80,9 +42,15 @@ func Sandbox(cmd *exec.Cmd, user, net bool) error {
syscall.CLONE_NEWNS | syscall.CLONE_NEWUTS | syscall.CLONE_NEWPID
}
if user {
- cmd.SysProcAttr.Credential = &syscall.Credential{
- Uid: uid,
- Gid: gid,
+ enabled, uid, gid, err := initSandbox()
+ if err != nil {
+ return err
+ }
+ if enabled {
+ cmd.SysProcAttr.Credential = &syscall.Credential{
+ Uid: uid,
+ Gid: gid,
+ }
}
}
return nil
@@ -145,12 +113,6 @@ func setPdeathsig(cmd *exec.Cmd) {
cmd.SysProcAttr = new(syscall.SysProcAttr)
}
cmd.SysProcAttr.Pdeathsig = syscall.SIGKILL
- // We will kill the whole process group.
- cmd.SysProcAttr.Setpgid = true
-}
-
-func killPgroup(cmd *exec.Cmd) {
- syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
}
func prolongPipe(r, w *os.File) {