mirror of
https://github.com/criyle/go-sandbox.git
synced 2025-11-04 14:49:53 +08:00
use new syscalls for mkdir and rmdir
This commit is contained in:
parent
bcb6df3c53
commit
c126eecfc7
@ -1,6 +1,8 @@
|
|||||||
package forkexec
|
package forkexec
|
||||||
|
|
||||||
import "syscall"
|
import (
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
)
|
||||||
|
|
||||||
// defines missing consts from syscall package
|
// defines missing consts from syscall package
|
||||||
const (
|
const (
|
||||||
@ -8,9 +10,9 @@ const (
|
|||||||
SECCOMP_SET_MODE_FILTER = 1
|
SECCOMP_SET_MODE_FILTER = 1
|
||||||
SECCOMP_FILTER_FLAG_TSYNC = 1
|
SECCOMP_FILTER_FLAG_TSYNC = 1
|
||||||
|
|
||||||
// CLONE_NEWCGOUP is not included
|
// Unshare flags
|
||||||
UnshareFlags = syscall.CLONE_NEWIPC | syscall.CLONE_NEWNET | syscall.CLONE_NEWNS |
|
UnshareFlags = unix.CLONE_NEWIPC | unix.CLONE_NEWNET | unix.CLONE_NEWNS |
|
||||||
syscall.CLONE_NEWPID | syscall.CLONE_NEWUSER | syscall.CLONE_NEWUTS
|
unix.CLONE_NEWPID | unix.CLONE_NEWUSER | unix.CLONE_NEWUTS | unix.CLONE_NEWCGROUP
|
||||||
)
|
)
|
||||||
|
|
||||||
// used by unshare remount / to private
|
// used by unshare remount / to private
|
||||||
@ -20,4 +22,7 @@ var (
|
|||||||
|
|
||||||
// tmp dir made by pivot_root
|
// tmp dir made by pivot_root
|
||||||
OldRoot = "old_root"
|
OldRoot = "old_root"
|
||||||
|
|
||||||
|
// go does not allow constant uintptr to be negative...
|
||||||
|
_AT_FDCWD = unix.AT_FDCWD
|
||||||
)
|
)
|
||||||
|
|||||||
@ -149,7 +149,7 @@ func (r *Runner) Start() (int, error) {
|
|||||||
for i, m := range mountParams {
|
for i, m := range mountParams {
|
||||||
// mkdirs(target)
|
// mkdirs(target)
|
||||||
for _, p := range dirsToMake[i] {
|
for _, p := range dirsToMake[i] {
|
||||||
_, _, err1 = syscall.RawSyscall(syscall.SYS_MKDIR, uintptr(unsafe.Pointer(p)), 0755, 0)
|
_, _, err1 = syscall.RawSyscall(syscall.SYS_MKDIRAT, uintptr(_AT_FDCWD), uintptr(unsafe.Pointer(p)), 0755)
|
||||||
if err1 != 0 && err1 != syscall.EEXIST {
|
if err1 != 0 && err1 != syscall.EEXIST {
|
||||||
goto childerror
|
goto childerror
|
||||||
}
|
}
|
||||||
@ -166,13 +166,13 @@ func (r *Runner) Start() (int, error) {
|
|||||||
// pivit_root
|
// pivit_root
|
||||||
if pivotRoot != nil {
|
if pivotRoot != nil {
|
||||||
// mkdir(root/old_root)
|
// mkdir(root/old_root)
|
||||||
_, _, err1 = syscall.RawSyscall(syscall.SYS_MKDIR, uintptr(unsafe.Pointer(oldRoot)), 0755, 0)
|
_, _, err1 = syscall.RawSyscall(syscall.SYS_MKDIRAT, uintptr(_AT_FDCWD), uintptr(unsafe.Pointer(oldRoot)), 0755)
|
||||||
if err1 != 0 {
|
if err1 != 0 {
|
||||||
goto childerror
|
goto childerror
|
||||||
}
|
}
|
||||||
|
|
||||||
// pivot_root(root, root/old_root)
|
// pivot_root(root, root/old_root)
|
||||||
_, _, err1 = syscall.RawSyscall(syscall.SYS_MKDIR, uintptr(unsafe.Pointer(pivotRoot)), uintptr(unsafe.Pointer(oldRoot)), 0)
|
_, _, err1 = syscall.RawSyscall(syscall.SYS_PIVOT_ROOT, uintptr(unsafe.Pointer(pivotRoot)), uintptr(unsafe.Pointer(oldRoot)), 0)
|
||||||
if err1 != 0 {
|
if err1 != 0 {
|
||||||
goto childerror
|
goto childerror
|
||||||
}
|
}
|
||||||
@ -184,7 +184,7 @@ func (r *Runner) Start() (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// rmdir(root/old_root)
|
// rmdir(root/old_root)
|
||||||
_, _, err1 = syscall.RawSyscall(syscall.SYS_RMDIR, uintptr(unsafe.Pointer(oldRoot)), 0755, 0)
|
_, _, err1 = syscall.RawSyscall(syscall.SYS_UNLINKAT, uintptr(_AT_FDCWD), uintptr(unsafe.Pointer(oldRoot)), uintptr(unix.AT_REMOVEDIR))
|
||||||
if err1 != 0 {
|
if err1 != 0 {
|
||||||
goto childerror
|
goto childerror
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user