Browse code

Purge the bits of pkg/system that moved to libcontainer/system

Signed-off-by: Andrew Page <admwiggin@gmail.com>

Tianon Gravi authored on 2014/08/02 16:35:04
Showing 10 changed files
... ...
@@ -9,9 +9,9 @@ import (
9 9
 
10 10
 	"github.com/docker/docker/daemon/execdriver"
11 11
 	"github.com/docker/docker/daemon/execdriver/native/template"
12
-	"github.com/docker/docker/pkg/system"
13 12
 	"github.com/docker/libcontainer/namespaces"
14 13
 	"github.com/docker/libcontainer/security/capabilities"
14
+	"github.com/docker/libcontainer/system"
15 15
 	"github.com/docker/libcontainer/utils"
16 16
 )
17 17
 
... ...
@@ -15,14 +15,15 @@ import (
15 15
 	"syscall"
16 16
 
17 17
 	"github.com/docker/docker/daemon/execdriver"
18
-	"github.com/docker/docker/pkg/system"
19 18
 	"github.com/docker/docker/pkg/term"
20 19
 	"github.com/docker/libcontainer"
21 20
 	"github.com/docker/libcontainer/apparmor"
22 21
 	"github.com/docker/libcontainer/cgroups/fs"
23 22
 	"github.com/docker/libcontainer/cgroups/systemd"
23
+	consolepkg "github.com/docker/libcontainer/console"
24 24
 	"github.com/docker/libcontainer/namespaces"
25 25
 	"github.com/docker/libcontainer/syncpipe"
26
+	"github.com/docker/libcontainer/system"
26 27
 )
27 28
 
28 29
 const (
... ...
@@ -143,8 +144,9 @@ func (d *driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, startCallba
143 143
 		}, args...)
144 144
 
145 145
 		// set this to nil so that when we set the clone flags anything else is reset
146
-		c.SysProcAttr = nil
147
-		system.SetCloneFlags(&c.Cmd, uintptr(namespaces.GetNamespaceFlags(container.Namespaces)))
146
+		c.SysProcAttr = &syscall.SysProcAttr{
147
+			Cloneflags: uintptr(namespaces.GetNamespaceFlags(container.Namespaces)),
148
+		}
148 149
 		c.ExtraFiles = []*os.File{child}
149 150
 
150 151
 		c.Env = container.Env
... ...
@@ -285,7 +287,7 @@ type TtyConsole struct {
285 285
 }
286 286
 
287 287
 func NewTtyConsole(command *execdriver.Command, pipes *execdriver.Pipes) (*TtyConsole, error) {
288
-	ptyMaster, console, err := system.CreateMasterAndConsole()
288
+	ptyMaster, console, err := consolepkg.CreateMasterAndConsole()
289 289
 	if err != nil {
290 290
 		return nil, err
291 291
 	}
292 292
deleted file mode 100644
... ...
@@ -1,185 +0,0 @@
1
-package system
2
-
3
-import (
4
-	"os/exec"
5
-	"syscall"
6
-	"unsafe"
7
-)
8
-
9
-func Chroot(dir string) error {
10
-	return syscall.Chroot(dir)
11
-}
12
-
13
-func Chdir(dir string) error {
14
-	return syscall.Chdir(dir)
15
-}
16
-
17
-func Exec(cmd string, args []string, env []string) error {
18
-	return syscall.Exec(cmd, args, env)
19
-}
20
-
21
-func Execv(cmd string, args []string, env []string) error {
22
-	name, err := exec.LookPath(cmd)
23
-	if err != nil {
24
-		return err
25
-	}
26
-	return Exec(name, args, env)
27
-}
28
-
29
-func Fork() (int, error) {
30
-	syscall.ForkLock.Lock()
31
-	pid, _, err := syscall.Syscall(syscall.SYS_FORK, 0, 0, 0)
32
-	syscall.ForkLock.Unlock()
33
-	if err != 0 {
34
-		return -1, err
35
-	}
36
-	return int(pid), nil
37
-}
38
-
39
-func Mount(source, target, fstype string, flags uintptr, data string) error {
40
-	return syscall.Mount(source, target, fstype, flags, data)
41
-}
42
-
43
-func Unmount(target string, flags int) error {
44
-	return syscall.Unmount(target, flags)
45
-}
46
-
47
-func Pivotroot(newroot, putold string) error {
48
-	return syscall.PivotRoot(newroot, putold)
49
-}
50
-
51
-func Unshare(flags int) error {
52
-	return syscall.Unshare(flags)
53
-}
54
-
55
-func Clone(flags uintptr) (int, error) {
56
-	syscall.ForkLock.Lock()
57
-	pid, _, err := syscall.RawSyscall(syscall.SYS_CLONE, flags, 0, 0)
58
-	syscall.ForkLock.Unlock()
59
-	if err != 0 {
60
-		return -1, err
61
-	}
62
-	return int(pid), nil
63
-}
64
-
65
-func UsetCloseOnExec(fd uintptr) error {
66
-	if _, _, err := syscall.Syscall(syscall.SYS_FCNTL, fd, syscall.F_SETFD, 0); err != 0 {
67
-		return err
68
-	}
69
-	return nil
70
-}
71
-
72
-func Setgroups(gids []int) error {
73
-	return syscall.Setgroups(gids)
74
-}
75
-
76
-func Setresgid(rgid, egid, sgid int) error {
77
-	return syscall.Setresgid(rgid, egid, sgid)
78
-}
79
-
80
-func Setresuid(ruid, euid, suid int) error {
81
-	return syscall.Setresuid(ruid, euid, suid)
82
-}
83
-
84
-func Setgid(gid int) error {
85
-	return syscall.Setgid(gid)
86
-}
87
-
88
-func Setuid(uid int) error {
89
-	return syscall.Setuid(uid)
90
-}
91
-
92
-func Sethostname(name string) error {
93
-	return syscall.Sethostname([]byte(name))
94
-}
95
-
96
-func Setsid() (int, error) {
97
-	return syscall.Setsid()
98
-}
99
-
100
-func Ioctl(fd uintptr, flag, data uintptr) error {
101
-	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, flag, data); err != 0 {
102
-		return err
103
-	}
104
-	return nil
105
-}
106
-
107
-func Closefd(fd uintptr) error {
108
-	return syscall.Close(int(fd))
109
-}
110
-
111
-func Dup2(fd1, fd2 uintptr) error {
112
-	return syscall.Dup2(int(fd1), int(fd2))
113
-}
114
-
115
-func Mknod(path string, mode uint32, dev int) error {
116
-	return syscall.Mknod(path, mode, dev)
117
-}
118
-
119
-func Prctl(option int, arg2, arg3, arg4, arg5 uintptr) error {
120
-	if _, _, err := syscall.Syscall6(syscall.SYS_PRCTL, uintptr(option), arg2, arg3, arg4, arg5, 0); err != 0 {
121
-		return err
122
-	}
123
-	return nil
124
-}
125
-
126
-func ParentDeathSignal(sig uintptr) error {
127
-	if _, _, err := syscall.RawSyscall(syscall.SYS_PRCTL, syscall.PR_SET_PDEATHSIG, sig, 0); err != 0 {
128
-		return err
129
-	}
130
-	return nil
131
-}
132
-
133
-func GetParentDeathSignal() (int, error) {
134
-	var sig int
135
-
136
-	_, _, err := syscall.RawSyscall(syscall.SYS_PRCTL, syscall.PR_GET_PDEATHSIG, uintptr(unsafe.Pointer(&sig)), 0)
137
-
138
-	if err != 0 {
139
-		return -1, err
140
-	}
141
-
142
-	return sig, nil
143
-}
144
-
145
-func SetKeepCaps() error {
146
-	if _, _, err := syscall.RawSyscall(syscall.SYS_PRCTL, syscall.PR_SET_KEEPCAPS, 1, 0); err != 0 {
147
-		return err
148
-	}
149
-
150
-	return nil
151
-}
152
-
153
-func ClearKeepCaps() error {
154
-	if _, _, err := syscall.RawSyscall(syscall.SYS_PRCTL, syscall.PR_SET_KEEPCAPS, 0, 0); err != 0 {
155
-		return err
156
-	}
157
-
158
-	return nil
159
-}
160
-
161
-func Setctty() error {
162
-	if _, _, err := syscall.RawSyscall(syscall.SYS_IOCTL, 0, uintptr(syscall.TIOCSCTTY), 0); err != 0 {
163
-		return err
164
-	}
165
-	return nil
166
-}
167
-
168
-func Mkfifo(name string, mode uint32) error {
169
-	return syscall.Mkfifo(name, mode)
170
-}
171
-
172
-func Umask(mask int) int {
173
-	return syscall.Umask(mask)
174
-}
175
-
176
-func SetCloneFlags(cmd *exec.Cmd, flag uintptr) {
177
-	if cmd.SysProcAttr == nil {
178
-		cmd.SysProcAttr = &syscall.SysProcAttr{}
179
-	}
180
-	cmd.SysProcAttr.Cloneflags = flag
181
-}
182
-
183
-func Gettid() int {
184
-	return syscall.Gettid()
185
-}
186 1
deleted file mode 100644
... ...
@@ -1,38 +0,0 @@
1
-package system
2
-
3
-import (
4
-	"io/ioutil"
5
-	"strconv"
6
-	"syscall"
7
-)
8
-
9
-// Works similarly to OpenBSD's "closefrom(2)":
10
-//   The closefrom() call deletes all descriptors numbered fd and higher from
11
-//   the per-process file descriptor table.  It is effectively the same as
12
-//   calling close(2) on each descriptor.
13
-// http://www.openbsd.org/cgi-bin/man.cgi?query=closefrom&sektion=2
14
-//
15
-// See also http://stackoverflow.com/a/918469/433558
16
-func CloseFdsFrom(minFd int) error {
17
-	fdList, err := ioutil.ReadDir("/proc/self/fd")
18
-	if err != nil {
19
-		return err
20
-	}
21
-	for _, fi := range fdList {
22
-		fd, err := strconv.Atoi(fi.Name())
23
-		if err != nil {
24
-			// ignore non-numeric file names
25
-			continue
26
-		}
27
-
28
-		if fd < minFd {
29
-			// ignore descriptors lower than our specified minimum
30
-			continue
31
-		}
32
-
33
-		// intentionally ignore errors from syscall.Close
34
-		syscall.Close(fd)
35
-		// the cases where this might fail are basically file descriptors that have already been closed (including and especially the one that was created when ioutil.ReadDir did the "opendir" syscall)
36
-	}
37
-	return nil
38
-}
39 1
deleted file mode 100644
... ...
@@ -1,12 +0,0 @@
1
-// +build !linux
2
-
3
-package system
4
-
5
-import (
6
-	"fmt"
7
-	"runtime"
8
-)
9
-
10
-func CloseFdsFrom(minFd int) error {
11
-	return fmt.Errorf("CloseFdsFrom is unsupported on this platform (%s/%s)", runtime.GOOS, runtime.GOARCH)
12
-}
13 1
deleted file mode 100644
... ...
@@ -1,26 +0,0 @@
1
-package system
2
-
3
-import (
4
-	"io/ioutil"
5
-	"path/filepath"
6
-	"strconv"
7
-	"strings"
8
-)
9
-
10
-// look in /proc to find the process start time so that we can verify
11
-// that this pid has started after ourself
12
-func GetProcessStartTime(pid int) (string, error) {
13
-	data, err := ioutil.ReadFile(filepath.Join("/proc", strconv.Itoa(pid), "stat"))
14
-	if err != nil {
15
-		return "", err
16
-	}
17
-	parts := strings.Split(string(data), " ")
18
-	// the starttime is located at pos 22
19
-	// from the man page
20
-	//
21
-	// starttime %llu (was %lu before Linux 2.6)
22
-	// (22)  The  time the process started after system boot.  In kernels before Linux 2.6, this
23
-	// value was expressed in jiffies.  Since Linux 2.6, the value is expressed in  clock  ticks
24
-	// (divide by sysconf(_SC_CLK_TCK)).
25
-	return parts[22-1], nil // starts at 1
26
-}
27 1
deleted file mode 100644
... ...
@@ -1,58 +0,0 @@
1
-package system
2
-
3
-import (
4
-	"fmt"
5
-	"os"
6
-	"syscall"
7
-	"unsafe"
8
-)
9
-
10
-// Unlockpt unlocks the slave pseudoterminal device corresponding to the master pseudoterminal referred to by f.
11
-// Unlockpt should be called before opening the slave side of a pseudoterminal.
12
-func Unlockpt(f *os.File) error {
13
-	var u int
14
-	return Ioctl(f.Fd(), syscall.TIOCSPTLCK, uintptr(unsafe.Pointer(&u)))
15
-}
16
-
17
-// Ptsname retrieves the name of the first available pts for the given master.
18
-func Ptsname(f *os.File) (string, error) {
19
-	var n int
20
-
21
-	if err := Ioctl(f.Fd(), syscall.TIOCGPTN, uintptr(unsafe.Pointer(&n))); err != nil {
22
-		return "", err
23
-	}
24
-	return fmt.Sprintf("/dev/pts/%d", n), nil
25
-}
26
-
27
-// CreateMasterAndConsole will open /dev/ptmx on the host and retreive the
28
-// pts name for use as the pty slave inside the container
29
-func CreateMasterAndConsole() (*os.File, string, error) {
30
-	master, err := os.OpenFile("/dev/ptmx", syscall.O_RDWR|syscall.O_NOCTTY|syscall.O_CLOEXEC, 0)
31
-	if err != nil {
32
-		return nil, "", err
33
-	}
34
-	console, err := Ptsname(master)
35
-	if err != nil {
36
-		return nil, "", err
37
-	}
38
-	if err := Unlockpt(master); err != nil {
39
-		return nil, "", err
40
-	}
41
-	return master, console, nil
42
-}
43
-
44
-// OpenPtmx opens /dev/ptmx, i.e. the PTY master.
45
-func OpenPtmx() (*os.File, error) {
46
-	// O_NOCTTY and O_CLOEXEC are not present in os package so we use the syscall's one for all.
47
-	return os.OpenFile("/dev/ptmx", syscall.O_RDONLY|syscall.O_NOCTTY|syscall.O_CLOEXEC, 0)
48
-}
49
-
50
-// OpenTerminal is a clone of os.OpenFile without the O_CLOEXEC
51
-// used to open the pty slave inside the container namespace
52
-func OpenTerminal(name string, flag int) (*os.File, error) {
53
-	r, e := syscall.Open(name, flag, 0)
54
-	if e != nil {
55
-		return nil, &os.PathError{"open", name, e}
56
-	}
57
-	return os.NewFile(uintptr(r), name), nil
58
-}
59 1
deleted file mode 100644
... ...
@@ -1,27 +0,0 @@
1
-package system
2
-
3
-import (
4
-	"fmt"
5
-	"runtime"
6
-	"syscall"
7
-)
8
-
9
-// Via http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=7b21fddd087678a70ad64afc0f632e0f1071b092
10
-//
11
-// We need different setns values for the different platforms and arch
12
-// We are declaring the macro here because the SETNS syscall does not exist in th stdlib
13
-var setNsMap = map[string]uintptr{
14
-	"linux/amd64": 308,
15
-}
16
-
17
-func Setns(fd uintptr, flags uintptr) error {
18
-	ns, exists := setNsMap[fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)]
19
-	if !exists {
20
-		return ErrNotSupportedPlatform
21
-	}
22
-	_, _, err := syscall.RawSyscall(ns, fd, flags, 0)
23
-	if err != 0 {
24
-		return err
25
-	}
26
-	return nil
27
-}
28 1
deleted file mode 100644
... ...
@@ -1,9 +0,0 @@
1
-// +build linux,!cgo
2
-
3
-package system
4
-
5
-func GetClockTicks() int {
6
-	// when we cannot call out to C to get the sysconf it is fairly safe to
7
-	// just return 100
8
-	return 100
9
-}
10 1
deleted file mode 100644
... ...
@@ -1,38 +0,0 @@
1
-// +build !linux
2
-
3
-package system
4
-
5
-import (
6
-	"os"
7
-	"os/exec"
8
-)
9
-
10
-func SetCloneFlags(cmd *exec.Cmd, flag uintptr) {
11
-
12
-}
13
-
14
-func UsetCloseOnExec(fd uintptr) error {
15
-	return ErrNotSupportedPlatform
16
-}
17
-
18
-func Gettid() int {
19
-	return 0
20
-}
21
-
22
-func GetClockTicks() int {
23
-	// when we cannot call out to C to get the sysconf it is fairly safe to
24
-	// just return 100
25
-	return 100
26
-}
27
-
28
-func CreateMasterAndConsole() (*os.File, string, error) {
29
-	return nil, "", ErrNotSupportedPlatform
30
-}
31
-
32
-func SetKeepCaps() error {
33
-	return ErrNotSupportedPlatform
34
-}
35
-
36
-func ClearKeepCaps() error {
37
-	return ErrNotSupportedPlatform
38
-}