Improve general quality of libcontainer
Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes <guillaume.charmes@docker.com> (github: creack)
This commit is contained in:
parent
593219d191
commit
a304eab9d4
12 changed files with 159 additions and 238 deletions
121
system/calls_linux.go
Normal file
121
system/calls_linux.go
Normal file
|
@ -0,0 +1,121 @@
|
|||
package system
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func Chroot(dir string) error {
|
||||
return syscall.Chroot(dir)
|
||||
}
|
||||
|
||||
func Chdir(dir string) error {
|
||||
return syscall.Chdir(dir)
|
||||
}
|
||||
|
||||
func Exec(cmd string, args []string, env []string) error {
|
||||
return syscall.Exec(cmd, args, env)
|
||||
}
|
||||
|
||||
func Fork() (int, error) {
|
||||
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
|
||||
}
|
||||
|
||||
func Mount(source, target, fstype string, flags uintptr, data string) error {
|
||||
return syscall.Mount(source, target, fstype, flags, data)
|
||||
}
|
||||
|
||||
func Unmount(target string, flags int) error {
|
||||
return syscall.Unmount(target, flags)
|
||||
}
|
||||
|
||||
func Pivotroot(newroot, putold string) error {
|
||||
return syscall.PivotRoot(newroot, putold)
|
||||
}
|
||||
|
||||
func Unshare(flags int) error {
|
||||
return syscall.Unshare(flags)
|
||||
}
|
||||
|
||||
func Clone(flags uintptr) (int, error) {
|
||||
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
|
||||
}
|
||||
|
||||
func UsetCloseOnExec(fd uintptr) error {
|
||||
if _, _, err := syscall.Syscall(syscall.SYS_FCNTL, fd, syscall.F_SETFD, 0); err != 0 {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Setgroups(gids []int) error {
|
||||
return syscall.Setgroups(gids)
|
||||
}
|
||||
|
||||
func Setresgid(rgid, egid, sgid int) error {
|
||||
return syscall.Setresgid(rgid, egid, sgid)
|
||||
}
|
||||
|
||||
func Setresuid(ruid, euid, suid int) error {
|
||||
return syscall.Setresuid(ruid, euid, suid)
|
||||
}
|
||||
|
||||
func Sethostname(name string) error {
|
||||
return syscall.Sethostname([]byte(name))
|
||||
}
|
||||
|
||||
func Setsid() (int, error) {
|
||||
return syscall.Setsid()
|
||||
}
|
||||
|
||||
func Ioctl(fd uintptr, flag, data uintptr) error {
|
||||
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, flag, data); err != 0 {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Closefd(fd uintptr) error {
|
||||
return syscall.Close(int(fd))
|
||||
}
|
||||
|
||||
func Dup2(fd1, fd2 uintptr) error {
|
||||
return syscall.Dup2(int(fd1), int(fd2))
|
||||
}
|
||||
|
||||
func Mknod(path string, mode uint32, dev int) error {
|
||||
return syscall.Mknod(path, mode, dev)
|
||||
}
|
||||
|
||||
func ParentDeathSignal() error {
|
||||
if _, _, err := syscall.RawSyscall(syscall.SYS_PRCTL, syscall.PR_SET_PDEATHSIG, uintptr(syscall.SIGKILL), 0); err != 0 {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Setctty() error {
|
||||
if _, _, err := syscall.RawSyscall(syscall.SYS_IOCTL, 0, uintptr(syscall.TIOCSCTTY), 0); err != 0 {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Mkfifo(name string, mode uint32) error {
|
||||
return syscall.Mkfifo(name, mode)
|
||||
}
|
||||
|
||||
func Umask(mask int) int {
|
||||
return syscall.Umask(mask)
|
||||
}
|
31
system/pty_linux.go
Normal file
31
system/pty_linux.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package system
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// Unlockpt unlocks the slave pseudoterminal device corresponding to the master pseudoterminal referred to by f.
|
||||
// Unlockpt should be called before opening the slave side of a pseudoterminal.
|
||||
func Unlockpt(f *os.File) error {
|
||||
var u int
|
||||
return Ioctl(f.Fd(), syscall.TIOCSPTLCK, uintptr(unsafe.Pointer(&u)))
|
||||
}
|
||||
|
||||
// Ptsname retrieves the name of the first available pts for the given master.
|
||||
func Ptsname(f *os.File) (string, error) {
|
||||
var n int
|
||||
|
||||
if err := Ioctl(f.Fd(), syscall.TIOCGPTN, uintptr(unsafe.Pointer(&n))); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return fmt.Sprintf("/dev/pts/%d", n), nil
|
||||
}
|
||||
|
||||
// OpenPtmx opens /dev/ptmx, i.e. the PTY master.
|
||||
func OpenPtmx() (*os.File, error) {
|
||||
// O_NOCTTY and O_CLOEXEC are not present in os package so we use the syscall's one for all.
|
||||
return os.OpenFile("/dev/ptmx", syscall.O_RDONLY|syscall.O_NOCTTY|syscall.O_CLOEXEC, 0)
|
||||
}
|
13
system/setns_linux.go
Normal file
13
system/setns_linux.go
Normal file
|
@ -0,0 +1,13 @@
|
|||
package system
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func Setns(fd uintptr, flags uintptr) error {
|
||||
_, _, err := syscall.RawSyscall(SYS_SETNS, fd, flags, 0)
|
||||
if err != 0 {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
8
system/setns_linux_amd64.go
Normal file
8
system/setns_linux_amd64.go
Normal file
|
@ -0,0 +1,8 @@
|
|||
// +build linux,amd64
|
||||
|
||||
package system
|
||||
|
||||
// Via http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=7b21fddd087678a70ad64afc0f632e0f1071b092
|
||||
const (
|
||||
SYS_SETNS = 308
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue