2014-02-19 07:13:36 +00:00
|
|
|
package system
|
2014-02-19 00:56:11 +00:00
|
|
|
|
|
|
|
import (
|
2014-02-25 05:11:52 +00:00
|
|
|
"os/exec"
|
2014-02-19 00:56:11 +00:00
|
|
|
"syscall"
|
2014-05-14 09:48:10 +00:00
|
|
|
"unsafe"
|
2014-02-19 00:56:11 +00:00
|
|
|
)
|
|
|
|
|
2014-02-19 01:52:06 +00:00
|
|
|
func Chroot(dir string) error {
|
2014-02-19 00:56:11 +00:00
|
|
|
return syscall.Chroot(dir)
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:52:06 +00:00
|
|
|
func Chdir(dir string) error {
|
2014-02-19 00:56:11 +00:00
|
|
|
return syscall.Chdir(dir)
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:52:06 +00:00
|
|
|
func Exec(cmd string, args []string, env []string) error {
|
2014-02-19 00:56:11 +00:00
|
|
|
return syscall.Exec(cmd, args, env)
|
|
|
|
}
|
|
|
|
|
2014-02-25 05:11:52 +00:00
|
|
|
func Execv(cmd string, args []string, env []string) error {
|
|
|
|
name, err := exec.LookPath(cmd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return Exec(name, args, env)
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:52:06 +00:00
|
|
|
func Fork() (int, error) {
|
2014-02-19 00:56:11 +00:00
|
|
|
syscall.ForkLock.Lock()
|
|
|
|
pid, _, err := syscall.Syscall(syscall.SYS_FORK, 0, 0, 0)
|
|
|
|
syscall.ForkLock.Unlock()
|
|
|
|
if err != 0 {
|
|
|
|
return -1, err
|
|
|
|
}
|
|
|
|
return int(pid), nil
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:52:06 +00:00
|
|
|
func Mount(source, target, fstype string, flags uintptr, data string) error {
|
2014-02-19 00:56:11 +00:00
|
|
|
return syscall.Mount(source, target, fstype, flags, data)
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:52:06 +00:00
|
|
|
func Unmount(target string, flags int) error {
|
2014-02-19 00:56:11 +00:00
|
|
|
return syscall.Unmount(target, flags)
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:52:06 +00:00
|
|
|
func Pivotroot(newroot, putold string) error {
|
2014-02-19 00:56:11 +00:00
|
|
|
return syscall.PivotRoot(newroot, putold)
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:52:06 +00:00
|
|
|
func Unshare(flags int) error {
|
2014-02-19 00:56:11 +00:00
|
|
|
return syscall.Unshare(flags)
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:52:06 +00:00
|
|
|
func Clone(flags uintptr) (int, error) {
|
2014-02-19 00:56:11 +00:00
|
|
|
syscall.ForkLock.Lock()
|
|
|
|
pid, _, err := syscall.RawSyscall(syscall.SYS_CLONE, flags, 0, 0)
|
|
|
|
syscall.ForkLock.Unlock()
|
|
|
|
if err != 0 {
|
|
|
|
return -1, err
|
|
|
|
}
|
|
|
|
return int(pid), nil
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:52:06 +00:00
|
|
|
func UsetCloseOnExec(fd uintptr) error {
|
2014-02-19 00:56:11 +00:00
|
|
|
if _, _, err := syscall.Syscall(syscall.SYS_FCNTL, fd, syscall.F_SETFD, 0); err != 0 {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:52:06 +00:00
|
|
|
func Setgroups(gids []int) error {
|
2014-02-19 00:56:11 +00:00
|
|
|
return syscall.Setgroups(gids)
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:52:06 +00:00
|
|
|
func Setresgid(rgid, egid, sgid int) error {
|
2014-02-19 00:56:11 +00:00
|
|
|
return syscall.Setresgid(rgid, egid, sgid)
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:52:06 +00:00
|
|
|
func Setresuid(ruid, euid, suid int) error {
|
2014-02-19 00:56:11 +00:00
|
|
|
return syscall.Setresuid(ruid, euid, suid)
|
|
|
|
}
|
|
|
|
|
2014-02-24 21:52:56 +00:00
|
|
|
func Setgid(gid int) error {
|
|
|
|
return syscall.Setgid(gid)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Setuid(uid int) error {
|
|
|
|
return syscall.Setuid(uid)
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:52:06 +00:00
|
|
|
func Sethostname(name string) error {
|
2014-02-19 00:56:11 +00:00
|
|
|
return syscall.Sethostname([]byte(name))
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:52:06 +00:00
|
|
|
func Setsid() (int, error) {
|
2014-02-19 00:56:11 +00:00
|
|
|
return syscall.Setsid()
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:52:06 +00:00
|
|
|
func Ioctl(fd uintptr, flag, data uintptr) error {
|
2014-02-19 00:56:11 +00:00
|
|
|
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, flag, data); err != 0 {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:52:06 +00:00
|
|
|
func Closefd(fd uintptr) error {
|
2014-02-19 00:56:11 +00:00
|
|
|
return syscall.Close(int(fd))
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:52:06 +00:00
|
|
|
func Dup2(fd1, fd2 uintptr) error {
|
2014-02-19 00:56:11 +00:00
|
|
|
return syscall.Dup2(int(fd1), int(fd2))
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:52:06 +00:00
|
|
|
func Mknod(path string, mode uint32, dev int) error {
|
2014-02-19 00:56:11 +00:00
|
|
|
return syscall.Mknod(path, mode, dev)
|
|
|
|
}
|
|
|
|
|
2014-06-13 18:38:32 +00:00
|
|
|
func Prctl(option int, arg2, arg3, arg4, arg5 uintptr) error {
|
|
|
|
if _, _, err := syscall.Syscall6(syscall.SYS_PRCTL, uintptr(option), arg2, arg3, arg4, arg5, 0); err != 0 {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-03-14 18:42:01 +00:00
|
|
|
func ParentDeathSignal(sig uintptr) error {
|
|
|
|
if _, _, err := syscall.RawSyscall(syscall.SYS_PRCTL, syscall.PR_SET_PDEATHSIG, sig, 0); err != 0 {
|
2014-02-19 00:56:11 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-05-14 09:48:10 +00:00
|
|
|
func GetParentDeathSignal() (int, error) {
|
|
|
|
var sig int
|
|
|
|
|
|
|
|
_, _, err := syscall.RawSyscall(syscall.SYS_PRCTL, syscall.PR_GET_PDEATHSIG, uintptr(unsafe.Pointer(&sig)), 0)
|
|
|
|
|
|
|
|
if err != 0 {
|
|
|
|
return -1, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return sig, nil
|
|
|
|
}
|
|
|
|
|
2014-05-28 14:40:36 +00:00
|
|
|
func SetKeepCaps() error {
|
|
|
|
if _, _, err := syscall.RawSyscall(syscall.SYS_PRCTL, syscall.PR_SET_KEEPCAPS, 1, 0); err != 0 {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ClearKeepCaps() error {
|
|
|
|
if _, _, err := syscall.RawSyscall(syscall.SYS_PRCTL, syscall.PR_SET_KEEPCAPS, 0, 0); err != 0 {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:52:06 +00:00
|
|
|
func Setctty() error {
|
2014-02-19 00:56:11 +00:00
|
|
|
if _, _, err := syscall.RawSyscall(syscall.SYS_IOCTL, 0, uintptr(syscall.TIOCSCTTY), 0); err != 0 {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:52:06 +00:00
|
|
|
func Mkfifo(name string, mode uint32) error {
|
2014-02-19 00:56:11 +00:00
|
|
|
return syscall.Mkfifo(name, mode)
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:52:06 +00:00
|
|
|
func Umask(mask int) int {
|
2014-02-19 00:56:11 +00:00
|
|
|
return syscall.Umask(mask)
|
|
|
|
}
|
2014-02-25 23:19:13 +00:00
|
|
|
|
|
|
|
func SetCloneFlags(cmd *exec.Cmd, flag uintptr) {
|
|
|
|
if cmd.SysProcAttr == nil {
|
|
|
|
cmd.SysProcAttr = &syscall.SysProcAttr{}
|
|
|
|
}
|
|
|
|
cmd.SysProcAttr.Cloneflags = flag
|
|
|
|
}
|
2014-04-07 21:43:50 +00:00
|
|
|
|
|
|
|
func Gettid() int {
|
|
|
|
return syscall.Gettid()
|
|
|
|
}
|