From e8740685ceb3ad8637532e7ddffb84ea55d4fc27 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Thu, 6 Feb 2014 14:13:03 -0800 Subject: [PATCH 1/5] Remove linux specific calls Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes (github: creack) --- archive/archive.go | 25 +++++++++++-------- .../{stat_darwin.go => start_unsupported.go} | 6 ++++- archive/stat_linux.go | 7 ++++++ 3 files changed, 27 insertions(+), 11 deletions(-) rename archive/{stat_darwin.go => start_unsupported.go} (72%) diff --git a/archive/archive.go b/archive/archive.go index b1400c2210..3a1c111ea2 100644 --- a/archive/archive.go +++ b/archive/archive.go @@ -5,6 +5,7 @@ import ( "bytes" "compress/bzip2" "compress/gzip" + "errors" "fmt" "github.com/dotcloud/docker/utils" "io" @@ -17,14 +18,18 @@ import ( "syscall" ) -type Archive io.Reader +type ( + Archive io.Reader + Compression int + TarOptions struct { + Includes []string + Compression Compression + } +) -type Compression int - -type TarOptions struct { - Includes []string - Compression Compression -} +var ( + ErrNotImplemented = errors.New("Function not implemented") +) const ( Uncompressed Compression = iota @@ -236,14 +241,14 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader *tar.Reader) return fmt.Errorf("Unhandled tar header type %d\n", hdr.Typeflag) } - if err := syscall.Lchown(path, hdr.Uid, hdr.Gid); err != nil { + if err := os.Lchown(path, hdr.Uid, hdr.Gid); err != nil { return err } // There is no LChmod, so ignore mode for symlink. Also, this // must happen after chown, as that can modify the file mode if hdr.Typeflag != tar.TypeSymlink { - if err := syscall.Chmod(path, uint32(hdr.Mode&07777)); err != nil { + if err := os.Chmod(path, os.FileMode(hdr.Mode&07777)); err != nil { return err } } @@ -251,7 +256,7 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader *tar.Reader) ts := []syscall.Timespec{timeToTimespec(hdr.AccessTime), timeToTimespec(hdr.ModTime)} // syscall.UtimesNano doesn't support a NOFOLLOW flag atm, and if hdr.Typeflag != tar.TypeSymlink { - if err := syscall.UtimesNano(path, ts); err != nil { + if err := UtimesNano(path, ts); err != nil { return err } } else { diff --git a/archive/stat_darwin.go b/archive/start_unsupported.go similarity index 72% rename from archive/stat_darwin.go rename to archive/start_unsupported.go index 32203299dd..834eda8c65 100644 --- a/archive/stat_darwin.go +++ b/archive/start_unsupported.go @@ -13,5 +13,9 @@ func getLastModification(stat *syscall.Stat_t) syscall.Timespec { } func LUtimesNano(path string, ts []syscall.Timespec) error { - return nil + return ErrNotImplemented +} + +func UtimesNano(path string, ts []syscall.Timespec) error { + return ErrNotImplemented } diff --git a/archive/stat_linux.go b/archive/stat_linux.go index 2f7a520ccd..f87a99c55a 100644 --- a/archive/stat_linux.go +++ b/archive/stat_linux.go @@ -30,3 +30,10 @@ func LUtimesNano(path string, ts []syscall.Timespec) error { return nil } + +func UtimesNano(path string, ts []syscall.Timespec) error { + if err := syscall.UtimesNano(path, ts); err != nil { + return err + } + return nil +} From 547ac421995860f99d1d0803c3c1e7ea51dc681e Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Fri, 7 Feb 2014 00:44:14 +0000 Subject: [PATCH 2/5] Add Freebsd client support Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes (github: creack) --- pkg/term/termios_bsd.go | 67 +++++++++++++++++++++++++++++++++++++++++ utils/signal_freebsd.go | 42 ++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 pkg/term/termios_bsd.go create mode 100644 utils/signal_freebsd.go diff --git a/pkg/term/termios_bsd.go b/pkg/term/termios_bsd.go new file mode 100644 index 0000000000..9acf9dfe15 --- /dev/null +++ b/pkg/term/termios_bsd.go @@ -0,0 +1,67 @@ +package term + +import ( + "syscall" + "unsafe" +) + +const ( + getTermios = syscall.TIOCGETA + setTermios = syscall.TIOCSETA + + IGNBRK = syscall.IGNBRK + PARMRK = syscall.PARMRK + INLCR = syscall.INLCR + IGNCR = syscall.IGNCR + ECHONL = syscall.ECHONL + CSIZE = syscall.CSIZE + ICRNL = syscall.ICRNL + ISTRIP = syscall.ISTRIP + PARENB = syscall.PARENB + ECHO = syscall.ECHO + ICANON = syscall.ICANON + ISIG = syscall.ISIG + IXON = syscall.IXON + BRKINT = syscall.BRKINT + INPCK = syscall.INPCK + OPOST = syscall.OPOST + CS8 = syscall.CS8 + IEXTEN = syscall.IEXTEN +) + +type Termios struct { + Iflag uint32 + Oflag uint32 + Cflag uint32 + Lflag uint32 + Cc [20]byte + Ispeed uint32 + Ospeed uint32 +} + +// MakeRaw put the terminal connected to the given file descriptor into raw +// mode and returns the previous state of the terminal so that it can be +// restored. +func MakeRaw(fd uintptr) (*State, error) { + var oldState State + if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 { + return nil, err + } + // C.makeraw() + // return &oldState, nil + + newState := oldState.termios + newState.Iflag &^= (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON) + newState.Oflag &^= OPOST + newState.Lflag &^= (ECHO | ECHONL | ICANON | ISIG | IEXTEN) + newState.Cflag &^= (CSIZE | PARENB) + newState.Cflag |= CS8 + newState.Cc[syscall.VMIN] = 1 + newState.Cc[syscall.VTIME] = 0 + + if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 { + return nil, err + } + + return &oldState, nil +} diff --git a/utils/signal_freebsd.go b/utils/signal_freebsd.go new file mode 100644 index 0000000000..65a700e894 --- /dev/null +++ b/utils/signal_freebsd.go @@ -0,0 +1,42 @@ +package utils + +import ( + "os" + "os/signal" + "syscall" +) + +func CatchAll(sigc chan os.Signal) { + signal.Notify(sigc, + syscall.SIGABRT, + syscall.SIGALRM, + syscall.SIGBUS, + syscall.SIGCHLD, + syscall.SIGCONT, + syscall.SIGFPE, + syscall.SIGHUP, + syscall.SIGILL, + syscall.SIGINT, + syscall.SIGIO, + syscall.SIGIOT, + syscall.SIGKILL, + syscall.SIGPIPE, + syscall.SIGPROF, + syscall.SIGQUIT, + syscall.SIGSEGV, + syscall.SIGSTOP, + syscall.SIGSYS, + syscall.SIGTERM, + syscall.SIGTRAP, + syscall.SIGTSTP, + syscall.SIGTTIN, + syscall.SIGTTOU, + syscall.SIGURG, + syscall.SIGUSR1, + syscall.SIGUSR2, + syscall.SIGVTALRM, + syscall.SIGWINCH, + syscall.SIGXCPU, + syscall.SIGXFSZ, + ) +} From 802407a099705a91017fbaa1b6820f145f580d86 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 10 Mar 2014 13:21:30 -0700 Subject: [PATCH 3/5] Update vendor for kr/pty Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes (github: creack) --- vendor/src/github.com/kr/pty/doc.go | 5 ++ vendor/src/github.com/kr/pty/pty_freebsd.go | 53 +++++++++++++++++++ .../src/github.com/kr/pty/pty_unsupported.go | 27 ++++++++++ 3 files changed, 85 insertions(+) create mode 100644 vendor/src/github.com/kr/pty/pty_freebsd.go create mode 100644 vendor/src/github.com/kr/pty/pty_unsupported.go diff --git a/vendor/src/github.com/kr/pty/doc.go b/vendor/src/github.com/kr/pty/doc.go index 491c060b28..190cfbea92 100644 --- a/vendor/src/github.com/kr/pty/doc.go +++ b/vendor/src/github.com/kr/pty/doc.go @@ -2,9 +2,14 @@ package pty import ( + "errors" "os" ) +// ErrUnsupported is returned if a function is not +// available on the current platform. +var ErrUnsupported = errors.New("unsupported") + // Opens a pty and its corresponding tty. func Open() (pty, tty *os.File, err error) { return open() diff --git a/vendor/src/github.com/kr/pty/pty_freebsd.go b/vendor/src/github.com/kr/pty/pty_freebsd.go new file mode 100644 index 0000000000..13b64d722e --- /dev/null +++ b/vendor/src/github.com/kr/pty/pty_freebsd.go @@ -0,0 +1,53 @@ +package pty + +import ( + "os" + "strconv" + "syscall" + "unsafe" +) + +const ( + sys_TIOCGPTN = 0x4004740F + sys_TIOCSPTLCK = 0x40045431 +) + +func open() (pty, tty *os.File, err error) { + p, err := os.OpenFile("/dev/ptmx", os.O_RDWR, 0) + if err != nil { + return nil, nil, err + } + + sname, err := ptsname(p) + if err != nil { + return nil, nil, err + } + + t, err := os.OpenFile(sname, os.O_RDWR|syscall.O_NOCTTY, 0) + if err != nil { + return nil, nil, err + } + return p, t, nil +} + +func ptsname(f *os.File) (string, error) { + var n int + err := ioctl(f.Fd(), sys_TIOCGPTN, &n) + if err != nil { + return "", err + } + return "/dev/pts/" + strconv.Itoa(n), nil +} + +func ioctl(fd uintptr, cmd uintptr, data *int) error { + _, _, e := syscall.Syscall( + syscall.SYS_IOCTL, + fd, + cmd, + uintptr(unsafe.Pointer(data)), + ) + if e != 0 { + return syscall.ENOTTY + } + return nil +} diff --git a/vendor/src/github.com/kr/pty/pty_unsupported.go b/vendor/src/github.com/kr/pty/pty_unsupported.go new file mode 100644 index 0000000000..d4958b3583 --- /dev/null +++ b/vendor/src/github.com/kr/pty/pty_unsupported.go @@ -0,0 +1,27 @@ +// +build !linux,!darwin,!freebsd + +package pty + +import ( + "os" +) + +func open() (pty, tty *os.File, err error) { + return nil, nil, ErrUnsupported +} + +func ptsname(f *os.File) (string, error) { + return "", ErrUnsupported +} + +func grantpt(f *os.File) error { + return ErrUnsupported +} + +func unlockpt(f *os.File) error { + return ErrUnsupported +} + +func ioctl(fd, cmd, ptr uintptr) error { + return ErrUnsupported +} From 6ccfb7fb9af207a9999c60e57d1c9486ca949a5e Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 10 Mar 2014 13:25:00 -0700 Subject: [PATCH 4/5] Update bsd specs Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes (github: creack) --- Dockerfile | 2 +- archive/{start_unsupported.go => stat_unsupported.go} | 4 ++-- pkg/term/{termios_bsd.go => termios_freebsd.go} | 0 3 files changed, 3 insertions(+), 3 deletions(-) rename archive/{start_unsupported.go => stat_unsupported.go} (87%) rename pkg/term/{termios_bsd.go => termios_freebsd.go} (100%) diff --git a/Dockerfile b/Dockerfile index 9929a10f3c..7fad3d56a1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -68,7 +68,7 @@ ENV GOPATH /go:/go/src/github.com/dotcloud/docker/vendor RUN cd /usr/local/go/src && ./make.bash --no-clean 2>&1 # Compile Go for cross compilation -ENV DOCKER_CROSSPLATFORMS linux/386 linux/arm darwin/amd64 darwin/386 +ENV DOCKER_CROSSPLATFORMS linux/386 linux/arm darwin/amd64 darwin/386 freebsd/amd64 freebsd/386 freebsd/arm # (set an explicit GOARM of 5 for maximum compatibility) ENV GOARM 5 RUN cd /usr/local/go/src && bash -xc 'for platform in $DOCKER_CROSSPLATFORMS; do GOOS=${platform%/*} GOARCH=${platform##*/} ./make.bash --no-clean 2>&1; done' diff --git a/archive/start_unsupported.go b/archive/stat_unsupported.go similarity index 87% rename from archive/start_unsupported.go rename to archive/stat_unsupported.go index 834eda8c65..004fa0f0a4 100644 --- a/archive/start_unsupported.go +++ b/archive/stat_unsupported.go @@ -5,11 +5,11 @@ package archive import "syscall" func getLastAccess(stat *syscall.Stat_t) syscall.Timespec { - return stat.Atimespec + return syscall.Timespec{} } func getLastModification(stat *syscall.Stat_t) syscall.Timespec { - return stat.Mtimespec + return syscall.Timespec{} } func LUtimesNano(path string, ts []syscall.Timespec) error { diff --git a/pkg/term/termios_bsd.go b/pkg/term/termios_freebsd.go similarity index 100% rename from pkg/term/termios_bsd.go rename to pkg/term/termios_freebsd.go From 3c25302a0b9fae2c3fff9262b2ae9fa5f6f04db7 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 10 Mar 2014 15:34:38 -0700 Subject: [PATCH 5/5] Update vendor.sh with new kr/pty revision Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes (github: creack) --- hack/vendor.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/vendor.sh b/hack/vendor.sh index 184cb750a5..ac996dde12 100755 --- a/hack/vendor.sh +++ b/hack/vendor.sh @@ -39,7 +39,7 @@ clone() { echo done } -clone git github.com/kr/pty 3b1f6487b +clone git github.com/kr/pty 98c7b80083 clone git github.com/gorilla/context 708054d61e5