Finish removing the dependency on docker/pkg/system

Fixes #92
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@docker.com> (github: crosbymichael)
This commit is contained in:
Michael Crosby 2014-07-14 17:00:05 -07:00
parent e9ec77ab34
commit 8947d07576
6 changed files with 35 additions and 17 deletions

View File

@ -12,7 +12,7 @@ import (
"time" "time"
"github.com/docker/libcontainer/cgroups" "github.com/docker/libcontainer/cgroups"
"github.com/dotcloud/docker/pkg/system" "github.com/docker/libcontainer/system"
) )
var ( var (

View File

@ -8,8 +8,6 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"syscall" "syscall"
"github.com/dotcloud/docker/pkg/system"
) )
func PivotRoot(rootfs string) error { func PivotRoot(rootfs string) error {
@ -17,16 +15,20 @@ func PivotRoot(rootfs string) error {
if err != nil { if err != nil {
return fmt.Errorf("can't create pivot_root dir %s, error %v", pivotDir, err) return fmt.Errorf("can't create pivot_root dir %s, error %v", pivotDir, err)
} }
if err := system.Pivotroot(rootfs, pivotDir); err != nil {
if err := syscall.PivotRoot(rootfs, pivotDir); err != nil {
return fmt.Errorf("pivot_root %s", err) return fmt.Errorf("pivot_root %s", err)
} }
if err := system.Chdir("/"); err != nil {
if err := syscall.Chdir("/"); err != nil {
return fmt.Errorf("chdir / %s", err) return fmt.Errorf("chdir / %s", err)
} }
// path to pivot dir now changed, update // path to pivot dir now changed, update
pivotDir = filepath.Join("/", filepath.Base(pivotDir)) pivotDir = filepath.Join("/", filepath.Base(pivotDir))
if err := system.Unmount(pivotDir, syscall.MNT_DETACH); err != nil { if err := syscall.Unmount(pivotDir, syscall.MNT_DETACH); err != nil {
return fmt.Errorf("unmount pivot_root dir %s", err) return fmt.Errorf("unmount pivot_root dir %s", err)
} }
return os.Remove(pivotDir) return os.Remove(pivotDir)
} }

View File

@ -4,9 +4,10 @@ package mount
import ( import (
"fmt" "fmt"
"github.com/docker/libcontainer/console"
"os" "os"
"path/filepath" "path/filepath"
"github.com/docker/libcontainer/console"
) )
func SetupPtmx(rootfs, consolePath, mountLabel string) error { func SetupPtmx(rootfs, consolePath, mountLabel string) error {
@ -14,13 +15,16 @@ func SetupPtmx(rootfs, consolePath, mountLabel string) error {
if err := os.Remove(ptmx); err != nil && !os.IsNotExist(err) { if err := os.Remove(ptmx); err != nil && !os.IsNotExist(err) {
return err return err
} }
if err := os.Symlink("pts/ptmx", ptmx); err != nil { if err := os.Symlink("pts/ptmx", ptmx); err != nil {
return fmt.Errorf("symlink dev ptmx %s", err) return fmt.Errorf("symlink dev ptmx %s", err)
} }
if consolePath != "" { if consolePath != "" {
if err := console.Setup(rootfs, consolePath, mountLabel); err != nil { if err := console.Setup(rootfs, consolePath, mountLabel); err != nil {
return err return err
} }
} }
return nil return nil
} }

View File

@ -3,10 +3,9 @@
package mount package mount
import ( import (
"github.com/dotcloud/docker/pkg/system"
"syscall" "syscall"
) )
func SetReadonly() error { func SetReadonly() error {
return system.Mount("/", "/", "bind", syscall.MS_BIND|syscall.MS_REMOUNT|syscall.MS_RDONLY|syscall.MS_REC, "") return syscall.Mount("/", "/", "bind", syscall.MS_BIND|syscall.MS_REMOUNT|syscall.MS_RDONLY|syscall.MS_REC, "")
} }

View File

@ -2,30 +2,30 @@
package mount package mount
import ( import "syscall"
"github.com/dotcloud/docker/pkg/system"
"syscall"
)
func RemountProc() error { func RemountProc() error {
if err := system.Unmount("/proc", syscall.MNT_DETACH); err != nil { if err := syscall.Unmount("/proc", syscall.MNT_DETACH); err != nil {
return err return err
} }
if err := system.Mount("proc", "/proc", "proc", uintptr(defaultMountFlags), ""); err != nil {
if err := syscall.Mount("proc", "/proc", "proc", uintptr(defaultMountFlags), ""); err != nil {
return err return err
} }
return nil return nil
} }
func RemountSys() error { func RemountSys() error {
if err := system.Unmount("/sys", syscall.MNT_DETACH); err != nil { if err := syscall.Unmount("/sys", syscall.MNT_DETACH); err != nil {
if err != syscall.EINVAL { if err != syscall.EINVAL {
return err return err
} }
} else { } else {
if err := system.Mount("sysfs", "/sys", "sysfs", uintptr(defaultMountFlags), ""); err != nil { if err := syscall.Mount("sysfs", "/sys", "sysfs", uintptr(defaultMountFlags), ""); err != nil {
return err return err
} }
} }
return nil return nil
} }

13
system/sysconfig.go Normal file
View File

@ -0,0 +1,13 @@
// +build linux,cgo
package system
/*
#include <unistd.h>
int get_hz(void) { return sysconf(_SC_CLK_TCK); }
*/
import "C"
func GetClockTicks() int {
return int(C.get_hz())
}