├── .gitignore ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── circle.yml ├── deployments └── k8s-traffic-control.yaml ├── docker.go ├── glide-update.sh ├── glide.lock ├── glide.yaml ├── imgs ├── controls.png └── traffic-control.png ├── main.go ├── report.go ├── store.go ├── tc.go ├── tools ├── .gitignore ├── README.md ├── circle.yml ├── cmd │ └── wcloud │ │ ├── Makefile │ │ ├── cli.go │ │ ├── client.go │ │ └── types.go ├── cover │ ├── Makefile │ ├── cover.go │ └── gather_coverage.sh ├── files-with-type ├── image-tag ├── integration │ ├── assert.sh │ ├── config.sh │ ├── gce.sh │ ├── run_all.sh │ └── sanity_check.sh ├── lint ├── publish-site ├── rebuild-image ├── runner │ ├── Makefile │ └── runner.go ├── sched ├── scheduler │ ├── .gitignore │ ├── README.md │ ├── app.yaml │ ├── appengine_config.py │ ├── cron.yaml │ ├── main.py │ └── requirements.txt ├── shell-lint ├── socks │ ├── Dockerfile │ ├── Makefile │ ├── README.md │ ├── connect.sh │ └── main.go └── test └── vendor ├── github.com ├── Microsoft │ └── go-winio │ │ ├── LICENSE │ │ ├── backup.go │ │ ├── file.go │ │ ├── fileinfo.go │ │ ├── pipe.go │ │ ├── privilege.go │ │ ├── reparse.go │ │ ├── sd.go │ │ ├── syscall.go │ │ └── zsyscall.go ├── Sirupsen │ └── logrus │ │ ├── LICENSE │ │ ├── doc.go │ │ ├── entry.go │ │ ├── exported.go │ │ ├── formatter.go │ │ ├── hooks.go │ │ ├── json_formatter.go │ │ ├── logger.go │ │ ├── logrus.go │ │ ├── terminal_bsd.go │ │ ├── terminal_linux.go │ │ ├── terminal_notwindows.go │ │ ├── terminal_solaris.go │ │ ├── terminal_windows.go │ │ ├── text_formatter.go │ │ └── writer.go ├── containernetworking │ └── cni │ │ ├── LICENSE │ │ └── pkg │ │ └── ns │ │ └── ns.go ├── docker │ ├── docker │ │ ├── LICENSE │ │ ├── NOTICE │ │ ├── api │ │ │ └── types │ │ │ │ ├── filters │ │ │ │ └── parse.go │ │ │ │ └── versions │ │ │ │ └── compare.go │ │ ├── opts │ │ │ ├── hosts.go │ │ │ ├── hosts_unix.go │ │ │ ├── hosts_windows.go │ │ │ ├── ip.go │ │ │ ├── opts.go │ │ │ ├── opts_unix.go │ │ │ └── opts_windows.go │ │ └── pkg │ │ │ ├── archive │ │ │ ├── archive.go │ │ │ ├── archive_linux.go │ │ │ ├── archive_other.go │ │ │ ├── archive_unix.go │ │ │ ├── archive_windows.go │ │ │ ├── changes.go │ │ │ ├── changes_linux.go │ │ │ ├── changes_other.go │ │ │ ├── changes_unix.go │ │ │ ├── changes_windows.go │ │ │ ├── copy.go │ │ │ ├── copy_unix.go │ │ │ ├── copy_windows.go │ │ │ ├── diff.go │ │ │ ├── example_changes.go │ │ │ ├── time_linux.go │ │ │ ├── time_unsupported.go │ │ │ ├── whiteouts.go │ │ │ └── wrap.go │ │ │ ├── fileutils │ │ │ ├── fileutils.go │ │ │ ├── fileutils_darwin.go │ │ │ ├── fileutils_solaris.go │ │ │ ├── fileutils_unix.go │ │ │ └── fileutils_windows.go │ │ │ ├── homedir │ │ │ └── homedir.go │ │ │ ├── idtools │ │ │ ├── idtools.go │ │ │ ├── idtools_unix.go │ │ │ ├── idtools_windows.go │ │ │ ├── usergroupadd_linux.go │ │ │ └── usergroupadd_unsupported.go │ │ │ ├── ioutils │ │ │ ├── buffer.go │ │ │ ├── bytespipe.go │ │ │ ├── fmt.go │ │ │ ├── fswriters.go │ │ │ ├── multireader.go │ │ │ ├── readers.go │ │ │ ├── temp_unix.go │ │ │ ├── temp_windows.go │ │ │ ├── writeflusher.go │ │ │ └── writers.go │ │ │ ├── longpath │ │ │ └── longpath.go │ │ │ ├── pools │ │ │ └── pools.go │ │ │ ├── promise │ │ │ └── promise.go │ │ │ ├── stdcopy │ │ │ └── stdcopy.go │ │ │ └── system │ │ │ ├── chtimes.go │ │ │ ├── chtimes_unix.go │ │ │ ├── chtimes_windows.go │ │ │ ├── errors.go │ │ │ ├── events_windows.go │ │ │ ├── filesys.go │ │ │ ├── filesys_windows.go │ │ │ ├── lstat.go │ │ │ ├── lstat_windows.go │ │ │ ├── meminfo.go │ │ │ ├── meminfo_linux.go │ │ │ ├── meminfo_solaris.go │ │ │ ├── meminfo_unsupported.go │ │ │ ├── meminfo_windows.go │ │ │ ├── mknod.go │ │ │ ├── mknod_windows.go │ │ │ ├── path_unix.go │ │ │ ├── path_windows.go │ │ │ ├── stat.go │ │ │ ├── stat_darwin.go │ │ │ ├── stat_freebsd.go │ │ │ ├── stat_linux.go │ │ │ ├── stat_openbsd.go │ │ │ ├── stat_solaris.go │ │ │ ├── stat_unsupported.go │ │ │ ├── stat_windows.go │ │ │ ├── syscall_unix.go │ │ │ ├── syscall_windows.go │ │ │ ├── umask.go │ │ │ ├── umask_windows.go │ │ │ ├── utimes_freebsd.go │ │ │ ├── utimes_linux.go │ │ │ ├── utimes_unsupported.go │ │ │ ├── xattrs_linux.go │ │ │ └── xattrs_unsupported.go │ ├── engine-api │ │ ├── LICENSE │ │ ├── doc.go │ │ └── types │ │ │ ├── mount │ │ │ └── mount.go │ │ │ └── swarm │ │ │ ├── common.go │ │ │ ├── container.go │ │ │ ├── network.go │ │ │ ├── node.go │ │ │ ├── service.go │ │ │ ├── swarm.go │ │ │ └── task.go │ └── go-units │ │ ├── LICENSE │ │ ├── duration.go │ │ ├── size.go │ │ └── ulimit.go ├── fsouza │ └── go-dockerclient │ │ ├── LICENSE │ │ ├── auth.go │ │ ├── change.go │ │ ├── client.go │ │ ├── client_unix.go │ │ ├── client_windows.go │ │ ├── container.go │ │ ├── env.go │ │ ├── event.go │ │ ├── exec.go │ │ ├── image.go │ │ ├── misc.go │ │ ├── network.go │ │ ├── node.go │ │ ├── service.go │ │ ├── signal.go │ │ ├── swarm.go │ │ ├── tar.go │ │ ├── task.go │ │ ├── tls.go │ │ └── volume.go ├── hashicorp │ └── go-cleanhttp │ │ ├── LICENSE │ │ ├── cleanhttp.go │ │ └── doc.go └── opencontainers │ └── runc │ ├── LICENSE │ ├── NOTICE │ ├── checkpoint.go │ ├── create.go │ ├── delete.go │ ├── events.go │ ├── exec.go │ ├── kill.go │ ├── libcontainer │ ├── system │ │ ├── linux.go │ │ ├── proc.go │ │ ├── setns_linux.go │ │ ├── syscall_linux_386.go │ │ ├── syscall_linux_64.go │ │ ├── syscall_linux_arm.go │ │ ├── sysconfig.go │ │ ├── sysconfig_notcgo.go │ │ ├── unsupported.go │ │ └── xattrs_linux.go │ └── user │ │ ├── lookup.go │ │ ├── lookup_unix.go │ │ ├── lookup_unsupported.go │ │ └── user.go │ ├── list.go │ ├── main.go │ ├── main_solaris.go │ ├── main_unix.go │ ├── main_unsupported.go │ ├── pause.go │ ├── ps.go │ ├── restore.go │ ├── rlimit_linux.go │ ├── run.go │ ├── signals.go │ ├── spec.go │ ├── start.go │ ├── state.go │ ├── tty.go │ ├── update.go │ ├── utils.go │ └── utils_linux.go └── golang.org └── x ├── net ├── LICENSE ├── PATENTS └── context │ ├── context.go │ ├── ctxhttp │ ├── ctxhttp.go │ └── ctxhttp_pre17.go │ ├── go17.go │ └── pre_go17.go └── sys ├── LICENSE ├── PATENTS ├── unix ├── asm.s ├── asm_darwin_386.s ├── asm_darwin_amd64.s ├── asm_dragonfly_386.s ├── asm_dragonfly_amd64.s ├── asm_freebsd_386.s ├── asm_freebsd_amd64.s ├── asm_freebsd_arm.s ├── asm_linux_386.s ├── asm_linux_amd64.s ├── asm_linux_arm.s ├── asm_netbsd_386.s ├── asm_netbsd_amd64.s ├── asm_netbsd_arm.s ├── asm_openbsd_386.s ├── asm_openbsd_amd64.s ├── asm_solaris_amd64.s ├── constants.go ├── env_unix.go ├── env_unset.go ├── flock.go ├── flock_linux_32bit.go ├── gccgo.go ├── gccgo_c.c ├── gccgo_linux_amd64.go ├── race.go ├── race0.go ├── so_solaris.go ├── sockcmsg_linux.go ├── sockcmsg_unix.go ├── str.go ├── syscall.go ├── syscall_bsd.go ├── syscall_darwin.go ├── syscall_darwin_386.go ├── syscall_darwin_amd64.go ├── syscall_dragonfly.go ├── syscall_dragonfly_386.go ├── syscall_dragonfly_amd64.go ├── syscall_freebsd.go ├── syscall_freebsd_386.go ├── syscall_freebsd_amd64.go ├── syscall_freebsd_arm.go ├── syscall_linux.go ├── syscall_linux_386.go ├── syscall_linux_amd64.go ├── syscall_linux_arm.go ├── syscall_netbsd.go ├── syscall_netbsd_386.go ├── syscall_netbsd_amd64.go ├── syscall_netbsd_arm.go ├── syscall_no_getwd.go ├── syscall_openbsd.go ├── syscall_openbsd_386.go ├── syscall_openbsd_amd64.go ├── syscall_solaris.go ├── syscall_solaris_amd64.go ├── syscall_unix.go ├── types_darwin.go ├── types_dragonfly.go ├── types_freebsd.go ├── types_linux.go ├── types_netbsd.go ├── types_openbsd.go ├── types_solaris.go ├── zerrors_darwin_386.go ├── zerrors_darwin_amd64.go ├── zerrors_dragonfly_386.go ├── zerrors_dragonfly_amd64.go ├── zerrors_freebsd_386.go ├── zerrors_freebsd_amd64.go ├── zerrors_freebsd_arm.go ├── zerrors_linux_386.go ├── zerrors_linux_amd64.go ├── zerrors_linux_arm.go ├── zerrors_netbsd_386.go ├── zerrors_netbsd_amd64.go ├── zerrors_netbsd_arm.go ├── zerrors_openbsd_386.go ├── zerrors_openbsd_amd64.go ├── zerrors_solaris_amd64.go ├── zsyscall_darwin_386.go ├── zsyscall_darwin_amd64.go ├── zsyscall_dragonfly_386.go ├── zsyscall_dragonfly_amd64.go ├── zsyscall_freebsd_386.go ├── zsyscall_freebsd_amd64.go ├── zsyscall_freebsd_arm.go ├── zsyscall_linux_386.go ├── zsyscall_linux_amd64.go ├── zsyscall_linux_arm.go ├── zsyscall_netbsd_386.go ├── zsyscall_netbsd_amd64.go ├── zsyscall_netbsd_arm.go ├── zsyscall_openbsd_386.go ├── zsyscall_openbsd_amd64.go ├── zsyscall_solaris_amd64.go ├── zsysctl_openbsd.go ├── zsysnum_darwin_386.go ├── zsysnum_darwin_amd64.go ├── zsysnum_dragonfly_386.go ├── zsysnum_dragonfly_amd64.go ├── zsysnum_freebsd_386.go ├── zsysnum_freebsd_amd64.go ├── zsysnum_freebsd_arm.go ├── zsysnum_linux_386.go ├── zsysnum_linux_amd64.go ├── zsysnum_linux_arm.go ├── zsysnum_netbsd_386.go ├── zsysnum_netbsd_amd64.go ├── zsysnum_netbsd_arm.go ├── zsysnum_openbsd_386.go ├── zsysnum_openbsd_amd64.go ├── zsysnum_solaris_amd64.go ├── ztypes_darwin_386.go ├── ztypes_darwin_amd64.go ├── ztypes_dragonfly_386.go ├── ztypes_dragonfly_amd64.go ├── ztypes_freebsd_386.go ├── ztypes_freebsd_amd64.go ├── ztypes_freebsd_arm.go ├── ztypes_linux_386.go ├── ztypes_linux_amd64.go ├── ztypes_linux_arm.go ├── ztypes_netbsd_386.go ├── ztypes_netbsd_amd64.go ├── ztypes_netbsd_arm.go ├── ztypes_openbsd_386.go ├── ztypes_openbsd_amd64.go └── ztypes_solaris_amd64.go └── windows ├── asm.s ├── asm_windows_386.s ├── asm_windows_amd64.s ├── dll_windows.go ├── env_unset.go ├── env_windows.go ├── eventlog.go ├── exec_windows.go ├── race.go ├── race0.go ├── security_windows.go ├── service.go ├── str.go ├── syscall.go ├── syscall_windows.go ├── zsyscall_windows.go ├── ztypes_windows.go ├── ztypes_windows_386.go └── ztypes_windows_amd64.go /.gitignore: -------------------------------------------------------------------------------- 1 | /traffic-control 2 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.4 2 | MAINTAINER Weaveworks Inc 3 | LABEL works.weave.role=system 4 | COPY ./traffic-control /usr/bin/traffic-control 5 | RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2 6 | RUN apk add --update iproute2 && rm -rf /var/cache/apk/* 7 | ENTRYPOINT ["/usr/bin/traffic-control"] 8 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: run clean 2 | 3 | SUDO=$(shell docker info >/dev/null 2>&1 || echo "sudo -E") 4 | EXE=traffic-control 5 | ORGANIZATION=weaveworksplugins 6 | IMAGE=$(ORGANIZATION)/scope-$(EXE) 7 | NAME=$(ORGANIZATION)-scope-$(EXE) 8 | UPTODATE=.$(EXE).uptodate 9 | 10 | run: $(UPTODATE) 11 | # --net=host gives us the remote hostname, in case we're being launched against a non-local docker host. 12 | # We could also pass in the `-hostname=foo` flag, but that doesn't work against a remote docker host. 13 | $(SUDO) docker run --rm -it \ 14 | --net=host \ 15 | --pid=host \ 16 | --privileged \ 17 | -v /var/run:/var/run \ 18 | --name $(NAME) $(IMAGE) 19 | 20 | $(UPTODATE): $(EXE) Dockerfile 21 | $(SUDO) docker build -t $(IMAGE) . 22 | touch $@ 23 | 24 | $(EXE): $(shell find . -maxdepth 1 -name "*.go") 25 | $(SUDO) docker run --rm \ 26 | -v "$$PWD":/go/src/hosting/org/$(EXE) \ 27 | -v $(shell pwd)/vendor:/go/src/hosting/org/$(EXE)/vendor \ 28 | -w /go/src/hosting/org/$(EXE) \ 29 | golang:1.6 go build -v 30 | 31 | 32 | clean: 33 | - rm -rf $(UPTODATE) $(EXE) 34 | - $(SUDO) docker rmi $(IMAGE) 35 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | general: 2 | branches: 3 | ignore: 4 | - gh-pages 5 | 6 | machine: 7 | services: 8 | - docker 9 | environment: 10 | GOPATH: /home/ubuntu 11 | SRCDIR: /home/ubuntu/scope-traffic-control 12 | PATH: $PATH:$HOME/.local/bin 13 | 14 | dependencies: 15 | cache_directories: 16 | - "~/docker" 17 | override: 18 | - echo "no dependencies" 19 | 20 | test: 21 | override: 22 | - cd $SRCDIR && make .traffic-control.uptodate && docker tag weaveworksplugins/scope-traffic-control weaveworksplugins/scope-traffic-control:$(./tools/image-tag): 23 | parallel: false 24 | timeout: 300 25 | 26 | deployment: 27 | hub: 28 | branch: master 29 | commands: 30 | - | 31 | test -z "${DOCKER_USER}" || ( 32 | docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS && 33 | (test "${DOCKER_ORGANIZATION:-$DOCKER_USER}" == "weaveworksplugins" || ( 34 | docker tag weaveworksplugins/scope-traffic-control:latest ${DOCKER_ORGANIZATION:-$DOCKER_USER}/scope-traffic-control:latest && 35 | docker tag weaveworksplugins/scope-traffic-control:$(./tools/image-tag) ${DOCKER_ORGANIZATION:-$DOCKER_USER}/scope-traffic-control:$(./tools/image-tag) 36 | )) && 37 | docker push ${DOCKER_ORGANIZATION:-$DOCKER_USER}/scope-traffic-control && 38 | docker push ${DOCKER_ORGANIZATION:-$DOCKER_USER}/scope-traffic-control:$(./tools/image-tag) 39 | ) 40 | hub-dev: 41 | branch: /^((?!master).)*$/ # not the master branch 42 | commands: 43 | - > 44 | test -z "${DEPLOY_BRANCH}" || test -z "${DOCKER_USER}" || ( 45 | docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS && 46 | docker tag weaveworksplugins/scope-traffic-control:latest ${DOCKER_ORGANIZATION:-$DOCKER_USER}/scope-traffic-control:${CIRCLE_BRANCH//\//-} && 47 | docker push ${DOCKER_ORGANIZATION:-$DOCKER_USER}/scope-traffic-control:${CIRCLE_BRANCH//\//-} 48 | ) 49 | -------------------------------------------------------------------------------- /deployments/k8s-traffic-control.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: extensions/v1beta1 2 | kind: DaemonSet 3 | metadata: 4 | labels: 5 | app: weavescope 6 | weavescope-component: weavescope-traffic-control-plugin 7 | name: weavescope-traffic-control-plugin 8 | spec: 9 | template: 10 | metadata: 11 | labels: 12 | app: weavescope 13 | weavescope-component: weavescope-traffic-control-plugin 14 | spec: 15 | hostPID: true 16 | hostNetwork: true 17 | containers: 18 | - name: weavescope-traffic-control-plugin 19 | image: weaveworksplugins/scope-traffic-control:latest 20 | securityContext: 21 | privileged: true 22 | volumeMounts: 23 | - name: docker-sock 24 | mountPath: /var/run/docker.sock 25 | - name: scope-plugins 26 | mountPath: /var/run/scope/plugins 27 | volumes: 28 | - name: docker-sock 29 | hostPath: 30 | path: /var/run/docker.sock 31 | - name: scope-plugins 32 | hostPath: 33 | path: /var/run/scope/plugins 34 | -------------------------------------------------------------------------------- /glide-update.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Update vendored dedendencies. 4 | # 5 | set -e 6 | 7 | if ! [[ "$PWD" = "$GOPATH/src/github.com/weaveworks-plugins/scope-traffic-control" ]]; then 8 | echo "must be run from \$GOPATH/src/github.com/weaveworks-plugins/scope-traffic-control" 9 | exit 255 10 | fi 11 | 12 | if [ ! $(command -v glide) ]; then 13 | echo "glide: command not found" 14 | exit 255 15 | fi 16 | 17 | if [ ! $(command -v glide-vc) ]; then 18 | echo "glide-vc: command not found" 19 | exit 255 20 | fi 21 | 22 | glide update --strip-vcs --strip-vendor --update-vendored --delete 23 | glide-vc --only-code --no-tests --keep="**/*.json.in" 24 | -------------------------------------------------------------------------------- /glide.lock: -------------------------------------------------------------------------------- 1 | hash: bd9336b880a82c02966079471881dae0531b073064ce86a756840c0beb1c52bc 2 | updated: 2016-09-27T14:59:05.607799553+02:00 3 | imports: 4 | - name: github.com/containernetworking/cni 5 | version: 5c3c17164270150467498a32c71436c7cd5501be 6 | subpackages: 7 | - pkg/ns 8 | - name: github.com/docker/docker 9 | version: 789e6868904d724ed56fe4b141b4b557f477f1ca 10 | subpackages: 11 | - api/types/filters 12 | - api/types/versions 13 | - opts 14 | - pkg/archive 15 | - pkg/fileutils 16 | - pkg/homedir 17 | - pkg/idtools 18 | - pkg/ioutils 19 | - pkg/longpath 20 | - pkg/pools 21 | - pkg/promise 22 | - pkg/stdcopy 23 | - pkg/system 24 | - name: github.com/docker/engine-api 25 | version: 4290f40c056686fcaa5c9caf02eac1dde9315adf 26 | subpackages: 27 | - types/mount 28 | - types/swarm 29 | - name: github.com/docker/go-units 30 | version: f2145db703495b2e525c59662db69a7344b00bb8 31 | - name: github.com/fsouza/go-dockerclient 32 | version: 30ceb1a86b568e935e73aaf0a4df18be5c8f945d 33 | - name: github.com/hashicorp/go-cleanhttp 34 | version: ad28ea4487f05916463e2423a55166280e8254b5 35 | - name: github.com/Microsoft/go-winio 36 | version: ce2922f643c8fd76b46cadc7f404a06282678b34 37 | - name: github.com/opencontainers/runc 38 | version: 2940d2e2e9365b4b3fec8ae24822435195f56b61 39 | subpackages: 40 | - libcontainer/system 41 | - libcontainer/user 42 | - name: github.com/Sirupsen/logrus 43 | version: 4b6ea7319e214d98c938f12692336f7ca9348d6b 44 | - name: golang.org/x/net 45 | version: 6a513affb38dc9788b449d59ffed099b8de18fa0 46 | subpackages: 47 | - context 48 | - context/ctxhttp 49 | - name: golang.org/x/sys 50 | version: e11762ca30adc5b39fdbfd8c4250dabeb8e456d3 51 | subpackages: 52 | - unix 53 | - windows 54 | testImports: [] 55 | -------------------------------------------------------------------------------- /glide.yaml: -------------------------------------------------------------------------------- 1 | package: github.com/weaveworks-plugins/traffic-control 2 | import: 3 | - package: github.com/Sirupsen/logrus 4 | version: ~0.10.0 5 | - package: github.com/containernetworking/cni 6 | version: ~0.3.0 7 | subpackages: 8 | - pkg/ns 9 | - package: github.com/fsouza/go-dockerclient 10 | -------------------------------------------------------------------------------- /imgs/controls.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weaveworks-plugins/scope-traffic-control/9119b9831249d82145d27116a74e89b0607d4c40/imgs/controls.png -------------------------------------------------------------------------------- /imgs/traffic-control.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weaveworks-plugins/scope-traffic-control/9119b9831249d82145d27116a74e89b0607d4c40/imgs/traffic-control.png -------------------------------------------------------------------------------- /store.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "sync" 5 | ) 6 | 7 | // State is the container internal state 8 | type State int 9 | 10 | const ( 11 | // Created state 12 | Created State = iota 13 | // Running state 14 | Running 15 | // Stopped state 16 | Stopped 17 | // Destroyed state 18 | Destroyed 19 | ) 20 | 21 | // Container data structure 22 | type Container struct { 23 | State State 24 | PID int 25 | } 26 | 27 | // Store data structure 28 | type Store struct { 29 | lock sync.Mutex 30 | containers map[string]Container 31 | } 32 | 33 | // NewStore instantiates a new Store 34 | func NewStore() *Store { 35 | return &Store{ 36 | containers: map[string]Container{}, 37 | } 38 | } 39 | 40 | // Container returns a container form its ID 41 | func (s *Store) Container(containerID string) (Container, bool) { 42 | s.lock.Lock() 43 | defer s.lock.Unlock() 44 | container, found := s.containers[containerID] 45 | return container, found 46 | } 47 | 48 | // SetContainer sets a container into the store 49 | func (s *Store) SetContainer(containerID string, container Container) { 50 | s.lock.Lock() 51 | defer s.lock.Unlock() 52 | s.containers[containerID] = container 53 | } 54 | 55 | // DeleteContainer deletes a container from the store 56 | func (s *Store) DeleteContainer(containerID string) { 57 | s.lock.Lock() 58 | defer s.lock.Unlock() 59 | delete(s.containers, containerID) 60 | } 61 | 62 | // ForEach execute a function on each container in the store 63 | func (s *Store) ForEach(callback func(ID string, c Container)) { 64 | s.lock.Lock() 65 | defer s.lock.Unlock() 66 | for containerID, container := range s.containers { 67 | callback(containerID, container) 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tools/.gitignore: -------------------------------------------------------------------------------- 1 | cover/cover 2 | socks/proxy 3 | socks/image.tar 4 | runner/runner 5 | cmd/wcloud/wcloud 6 | *.pyc 7 | *~ 8 | -------------------------------------------------------------------------------- /tools/README.md: -------------------------------------------------------------------------------- 1 | # Weaveworks Build Tools 2 | 3 | Included in this repo are tools shared by weave.git and scope.git. They include 4 | 5 | - ```cover```: a tool which merges overlapping coverage reports generated by go 6 | test 7 | - ```files-with-type```: a tool to search directories for files of a given 8 | MIME type 9 | - ```lint```: a script to lint Go project; runs various tools like golint, go 10 | vet, errcheck etc 11 | - ```rebuild-image```: a script to rebuild docker images when their input files 12 | change; useful when you using docker images to build your software, but you 13 | don't want to build the image every time. 14 | - ```shell-lint```: a script to lint multiple shell files with 15 | [shellcheck](http://www.shellcheck.net/) 16 | - ```socks```: a simple, dockerised SOCKS proxy for getting your laptop onto 17 | the Weave network 18 | - ```test```: a script to run all go unit tests in subdirectories, gather the 19 | coverage results, and merge them into a single report. 20 | - ```runner```: a tool for running tests in parallel; given each test is 21 | suffixed with the number of hosts it requires, and the hosts available are 22 | contained in the environment variable HOSTS, the tool will run tests in 23 | parallel, on different hosts. 24 | - ```scheduler```: an appengine application that can be used to distribute 25 | tests across different shards in CircleCI. 26 | 27 | ## Using build-tools.git 28 | 29 | To allow you to tie your code to a specific version of build-tools.git, such 30 | that future changes don't break you, we recommendation that you [`git subtree`]() 31 | this repository into your own repository: 32 | 33 | [`git subtree`]: http://blogs.atlassian.com/2013/05/alternatives-to-git-submodule-git-subtree/ 34 | 35 | ``` 36 | git subtree add --prefix tools https://github.com/weaveworks/build-tools.git master --squash 37 | ```` 38 | 39 | To update the code in build-tools.git, the process is therefore: 40 | - PR into build-tools.git, go through normal review process etc. 41 | - Do `git subtree pull --prefix tools https://github.com/weaveworks/build-tools.git master --squash` 42 | in your repo, and PR that. 43 | -------------------------------------------------------------------------------- /tools/circle.yml: -------------------------------------------------------------------------------- 1 | machine: 2 | services: 3 | - docker 4 | environment: 5 | GOPATH: /home/ubuntu 6 | SRCDIR: /home/ubuntu/src/github.com/weaveworks/tools 7 | PATH: $PATH:$HOME/bin 8 | 9 | dependencies: 10 | post: 11 | - go clean -i net 12 | - go install -tags netgo std 13 | - mkdir -p $(dirname $SRCDIR) 14 | - cp -r $(pwd)/ $SRCDIR 15 | - go get github.com/golang/lint/golint github.com/fzipp/gocyclo github.com/kisielk/errcheck 16 | 17 | test: 18 | override: 19 | - cd $SRCDIR; ./lint . 20 | - cd $SRCDIR/cover; make 21 | - cd $SRCDIR/socks; make 22 | - cd $SRCDIR/runner; make 23 | - cd $SRCDIR/cmd/wcloud; make 24 | 25 | -------------------------------------------------------------------------------- /tools/cmd/wcloud/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all clean 2 | 3 | all: wcloud 4 | 5 | wcloud: *.go 6 | go get ./$(@D) 7 | go build -o $@ ./$(@D) 8 | 9 | clean: 10 | rm -rf wcloud 11 | go clean ./... 12 | -------------------------------------------------------------------------------- /tools/cmd/wcloud/types.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "time" 5 | ) 6 | 7 | // Deployment describes a deployment 8 | type Deployment struct { 9 | ID string `json:"id"` 10 | CreatedAt time.Time `json:"created_at"` 11 | ImageName string `json:"image_name"` 12 | Version string `json:"version"` 13 | Priority int `json:"priority"` 14 | State string `json:"status"` 15 | 16 | TriggeringUser string `json:"triggering_user"` 17 | IntendedServices []string `json:"intended_services"` 18 | } 19 | 20 | // Config for the deployment system for a user. 21 | type Config struct { 22 | RepoURL string `json:"repo_url" yaml:"repo_url"` 23 | RepoBranch string `json:"repo_branch" yaml:"repo_branch"` 24 | RepoPath string `json:"repo_path" yaml:"repo_path"` 25 | RepoKey string `json:"repo_key" yaml:"repo_key"` 26 | KubeconfigPath string `json:"kubeconfig_path" yaml:"kubeconfig_path"` 27 | AutoApply bool `json:"auto_apply" yaml:"auto_apply"` 28 | 29 | Notifications []NotificationConfig `json:"notifications" yaml:"notifications"` 30 | 31 | // Globs of files not to change, relative to the route of the repo 32 | ConfigFileBlackList []string `json:"config_file_black_list" yaml:"config_file_black_list"` 33 | 34 | CommitMessageTemplate string `json:"commit_message_template" yaml:"commit_message_template"` // See https://golang.org/pkg/text/template/ 35 | } 36 | 37 | // NotificationConfig describes how to send notifications 38 | type NotificationConfig struct { 39 | SlackWebhookURL string `json:"slack_webhook_url" yaml:"slack_webhook_url"` 40 | SlackUsername string `json:"slack_username" yaml:"slack_username"` 41 | MessageTemplate string `json:"message_template" yaml:"message_template"` 42 | ApplyMessageTemplate string `json:"apply_message_template" yaml:"apply_message_template"` 43 | } 44 | -------------------------------------------------------------------------------- /tools/cover/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all clean 2 | 3 | all: cover 4 | 5 | cover: *.go 6 | go get -tags netgo ./$(@D) 7 | go build -ldflags "-extldflags \"-static\" -linkmode=external" -tags netgo -o $@ ./$(@D) 8 | 9 | clean: 10 | rm -rf cover 11 | go clean ./... 12 | -------------------------------------------------------------------------------- /tools/cover/gather_coverage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This scripts copies all the coverage reports from various circle shards, 3 | # merges them and produces a complete report. 4 | 5 | set -ex 6 | DESTINATION=$1 7 | FROMDIR=$2 8 | mkdir -p "$DESTINATION" 9 | 10 | if [ -n "$CIRCLECI" ]; then 11 | for i in $(seq 1 $((CIRCLE_NODE_TOTAL - 1))); do 12 | scp "node$i:$FROMDIR"/* "$DESTINATION" || true 13 | done 14 | fi 15 | 16 | go get github.com/weaveworks/build-tools/cover 17 | cover "$DESTINATION"/* >profile.cov 18 | go tool cover -html=profile.cov -o coverage.html 19 | go tool cover -func=profile.cov -o coverage.txt 20 | tar czf coverage.tar.gz "$DESTINATION" 21 | -------------------------------------------------------------------------------- /tools/files-with-type: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Find all files with a given MIME type. 4 | # 5 | # e.g. 6 | # $ files-with-type text/x-shellscript k8s infra 7 | 8 | mime_type=$1 9 | shift 10 | 11 | git ls-files "$@" | grep -vE '^vendor/' | xargs file --mime-type | grep "${mime_type}" | sed -e 's/:.*$//' 12 | -------------------------------------------------------------------------------- /tools/image-tag: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -o errexit 4 | set -o nounset 5 | set -o pipefail 6 | 7 | WORKING_SUFFIX=$(if ! git diff --exit-code --quiet HEAD >&2; \ 8 | then echo "-WIP"; \ 9 | else echo ""; \ 10 | fi) 11 | BRANCH_PREFIX=$(git rev-parse --abbrev-ref HEAD) 12 | echo "${BRANCH_PREFIX//\//-}-$(git rev-parse --short HEAD)$WORKING_SUFFIX" 13 | -------------------------------------------------------------------------------- /tools/integration/run_all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 6 | # shellcheck disable=SC1090 7 | . "$DIR/config.sh" 8 | 9 | whitely echo Sanity checks 10 | if ! bash "$DIR/sanity_check.sh"; then 11 | whitely echo ...failed 12 | exit 1 13 | fi 14 | whitely echo ...ok 15 | 16 | # shellcheck disable=SC2068 17 | TESTS=( ${@:-$(find . -name '*_test.sh')} ) 18 | RUNNER_ARGS=( ) 19 | 20 | # If running on circle, use the scheduler to work out what tests to run 21 | if [ -n "$CIRCLECI" ] && [ -z "$NO_SCHEDULER" ]; then 22 | RUNNER_ARGS=( "${RUNNER_ARGS[@]}" -scheduler ) 23 | fi 24 | 25 | # If running on circle or PARALLEL is not empty, run tests in parallel 26 | if [ -n "$CIRCLECI" ] || [ -n "$PARALLEL" ]; then 27 | RUNNER_ARGS=( "${RUNNER_ARGS[@]}" -parallel ) 28 | fi 29 | 30 | make -C "${DIR}/../runner" 31 | HOSTS="$HOSTS" "${DIR}/../runner/runner" "${RUNNER_ARGS[@]}" "${TESTS[@]}" 32 | -------------------------------------------------------------------------------- /tools/integration/sanity_check.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # shellcheck disable=SC1091 3 | . ./config.sh 4 | 5 | set -e 6 | 7 | whitely echo Ping each host from the other 8 | for host in $HOSTS; do 9 | for other in $HOSTS; do 10 | [ "$host" = "$other" ] || run_on "$host" "$PING" "$other" 11 | done 12 | done 13 | 14 | whitely echo Check we can reach docker 15 | 16 | for host in $HOSTS; do 17 | echo 18 | echo "Host Version Info: $host" 19 | echo "=====================================" 20 | echo "# docker version" 21 | docker_on "$host" version 22 | echo "# docker info" 23 | docker_on "$host" info 24 | echo "# weave version" 25 | weave_on "$host" version 26 | done 27 | -------------------------------------------------------------------------------- /tools/publish-site: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -o pipefail 5 | 6 | : "${PRODUCT:=}" 7 | 8 | fatal() { 9 | echo "$@" >&2 10 | exit 1 11 | } 12 | 13 | if [ ! -d .git ] ; then 14 | fatal "Current directory is not a git clone" 15 | fi 16 | 17 | if [ -z "${PRODUCT}" ]; then 18 | fatal "Must specify PRODUCT" 19 | fi 20 | 21 | if ! BRANCH=$(git symbolic-ref --short HEAD) || [ -z "$BRANCH" ] ; then 22 | fatal "Could not determine branch" 23 | fi 24 | 25 | case "$BRANCH" in 26 | issues/*) 27 | VERSION="${BRANCH#issues/}" 28 | TAGS="$VERSION" 29 | ;; 30 | *) 31 | if echo "$BRANCH" | grep -qE '^[0-9]+\.[0-9]+' ; then 32 | DESCRIBE=$(git describe --match 'v*') 33 | if ! VERSION=$(echo "$DESCRIBE" | grep -oP '(?<=^v)[0-9]+\.[0-9]+\.[0-9]+') ; then 34 | fatal "Could not infer latest $BRANCH version from $DESCRIBE" 35 | fi 36 | TAGS="$VERSION latest" 37 | else 38 | VERSION="$BRANCH" 39 | TAGS="$VERSION" 40 | fi 41 | ;; 42 | esac 43 | 44 | for TAG in $TAGS ; do 45 | echo ">>> Publishing $PRODUCT $VERSION to $1/docs/$PRODUCT/$TAG" 46 | wordepress \ 47 | --url "$1" --user "$2" --password "$3" \ 48 | --product "$PRODUCT" --version "$VERSION" --tag "$TAG" \ 49 | publish site 50 | done 51 | -------------------------------------------------------------------------------- /tools/rebuild-image: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Rebuild a cached docker image if the input files have changed. 3 | # Usage: ./rebuild-image 4 | 5 | set -eux 6 | 7 | IMAGENAME=$1 8 | # shellcheck disable=SC2001 9 | SAVEDNAME=$(echo "$IMAGENAME" | sed "s/[\/\-]/\./g") 10 | IMAGEDIR=$2 11 | shift 2 12 | 13 | INPUTFILES=( "$@" ) 14 | CACHEDIR=$HOME/docker/ 15 | 16 | # Rebuild the image 17 | rebuild() { 18 | mkdir -p "$CACHEDIR" 19 | rm "$CACHEDIR/$SAVEDNAME"* || true 20 | docker build -t "$IMAGENAME" "$IMAGEDIR" 21 | docker save "$IMAGENAME:latest" | gzip - > "$CACHEDIR/$SAVEDNAME-$CIRCLE_SHA1.gz" 22 | } 23 | 24 | # Get the revision the cached image was build at 25 | cached_image_rev() { 26 | find "$CACHEDIR" -name "$SAVEDNAME-*" -type f | sed -n 's/^[^\-]*\-\([a-z0-9]*\).gz$/\1/p' 27 | } 28 | 29 | # Have there been any revision between $1 and $2 30 | has_changes() { 31 | local rev1=$1 32 | local rev2=$2 33 | local changes 34 | changes=$(git diff --oneline "$rev1..$rev2" -- "${INPUTFILES[@]}" | wc -l) 35 | [ "$changes" -gt 0 ] 36 | } 37 | 38 | commit_timestamp() { 39 | local rev=$1 40 | git show -s --format=%ct "$rev" 41 | } 42 | 43 | cached_revision=$(cached_image_rev) 44 | if [ -z "$cached_revision" ]; then 45 | echo ">>> No cached image found; rebuilding" 46 | rebuild 47 | exit 0 48 | fi 49 | 50 | echo ">>> Found cached image rev $cached_revision" 51 | if has_changes "$cached_revision" "$CIRCLE_SHA1" ; then 52 | echo ">>> Found changes, rebuilding" 53 | rebuild 54 | exit 0 55 | fi 56 | 57 | IMAGE_TIMEOUT="$(( 3 * 24 * 60 * 60 ))" 58 | if [ "$(commit_timestamp "$cached_revision")" -lt "${IMAGE_TIMEOUT}" ]; then 59 | echo ">>> Image is more the 24hrs old; rebuilding" 60 | rebuild 61 | exit 0 62 | fi 63 | 64 | # we didn't rebuild; import cached version 65 | echo ">>> No changes found, importing cached image" 66 | zcat "$CACHEDIR/$SAVEDNAME-$cached_revision.gz" | docker load 67 | -------------------------------------------------------------------------------- /tools/runner/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all clean 2 | 3 | all: runner 4 | 5 | runner: *.go 6 | go get -tags netgo ./$(@D) 7 | go build -ldflags "-extldflags \"-static\" -linkmode=external" -tags netgo -o $@ ./$(@D) 8 | 9 | clean: 10 | rm -rf runner 11 | go clean ./... 12 | -------------------------------------------------------------------------------- /tools/sched: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import sys, string, json, urllib 3 | import requests 4 | import optparse 5 | 6 | def test_time(target, test_name, runtime): 7 | r = requests.post(target + "/record/%s/%f" % (urllib.quote(test_name, safe=""), runtime)) 8 | print r.text 9 | assert r.status_code == 204 10 | 11 | def test_sched(target, test_run, shard_count, shard_id): 12 | tests = json.dumps({'tests': string.split(sys.stdin.read())}) 13 | r = requests.post(target + "/schedule/%s/%d/%d" % (test_run, shard_count, shard_id), data=tests) 14 | assert r.status_code == 200 15 | result = r.json() 16 | for test in sorted(result['tests']): 17 | print test 18 | 19 | def usage(): 20 | print "%s (--target=...) " % sys.argv[0] 21 | print " time " 22 | print " sched " 23 | 24 | def main(): 25 | parser = optparse.OptionParser() 26 | parser.add_option('--target', default="http://positive-cocoa-90213.appspot.com") 27 | options, args = parser.parse_args() 28 | if len(args) < 3: 29 | usage() 30 | sys.exit(1) 31 | 32 | if args[0] == "time": 33 | test_time(options.target, args[1], float(args[2])) 34 | elif args[0] == "sched": 35 | test_sched(options.target, args[1], int(args[2]), int(args[3])) 36 | else: 37 | usage() 38 | 39 | if __name__ == '__main__': 40 | main() 41 | -------------------------------------------------------------------------------- /tools/scheduler/.gitignore: -------------------------------------------------------------------------------- 1 | lib 2 | -------------------------------------------------------------------------------- /tools/scheduler/README.md: -------------------------------------------------------------------------------- 1 | To upload newer version: 2 | 3 | ``` 4 | pip install -r requirements.txt -t lib 5 | appcfg.py update . 6 | ``` 7 | -------------------------------------------------------------------------------- /tools/scheduler/app.yaml: -------------------------------------------------------------------------------- 1 | application: positive-cocoa-90213 2 | version: 1 3 | runtime: python27 4 | api_version: 1 5 | threadsafe: true 6 | 7 | handlers: 8 | - url: .* 9 | script: main.app 10 | 11 | libraries: 12 | - name: webapp2 13 | version: latest 14 | - name: ssl 15 | version: latest 16 | -------------------------------------------------------------------------------- /tools/scheduler/appengine_config.py: -------------------------------------------------------------------------------- 1 | from google.appengine.ext import vendor 2 | 3 | vendor.add('lib') 4 | -------------------------------------------------------------------------------- /tools/scheduler/cron.yaml: -------------------------------------------------------------------------------- 1 | cron: 2 | - description: periodic gc 3 | url: /tasks/gc 4 | schedule: every 5 minutes 5 | -------------------------------------------------------------------------------- /tools/scheduler/requirements.txt: -------------------------------------------------------------------------------- 1 | flask 2 | google-api-python-client 3 | -------------------------------------------------------------------------------- /tools/shell-lint: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Lint all shell files in given directories with `shellcheck`. 4 | # 5 | # e.g. 6 | # $ shell-lint infra k8s 7 | # 8 | # Depends on: 9 | # - shellcheck 10 | # - files-with-type 11 | # - file >= 5.22 12 | 13 | "$(dirname "${BASH_SOURCE[0]}")/files-with-type" text/x-shellscript "$@" | xargs --no-run-if-empty shellcheck 14 | -------------------------------------------------------------------------------- /tools/socks/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM gliderlabs/alpine 2 | MAINTAINER Weaveworks Inc 3 | WORKDIR / 4 | COPY proxy / 5 | EXPOSE 8000 6 | EXPOSE 8080 7 | ENTRYPOINT ["/proxy"] 8 | -------------------------------------------------------------------------------- /tools/socks/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all clean 2 | 3 | IMAGE_TAR=image.tar 4 | IMAGE_NAME=weaveworks/socksproxy 5 | PROXY_EXE=proxy 6 | NETGO_CHECK=@strings $@ | grep cgo_stub\\\.go >/dev/null || { \ 7 | rm $@; \ 8 | echo "\nYour go standard library was built without the 'netgo' build tag."; \ 9 | echo "To fix that, run"; \ 10 | echo " sudo go clean -i net"; \ 11 | echo " sudo go install -tags netgo std"; \ 12 | false; \ 13 | } 14 | 15 | all: $(IMAGE_TAR) 16 | 17 | $(IMAGE_TAR): Dockerfile $(PROXY_EXE) 18 | docker build -t $(IMAGE_NAME) . 19 | docker save $(IMAGE_NAME):latest > $@ 20 | 21 | $(PROXY_EXE): *.go 22 | go get -tags netgo ./$(@D) 23 | go build -ldflags "-extldflags \"-static\" -linkmode=external" -tags netgo -o $@ ./$(@D) 24 | $(NETGO_CHECK) 25 | 26 | clean: 27 | -docker rmi $(IMAGE_NAME) 28 | rm -rf $(PROXY_EXE) $(IMAGE_TAR) 29 | go clean ./... 30 | -------------------------------------------------------------------------------- /tools/socks/README.md: -------------------------------------------------------------------------------- 1 | # SOCKS Proxy 2 | 3 | The challenge: you’ve built and deployed your microservices based 4 | application on a Weave network, running on a set of VMs on EC2. Many 5 | of the services’ public API are reachable from the internet via an 6 | Nginx-based reverse proxy, but some of the services also expose 7 | private monitoring and manage endpoints via embedded HTTP servers. 8 | How do I securely get access to these from my laptop, without exposing 9 | them to the world? 10 | 11 | One method we’ve started using at Weaveworks is a 90’s technology - a 12 | SOCKS proxy combined with a PAC script. It’s relatively 13 | straight-forward: one ssh’s into any of the VMs participating in the 14 | Weave network, starts the SOCKS proxy in a container on Weave the 15 | network, and SSH port forwards a few local port to the proxy. All 16 | that’s left is for the user to configure his browser to use the proxy, 17 | and voila, you can now access your Docker containers, via the Weave 18 | network (and with all the magic of weavedns), from your laptop’s 19 | browser! 20 | 21 | It is perhaps worth noting there is nothing Weave-specific about this 22 | approach - this should work with any SDN or private network. 23 | 24 | A quick example: 25 | 26 | ``` 27 | vm1$ weave launch 28 | vm1$ eval $(weave env) 29 | vm1$ docker run -d --name nginx nginx 30 | ``` 31 | 32 | And on your laptop 33 | 34 | ``` 35 | laptop$ git clone https://github.com/weaveworks/tools 36 | laptop$ cd tools/socks 37 | laptop$ ./connect.sh vm1 38 | Starting proxy container... 39 | Please configure your browser for proxy 40 | http://localhost:8080/proxy.pac 41 | ``` 42 | 43 | To configure your Mac to use the proxy: 44 | 45 | 1. Open System Preferences 46 | 2. Select Network 47 | 3. Click the 'Advanced' button 48 | 4. Select the Proxies tab 49 | 5. Click the 'Automatic Proxy Configuration' check box 50 | 6. Enter 'http://localhost:8080/proxy.pac' in the URL box 51 | 7. Remove `*.local` from the 'Bypass proxy settings for these Hosts & Domains' 52 | 53 | Now point your browser at http://nginx.weave.local/ 54 | -------------------------------------------------------------------------------- /tools/socks/connect.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -eu 4 | 5 | if [ $# -ne 1 ]; then 6 | echo "Usage: $0 " 7 | exit 1 8 | fi 9 | 10 | HOST=$1 11 | 12 | echo "Starting proxy container..." 13 | PROXY_CONTAINER=$(ssh "$HOST" weave run -d weaveworks/socksproxy) 14 | 15 | function finish { 16 | echo "Removing proxy container.." 17 | # shellcheck disable=SC2029 18 | ssh "$HOST" docker rm -f "$PROXY_CONTAINER" 19 | } 20 | trap finish EXIT 21 | 22 | # shellcheck disable=SC2029 23 | PROXY_IP=$(ssh "$HOST" -- "docker inspect --format='{{.NetworkSettings.IPAddress}}' $PROXY_CONTAINER") 24 | echo 'Please configure your browser for proxy http://localhost:8080/proxy.pac' 25 | # shellcheck disable=SC2029 26 | ssh "-L8000:$PROXY_IP:8000" "-L8080:$PROXY_IP:8080" "$HOST" docker attach "$PROXY_CONTAINER" 27 | -------------------------------------------------------------------------------- /tools/socks/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "net/http" 7 | "os" 8 | "strings" 9 | "text/template" 10 | 11 | socks5 "github.com/armon/go-socks5" 12 | "github.com/weaveworks/docker/pkg/mflag" 13 | "github.com/weaveworks/weave/common/mflagext" 14 | "golang.org/x/net/context" 15 | ) 16 | 17 | type pacFileParameters struct { 18 | HostMatch string 19 | Aliases map[string]string 20 | } 21 | 22 | const ( 23 | pacfile = ` 24 | function FindProxyForURL(url, host) { 25 | if(shExpMatch(host, "{{.HostMatch}}")) { 26 | return "SOCKS5 localhost:8000"; 27 | } 28 | {{range $key, $value := .Aliases}} 29 | if (host == "{{$key}}") { 30 | return "SOCKS5 localhost:8000"; 31 | } 32 | {{end}} 33 | return "DIRECT"; 34 | } 35 | ` 36 | ) 37 | 38 | func main() { 39 | var ( 40 | as []string 41 | hostMatch string 42 | ) 43 | mflagext.ListVar(&as, []string{"a", "-alias"}, []string{}, "Specify hostname aliases in the form alias:hostname. Can be repeated.") 44 | mflag.StringVar(&hostMatch, []string{"h", "-host-match"}, "*.weave.local", "Specify main host shExpMatch expression in pacfile") 45 | mflag.Parse() 46 | 47 | var aliases = map[string]string{} 48 | for _, a := range as { 49 | parts := strings.SplitN(a, ":", 2) 50 | if len(parts) != 2 { 51 | fmt.Printf("'%s' is not a valid alias.\n", a) 52 | mflag.Usage() 53 | os.Exit(1) 54 | } 55 | aliases[parts[0]] = parts[1] 56 | } 57 | 58 | go socksProxy(aliases) 59 | 60 | t := template.Must(template.New("pacfile").Parse(pacfile)) 61 | http.HandleFunc("/proxy.pac", func(w http.ResponseWriter, r *http.Request) { 62 | w.Header().Set("Content-Type", "application/x-ns-proxy-autoconfig") 63 | t.Execute(w, pacFileParameters{hostMatch, aliases}) 64 | }) 65 | 66 | if err := http.ListenAndServe(":8080", nil); err != nil { 67 | panic(err) 68 | } 69 | } 70 | 71 | type aliasingResolver struct { 72 | aliases map[string]string 73 | socks5.NameResolver 74 | } 75 | 76 | func (r aliasingResolver) Resolve(ctx context.Context, name string) (context.Context, net.IP, error) { 77 | if alias, ok := r.aliases[name]; ok { 78 | return r.NameResolver.Resolve(ctx, alias) 79 | } 80 | return r.NameResolver.Resolve(ctx, name) 81 | } 82 | 83 | func socksProxy(aliases map[string]string) { 84 | conf := &socks5.Config{ 85 | Resolver: aliasingResolver{ 86 | aliases: aliases, 87 | NameResolver: socks5.DNSResolver{}, 88 | }, 89 | } 90 | server, err := socks5.New(conf) 91 | if err != nil { 92 | panic(err) 93 | } 94 | if err := server.ListenAndServe("tcp", ":8000"); err != nil { 95 | panic(err) 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /vendor/github.com/Microsoft/go-winio/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Microsoft 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /vendor/github.com/Microsoft/go-winio/fileinfo.go: -------------------------------------------------------------------------------- 1 | package winio 2 | 3 | import ( 4 | "os" 5 | "syscall" 6 | "unsafe" 7 | ) 8 | 9 | //sys getFileInformationByHandleEx(h syscall.Handle, class uint32, buffer *byte, size uint32) (err error) = GetFileInformationByHandleEx 10 | //sys setFileInformationByHandle(h syscall.Handle, class uint32, buffer *byte, size uint32) (err error) = SetFileInformationByHandle 11 | 12 | const ( 13 | fileBasicInfo = 0 14 | fileIDInfo = 0x12 15 | ) 16 | 17 | // FileBasicInfo contains file access time and file attributes information. 18 | type FileBasicInfo struct { 19 | CreationTime, LastAccessTime, LastWriteTime, ChangeTime syscall.Filetime 20 | FileAttributes uintptr // includes padding 21 | } 22 | 23 | // GetFileBasicInfo retrieves times and attributes for a file. 24 | func GetFileBasicInfo(f *os.File) (*FileBasicInfo, error) { 25 | bi := &FileBasicInfo{} 26 | if err := getFileInformationByHandleEx(syscall.Handle(f.Fd()), fileBasicInfo, (*byte)(unsafe.Pointer(bi)), uint32(unsafe.Sizeof(*bi))); err != nil { 27 | return nil, &os.PathError{Op: "GetFileInformationByHandleEx", Path: f.Name(), Err: err} 28 | } 29 | return bi, nil 30 | } 31 | 32 | // SetFileBasicInfo sets times and attributes for a file. 33 | func SetFileBasicInfo(f *os.File, bi *FileBasicInfo) error { 34 | if err := setFileInformationByHandle(syscall.Handle(f.Fd()), fileBasicInfo, (*byte)(unsafe.Pointer(bi)), uint32(unsafe.Sizeof(*bi))); err != nil { 35 | return &os.PathError{Op: "SetFileInformationByHandle", Path: f.Name(), Err: err} 36 | } 37 | return nil 38 | } 39 | 40 | // FileIDInfo contains the volume serial number and file ID for a file. This pair should be 41 | // unique on a system. 42 | type FileIDInfo struct { 43 | VolumeSerialNumber uint64 44 | FileID [16]byte 45 | } 46 | 47 | // GetFileID retrieves the unique (volume, file ID) pair for a file. 48 | func GetFileID(f *os.File) (*FileIDInfo, error) { 49 | fileID := &FileIDInfo{} 50 | if err := getFileInformationByHandleEx(syscall.Handle(f.Fd()), fileIDInfo, (*byte)(unsafe.Pointer(fileID)), uint32(unsafe.Sizeof(*fileID))); err != nil { 51 | return nil, &os.PathError{Op: "GetFileInformationByHandleEx", Path: f.Name(), Err: err} 52 | } 53 | return fileID, nil 54 | } 55 | -------------------------------------------------------------------------------- /vendor/github.com/Microsoft/go-winio/syscall.go: -------------------------------------------------------------------------------- 1 | package winio 2 | 3 | //go:generate go run $GOROOT/src/syscall/mksyscall_windows.go -output zsyscall.go file.go pipe.go sd.go fileinfo.go privilege.go backup.go 4 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Simon Eskildsen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Package logrus is a structured logger for Go, completely API compatible with the standard library logger. 3 | 4 | 5 | The simplest way to use Logrus is simply the package-level exported logger: 6 | 7 | package main 8 | 9 | import ( 10 | log "github.com/Sirupsen/logrus" 11 | ) 12 | 13 | func main() { 14 | log.WithFields(log.Fields{ 15 | "animal": "walrus", 16 | "number": 1, 17 | "size": 10, 18 | }).Info("A walrus appears") 19 | } 20 | 21 | Output: 22 | time="2015-09-07T08:48:33Z" level=info msg="A walrus appears" animal=walrus number=1 size=10 23 | 24 | For a full guide visit https://github.com/Sirupsen/logrus 25 | */ 26 | package logrus 27 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/formatter.go: -------------------------------------------------------------------------------- 1 | package logrus 2 | 3 | import "time" 4 | 5 | const DefaultTimestampFormat = time.RFC3339 6 | 7 | // The Formatter interface is used to implement a custom Formatter. It takes an 8 | // `Entry`. It exposes all the fields, including the default ones: 9 | // 10 | // * `entry.Data["msg"]`. The message passed from Info, Warn, Error .. 11 | // * `entry.Data["time"]`. The timestamp. 12 | // * `entry.Data["level"]. The level the entry was logged at. 13 | // 14 | // Any additional fields added with `WithField` or `WithFields` are also in 15 | // `entry.Data`. Format is expected to return an array of bytes which are then 16 | // logged to `logger.Out`. 17 | type Formatter interface { 18 | Format(*Entry) ([]byte, error) 19 | } 20 | 21 | // This is to not silently overwrite `time`, `msg` and `level` fields when 22 | // dumping it. If this code wasn't there doing: 23 | // 24 | // logrus.WithField("level", 1).Info("hello") 25 | // 26 | // Would just silently drop the user provided level. Instead with this code 27 | // it'll logged as: 28 | // 29 | // {"level": "info", "fields.level": 1, "msg": "hello", "time": "..."} 30 | // 31 | // It's not exported because it's still using Data in an opinionated way. It's to 32 | // avoid code duplication between the two default formatters. 33 | func prefixFieldClashes(data Fields) { 34 | _, ok := data["time"] 35 | if ok { 36 | data["fields.time"] = data["time"] 37 | } 38 | 39 | _, ok = data["msg"] 40 | if ok { 41 | data["fields.msg"] = data["msg"] 42 | } 43 | 44 | _, ok = data["level"] 45 | if ok { 46 | data["fields.level"] = data["level"] 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/hooks.go: -------------------------------------------------------------------------------- 1 | package logrus 2 | 3 | // A hook to be fired when logging on the logging levels returned from 4 | // `Levels()` on your implementation of the interface. Note that this is not 5 | // fired in a goroutine or a channel with workers, you should handle such 6 | // functionality yourself if your call is non-blocking and you don't wish for 7 | // the logging calls for levels returned from `Levels()` to block. 8 | type Hook interface { 9 | Levels() []Level 10 | Fire(*Entry) error 11 | } 12 | 13 | // Internal type for storing the hooks on a logger instance. 14 | type LevelHooks map[Level][]Hook 15 | 16 | // Add a hook to an instance of logger. This is called with 17 | // `log.Hooks.Add(new(MyHook))` where `MyHook` implements the `Hook` interface. 18 | func (hooks LevelHooks) Add(hook Hook) { 19 | for _, level := range hook.Levels() { 20 | hooks[level] = append(hooks[level], hook) 21 | } 22 | } 23 | 24 | // Fire all the hooks for the passed level. Used by `entry.log` to fire 25 | // appropriate hooks for a log entry. 26 | func (hooks LevelHooks) Fire(level Level, entry *Entry) error { 27 | for _, hook := range hooks[level] { 28 | if err := hook.Fire(entry); err != nil { 29 | return err 30 | } 31 | } 32 | 33 | return nil 34 | } 35 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/json_formatter.go: -------------------------------------------------------------------------------- 1 | package logrus 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | ) 7 | 8 | type JSONFormatter struct { 9 | // TimestampFormat sets the format used for marshaling timestamps. 10 | TimestampFormat string 11 | } 12 | 13 | func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) { 14 | data := make(Fields, len(entry.Data)+3) 15 | for k, v := range entry.Data { 16 | switch v := v.(type) { 17 | case error: 18 | // Otherwise errors are ignored by `encoding/json` 19 | // https://github.com/Sirupsen/logrus/issues/137 20 | data[k] = v.Error() 21 | default: 22 | data[k] = v 23 | } 24 | } 25 | prefixFieldClashes(data) 26 | 27 | timestampFormat := f.TimestampFormat 28 | if timestampFormat == "" { 29 | timestampFormat = DefaultTimestampFormat 30 | } 31 | 32 | data["time"] = entry.Time.Format(timestampFormat) 33 | data["msg"] = entry.Message 34 | data["level"] = entry.Level.String() 35 | 36 | serialized, err := json.Marshal(data) 37 | if err != nil { 38 | return nil, fmt.Errorf("Failed to marshal fields to JSON, %v", err) 39 | } 40 | return append(serialized, '\n'), nil 41 | } 42 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/terminal_bsd.go: -------------------------------------------------------------------------------- 1 | // +build darwin freebsd openbsd netbsd dragonfly 2 | 3 | package logrus 4 | 5 | import "syscall" 6 | 7 | const ioctlReadTermios = syscall.TIOCGETA 8 | 9 | type Termios syscall.Termios 10 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/terminal_linux.go: -------------------------------------------------------------------------------- 1 | // Based on ssh/terminal: 2 | // Copyright 2013 The Go Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style 4 | // license that can be found in the LICENSE file. 5 | 6 | package logrus 7 | 8 | import "syscall" 9 | 10 | const ioctlReadTermios = syscall.TCGETS 11 | 12 | type Termios syscall.Termios 13 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/terminal_notwindows.go: -------------------------------------------------------------------------------- 1 | // Based on ssh/terminal: 2 | // Copyright 2011 The Go Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style 4 | // license that can be found in the LICENSE file. 5 | 6 | // +build linux darwin freebsd openbsd netbsd dragonfly 7 | 8 | package logrus 9 | 10 | import ( 11 | "syscall" 12 | "unsafe" 13 | ) 14 | 15 | // IsTerminal returns true if stderr's file descriptor is a terminal. 16 | func IsTerminal() bool { 17 | fd := syscall.Stderr 18 | var termios Termios 19 | _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0) 20 | return err == 0 21 | } 22 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/terminal_solaris.go: -------------------------------------------------------------------------------- 1 | // +build solaris 2 | 3 | package logrus 4 | 5 | import ( 6 | "os" 7 | 8 | "golang.org/x/sys/unix" 9 | ) 10 | 11 | // IsTerminal returns true if the given file descriptor is a terminal. 12 | func IsTerminal() bool { 13 | _, err := unix.IoctlGetTermios(int(os.Stdout.Fd()), unix.TCGETA) 14 | return err == nil 15 | } 16 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/terminal_windows.go: -------------------------------------------------------------------------------- 1 | // Based on ssh/terminal: 2 | // Copyright 2011 The Go Authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style 4 | // license that can be found in the LICENSE file. 5 | 6 | // +build windows 7 | 8 | package logrus 9 | 10 | import ( 11 | "syscall" 12 | "unsafe" 13 | ) 14 | 15 | var kernel32 = syscall.NewLazyDLL("kernel32.dll") 16 | 17 | var ( 18 | procGetConsoleMode = kernel32.NewProc("GetConsoleMode") 19 | ) 20 | 21 | // IsTerminal returns true if stderr's file descriptor is a terminal. 22 | func IsTerminal() bool { 23 | fd := syscall.Stderr 24 | var st uint32 25 | r, _, e := syscall.Syscall(procGetConsoleMode.Addr(), 2, uintptr(fd), uintptr(unsafe.Pointer(&st)), 0) 26 | return r != 0 && e == 0 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/Sirupsen/logrus/writer.go: -------------------------------------------------------------------------------- 1 | package logrus 2 | 3 | import ( 4 | "bufio" 5 | "io" 6 | "runtime" 7 | ) 8 | 9 | func (logger *Logger) Writer() *io.PipeWriter { 10 | reader, writer := io.Pipe() 11 | 12 | go logger.writerScanner(reader) 13 | runtime.SetFinalizer(writer, writerFinalizer) 14 | 15 | return writer 16 | } 17 | 18 | func (logger *Logger) writerScanner(reader *io.PipeReader) { 19 | scanner := bufio.NewScanner(reader) 20 | for scanner.Scan() { 21 | logger.Print(scanner.Text()) 22 | } 23 | if err := scanner.Err(); err != nil { 24 | logger.Errorf("Error while reading from Writer: %s", err) 25 | } 26 | reader.Close() 27 | } 28 | 29 | func writerFinalizer(writer *io.PipeWriter) { 30 | writer.Close() 31 | } 32 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/NOTICE: -------------------------------------------------------------------------------- 1 | Docker 2 | Copyright 2012-2016 Docker, Inc. 3 | 4 | This product includes software developed at Docker, Inc. (https://www.docker.com). 5 | 6 | This product contains software (https://github.com/kr/pty) developed 7 | by Keith Rarick, licensed under the MIT License. 8 | 9 | The following is courtesy of our legal counsel: 10 | 11 | 12 | Use and transfer of Docker may be subject to certain restrictions by the 13 | United States and other governments. 14 | It is your responsibility to ensure that your use and/or transfer does not 15 | violate applicable laws. 16 | 17 | For more information, please see https://www.bis.doc.gov 18 | 19 | See also https://www.apache.org/dev/crypto.html and/or seek legal counsel. 20 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/api/types/versions/compare.go: -------------------------------------------------------------------------------- 1 | package versions 2 | 3 | import ( 4 | "strconv" 5 | "strings" 6 | ) 7 | 8 | // compare compares two version strings 9 | // returns -1 if v1 < v2, 1 if v1 > v2, 0 otherwise. 10 | func compare(v1, v2 string) int { 11 | var ( 12 | currTab = strings.Split(v1, ".") 13 | otherTab = strings.Split(v2, ".") 14 | ) 15 | 16 | max := len(currTab) 17 | if len(otherTab) > max { 18 | max = len(otherTab) 19 | } 20 | for i := 0; i < max; i++ { 21 | var currInt, otherInt int 22 | 23 | if len(currTab) > i { 24 | currInt, _ = strconv.Atoi(currTab[i]) 25 | } 26 | if len(otherTab) > i { 27 | otherInt, _ = strconv.Atoi(otherTab[i]) 28 | } 29 | if currInt > otherInt { 30 | return 1 31 | } 32 | if otherInt > currInt { 33 | return -1 34 | } 35 | } 36 | return 0 37 | } 38 | 39 | // LessThan checks if a version is less than another 40 | func LessThan(v, other string) bool { 41 | return compare(v, other) == -1 42 | } 43 | 44 | // LessThanOrEqualTo checks if a version is less than or equal to another 45 | func LessThanOrEqualTo(v, other string) bool { 46 | return compare(v, other) <= 0 47 | } 48 | 49 | // GreaterThan checks if a version is greater than another 50 | func GreaterThan(v, other string) bool { 51 | return compare(v, other) == 1 52 | } 53 | 54 | // GreaterThanOrEqualTo checks if a version is greater than or equal to another 55 | func GreaterThanOrEqualTo(v, other string) bool { 56 | return compare(v, other) >= 0 57 | } 58 | 59 | // Equal checks if a version is equal to another 60 | func Equal(v, other string) bool { 61 | return compare(v, other) == 0 62 | } 63 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/opts/hosts_unix.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package opts 4 | 5 | import "fmt" 6 | 7 | // DefaultHost constant defines the default host string used by docker on other hosts than Windows 8 | var DefaultHost = fmt.Sprintf("unix://%s", DefaultUnixSocket) 9 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/opts/hosts_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package opts 4 | 5 | // DefaultHost constant defines the default host string used by docker on Windows 6 | var DefaultHost = "npipe://" + DefaultNamedPipe 7 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/opts/ip.go: -------------------------------------------------------------------------------- 1 | package opts 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | ) 7 | 8 | // IPOpt holds an IP. It is used to store values from CLI flags. 9 | type IPOpt struct { 10 | *net.IP 11 | } 12 | 13 | // NewIPOpt creates a new IPOpt from a reference net.IP and a 14 | // string representation of an IP. If the string is not a valid 15 | // IP it will fallback to the specified reference. 16 | func NewIPOpt(ref *net.IP, defaultVal string) *IPOpt { 17 | o := &IPOpt{ 18 | IP: ref, 19 | } 20 | o.Set(defaultVal) 21 | return o 22 | } 23 | 24 | // Set sets an IPv4 or IPv6 address from a given string. If the given 25 | // string is not parseable as an IP address it returns an error. 26 | func (o *IPOpt) Set(val string) error { 27 | ip := net.ParseIP(val) 28 | if ip == nil { 29 | return fmt.Errorf("%s is not an ip address", val) 30 | } 31 | *o.IP = ip 32 | return nil 33 | } 34 | 35 | // String returns the IP address stored in the IPOpt. If stored IP is a 36 | // nil pointer, it returns an empty string. 37 | func (o *IPOpt) String() string { 38 | if *o.IP == nil { 39 | return "" 40 | } 41 | return o.IP.String() 42 | } 43 | 44 | // Type returns the type of the option 45 | func (o *IPOpt) Type() string { 46 | return "ip" 47 | } 48 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/opts/opts_unix.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package opts 4 | 5 | // DefaultHTTPHost Default HTTP Host used if only port is provided to -H flag e.g. docker daemon -H tcp://:8080 6 | const DefaultHTTPHost = "localhost" 7 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/archive/archive_other.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package archive 4 | 5 | func getWhiteoutConverter(format WhiteoutFormat) tarWhiteoutConverter { 6 | return nil 7 | } 8 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/archive/archive_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package archive 4 | 5 | import ( 6 | "archive/tar" 7 | "fmt" 8 | "os" 9 | "path/filepath" 10 | "strings" 11 | 12 | "github.com/docker/docker/pkg/longpath" 13 | ) 14 | 15 | // fixVolumePathPrefix does platform specific processing to ensure that if 16 | // the path being passed in is not in a volume path format, convert it to one. 17 | func fixVolumePathPrefix(srcPath string) string { 18 | return longpath.AddPrefix(srcPath) 19 | } 20 | 21 | // getWalkRoot calculates the root path when performing a TarWithOptions. 22 | // We use a separate function as this is platform specific. 23 | func getWalkRoot(srcPath string, include string) string { 24 | return filepath.Join(srcPath, include) 25 | } 26 | 27 | // CanonicalTarNameForPath returns platform-specific filepath 28 | // to canonical posix-style path for tar archival. p is relative 29 | // path. 30 | func CanonicalTarNameForPath(p string) (string, error) { 31 | // windows: convert windows style relative path with backslashes 32 | // into forward slashes. Since windows does not allow '/' or '\' 33 | // in file names, it is mostly safe to replace however we must 34 | // check just in case 35 | if strings.Contains(p, "/") { 36 | return "", fmt.Errorf("Windows path contains forward slash: %s", p) 37 | } 38 | return strings.Replace(p, string(os.PathSeparator), "/", -1), nil 39 | 40 | } 41 | 42 | // chmodTarEntry is used to adjust the file permissions used in tar header based 43 | // on the platform the archival is done. 44 | func chmodTarEntry(perm os.FileMode) os.FileMode { 45 | perm &= 0755 46 | // Add the x bit: make everything +x from windows 47 | perm |= 0111 48 | 49 | return perm 50 | } 51 | 52 | func setHeaderForSpecialDevice(hdr *tar.Header, ta *tarAppender, name string, stat interface{}) (inode uint64, err error) { 53 | // do nothing. no notion of Rdev, Inode, Nlink in stat on Windows 54 | return 55 | } 56 | 57 | // handleTarTypeBlockCharFifo is an OS-specific helper function used by 58 | // createTarFile to handle the following types of header: Block; Char; Fifo 59 | func handleTarTypeBlockCharFifo(hdr *tar.Header, path string) error { 60 | return nil 61 | } 62 | 63 | func handleLChmod(hdr *tar.Header, path string, hdrInfo os.FileInfo) error { 64 | return nil 65 | } 66 | 67 | func getFileUIDGID(stat interface{}) (int, int, error) { 68 | // no notion of file ownership mapping yet on Windows 69 | return 0, 0, nil 70 | } 71 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/archive/changes_other.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package archive 4 | 5 | import ( 6 | "fmt" 7 | "os" 8 | "path/filepath" 9 | "runtime" 10 | "strings" 11 | 12 | "github.com/docker/docker/pkg/system" 13 | ) 14 | 15 | func collectFileInfoForChanges(oldDir, newDir string) (*FileInfo, *FileInfo, error) { 16 | var ( 17 | oldRoot, newRoot *FileInfo 18 | err1, err2 error 19 | errs = make(chan error, 2) 20 | ) 21 | go func() { 22 | oldRoot, err1 = collectFileInfo(oldDir) 23 | errs <- err1 24 | }() 25 | go func() { 26 | newRoot, err2 = collectFileInfo(newDir) 27 | errs <- err2 28 | }() 29 | 30 | // block until both routines have returned 31 | for i := 0; i < 2; i++ { 32 | if err := <-errs; err != nil { 33 | return nil, nil, err 34 | } 35 | } 36 | 37 | return oldRoot, newRoot, nil 38 | } 39 | 40 | func collectFileInfo(sourceDir string) (*FileInfo, error) { 41 | root := newRootFileInfo() 42 | 43 | err := filepath.Walk(sourceDir, func(path string, f os.FileInfo, err error) error { 44 | if err != nil { 45 | return err 46 | } 47 | 48 | // Rebase path 49 | relPath, err := filepath.Rel(sourceDir, path) 50 | if err != nil { 51 | return err 52 | } 53 | 54 | // As this runs on the daemon side, file paths are OS specific. 55 | relPath = filepath.Join(string(os.PathSeparator), relPath) 56 | 57 | // See https://github.com/golang/go/issues/9168 - bug in filepath.Join. 58 | // Temporary workaround. If the returned path starts with two backslashes, 59 | // trim it down to a single backslash. Only relevant on Windows. 60 | if runtime.GOOS == "windows" { 61 | if strings.HasPrefix(relPath, `\\`) { 62 | relPath = relPath[1:] 63 | } 64 | } 65 | 66 | if relPath == string(os.PathSeparator) { 67 | return nil 68 | } 69 | 70 | parent := root.LookUp(filepath.Dir(relPath)) 71 | if parent == nil { 72 | return fmt.Errorf("collectFileInfo: Unexpectedly no parent for %s", relPath) 73 | } 74 | 75 | info := &FileInfo{ 76 | name: filepath.Base(relPath), 77 | children: make(map[string]*FileInfo), 78 | parent: parent, 79 | } 80 | 81 | s, err := system.Lstat(path) 82 | if err != nil { 83 | return err 84 | } 85 | info.stat = s 86 | 87 | info.capability, _ = system.Lgetxattr(path, "security.capability") 88 | 89 | parent.children[info.name] = info 90 | 91 | return nil 92 | }) 93 | if err != nil { 94 | return nil, err 95 | } 96 | return root, nil 97 | } 98 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/archive/changes_unix.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package archive 4 | 5 | import ( 6 | "os" 7 | "syscall" 8 | 9 | "github.com/docker/docker/pkg/system" 10 | ) 11 | 12 | func statDifferent(oldStat *system.StatT, newStat *system.StatT) bool { 13 | // Don't look at size for dirs, its not a good measure of change 14 | if oldStat.Mode() != newStat.Mode() || 15 | oldStat.UID() != newStat.UID() || 16 | oldStat.GID() != newStat.GID() || 17 | oldStat.Rdev() != newStat.Rdev() || 18 | // Don't look at size for dirs, its not a good measure of change 19 | (oldStat.Mode()&syscall.S_IFDIR != syscall.S_IFDIR && 20 | (!sameFsTimeSpec(oldStat.Mtim(), newStat.Mtim()) || (oldStat.Size() != newStat.Size()))) { 21 | return true 22 | } 23 | return false 24 | } 25 | 26 | func (info *FileInfo) isDir() bool { 27 | return info.parent == nil || info.stat.Mode()&syscall.S_IFDIR != 0 28 | } 29 | 30 | func getIno(fi os.FileInfo) uint64 { 31 | return uint64(fi.Sys().(*syscall.Stat_t).Ino) 32 | } 33 | 34 | func hasHardlinks(fi os.FileInfo) bool { 35 | return fi.Sys().(*syscall.Stat_t).Nlink > 1 36 | } 37 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/archive/changes_windows.go: -------------------------------------------------------------------------------- 1 | package archive 2 | 3 | import ( 4 | "os" 5 | 6 | "github.com/docker/docker/pkg/system" 7 | ) 8 | 9 | func statDifferent(oldStat *system.StatT, newStat *system.StatT) bool { 10 | 11 | // Don't look at size for dirs, its not a good measure of change 12 | if oldStat.ModTime() != newStat.ModTime() || 13 | oldStat.Mode() != newStat.Mode() || 14 | oldStat.Size() != newStat.Size() && !oldStat.IsDir() { 15 | return true 16 | } 17 | return false 18 | } 19 | 20 | func (info *FileInfo) isDir() bool { 21 | return info.parent == nil || info.stat.IsDir() 22 | } 23 | 24 | func getIno(fi os.FileInfo) (inode uint64) { 25 | return 26 | } 27 | 28 | func hasHardlinks(fi os.FileInfo) bool { 29 | return false 30 | } 31 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/archive/copy_unix.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package archive 4 | 5 | import ( 6 | "path/filepath" 7 | ) 8 | 9 | func normalizePath(path string) string { 10 | return filepath.ToSlash(path) 11 | } 12 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/archive/copy_windows.go: -------------------------------------------------------------------------------- 1 | package archive 2 | 3 | import ( 4 | "path/filepath" 5 | ) 6 | 7 | func normalizePath(path string) string { 8 | return filepath.FromSlash(path) 9 | } 10 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/archive/time_linux.go: -------------------------------------------------------------------------------- 1 | package archive 2 | 3 | import ( 4 | "syscall" 5 | "time" 6 | ) 7 | 8 | func timeToTimespec(time time.Time) (ts syscall.Timespec) { 9 | if time.IsZero() { 10 | // Return UTIME_OMIT special value 11 | ts.Sec = 0 12 | ts.Nsec = ((1 << 30) - 2) 13 | return 14 | } 15 | return syscall.NsecToTimespec(time.UnixNano()) 16 | } 17 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/archive/time_unsupported.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package archive 4 | 5 | import ( 6 | "syscall" 7 | "time" 8 | ) 9 | 10 | func timeToTimespec(time time.Time) (ts syscall.Timespec) { 11 | nsec := int64(0) 12 | if !time.IsZero() { 13 | nsec = time.UnixNano() 14 | } 15 | return syscall.NsecToTimespec(nsec) 16 | } 17 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/archive/whiteouts.go: -------------------------------------------------------------------------------- 1 | package archive 2 | 3 | // Whiteouts are files with a special meaning for the layered filesystem. 4 | // Docker uses AUFS whiteout files inside exported archives. In other 5 | // filesystems these files are generated/handled on tar creation/extraction. 6 | 7 | // WhiteoutPrefix prefix means file is a whiteout. If this is followed by a 8 | // filename this means that file has been removed from the base layer. 9 | const WhiteoutPrefix = ".wh." 10 | 11 | // WhiteoutMetaPrefix prefix means whiteout has a special meaning and is not 12 | // for removing an actual file. Normally these files are excluded from exported 13 | // archives. 14 | const WhiteoutMetaPrefix = WhiteoutPrefix + WhiteoutPrefix 15 | 16 | // WhiteoutLinkDir is a directory AUFS uses for storing hardlink links to other 17 | // layers. Normally these should not go into exported archives and all changed 18 | // hardlinks should be copied to the top layer. 19 | const WhiteoutLinkDir = WhiteoutMetaPrefix + "plnk" 20 | 21 | // WhiteoutOpaqueDir file means directory has been made opaque - meaning 22 | // readdir calls to this directory do not follow to lower layers. 23 | const WhiteoutOpaqueDir = WhiteoutMetaPrefix + ".opq" 24 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/archive/wrap.go: -------------------------------------------------------------------------------- 1 | package archive 2 | 3 | import ( 4 | "archive/tar" 5 | "bytes" 6 | "io/ioutil" 7 | ) 8 | 9 | // Generate generates a new archive from the content provided 10 | // as input. 11 | // 12 | // `files` is a sequence of path/content pairs. A new file is 13 | // added to the archive for each pair. 14 | // If the last pair is incomplete, the file is created with an 15 | // empty content. For example: 16 | // 17 | // Generate("foo.txt", "hello world", "emptyfile") 18 | // 19 | // The above call will return an archive with 2 files: 20 | // * ./foo.txt with content "hello world" 21 | // * ./empty with empty content 22 | // 23 | // FIXME: stream content instead of buffering 24 | // FIXME: specify permissions and other archive metadata 25 | func Generate(input ...string) (Archive, error) { 26 | files := parseStringPairs(input...) 27 | buf := new(bytes.Buffer) 28 | tw := tar.NewWriter(buf) 29 | for _, file := range files { 30 | name, content := file[0], file[1] 31 | hdr := &tar.Header{ 32 | Name: name, 33 | Size: int64(len(content)), 34 | } 35 | if err := tw.WriteHeader(hdr); err != nil { 36 | return nil, err 37 | } 38 | if _, err := tw.Write([]byte(content)); err != nil { 39 | return nil, err 40 | } 41 | } 42 | if err := tw.Close(); err != nil { 43 | return nil, err 44 | } 45 | return ioutil.NopCloser(buf), nil 46 | } 47 | 48 | func parseStringPairs(input ...string) (output [][2]string) { 49 | output = make([][2]string, 0, len(input)/2+1) 50 | for i := 0; i < len(input); i += 2 { 51 | var pair [2]string 52 | pair[0] = input[i] 53 | if i+1 < len(input) { 54 | pair[1] = input[i+1] 55 | } 56 | output = append(output, pair) 57 | } 58 | return 59 | } 60 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/fileutils/fileutils_darwin.go: -------------------------------------------------------------------------------- 1 | package fileutils 2 | 3 | import ( 4 | "os" 5 | "os/exec" 6 | "strconv" 7 | "strings" 8 | ) 9 | 10 | // GetTotalUsedFds returns the number of used File Descriptors by 11 | // executing `lsof -p PID` 12 | func GetTotalUsedFds() int { 13 | pid := os.Getpid() 14 | 15 | cmd := exec.Command("lsof", "-p", strconv.Itoa(pid)) 16 | 17 | output, err := cmd.CombinedOutput() 18 | if err != nil { 19 | return -1 20 | } 21 | 22 | outputStr := strings.TrimSpace(string(output)) 23 | 24 | fds := strings.Split(outputStr, "\n") 25 | 26 | return len(fds) - 1 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/fileutils/fileutils_solaris.go: -------------------------------------------------------------------------------- 1 | package fileutils 2 | 3 | // GetTotalUsedFds Returns the number of used File Descriptors. 4 | // On Solaris these limits are per process and not systemwide 5 | func GetTotalUsedFds() int { 6 | return -1 7 | } 8 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/fileutils/fileutils_unix.go: -------------------------------------------------------------------------------- 1 | // +build linux freebsd 2 | 3 | package fileutils 4 | 5 | import ( 6 | "fmt" 7 | "io/ioutil" 8 | "os" 9 | 10 | "github.com/Sirupsen/logrus" 11 | ) 12 | 13 | // GetTotalUsedFds Returns the number of used File Descriptors by 14 | // reading it via /proc filesystem. 15 | func GetTotalUsedFds() int { 16 | if fds, err := ioutil.ReadDir(fmt.Sprintf("/proc/%d/fd", os.Getpid())); err != nil { 17 | logrus.Errorf("Error opening /proc/%d/fd: %s", os.Getpid(), err) 18 | } else { 19 | return len(fds) 20 | } 21 | return -1 22 | } 23 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/fileutils/fileutils_windows.go: -------------------------------------------------------------------------------- 1 | package fileutils 2 | 3 | // GetTotalUsedFds Returns the number of used File Descriptors. Not supported 4 | // on Windows. 5 | func GetTotalUsedFds() int { 6 | return -1 7 | } 8 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/homedir/homedir.go: -------------------------------------------------------------------------------- 1 | package homedir 2 | 3 | import ( 4 | "os" 5 | "runtime" 6 | 7 | "github.com/opencontainers/runc/libcontainer/user" 8 | ) 9 | 10 | // Key returns the env var name for the user's home dir based on 11 | // the platform being run on 12 | func Key() string { 13 | if runtime.GOOS == "windows" { 14 | return "USERPROFILE" 15 | } 16 | return "HOME" 17 | } 18 | 19 | // Get returns the home directory of the current user with the help of 20 | // environment variables depending on the target operating system. 21 | // Returned path should be used with "path/filepath" to form new paths. 22 | func Get() string { 23 | home := os.Getenv(Key()) 24 | if home == "" && runtime.GOOS != "windows" { 25 | if u, err := user.CurrentUser(); err == nil { 26 | return u.Home 27 | } 28 | } 29 | return home 30 | } 31 | 32 | // GetShortcutString returns the string that is shortcut to user's home directory 33 | // in the native shell of the platform running on. 34 | func GetShortcutString() string { 35 | if runtime.GOOS == "windows" { 36 | return "%USERPROFILE%" // be careful while using in format functions 37 | } 38 | return "~" 39 | } 40 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/idtools/idtools_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package idtools 4 | 5 | import ( 6 | "os" 7 | 8 | "github.com/docker/docker/pkg/system" 9 | ) 10 | 11 | // Platforms such as Windows do not support the UID/GID concept. So make this 12 | // just a wrapper around system.MkdirAll. 13 | func mkdirAs(path string, mode os.FileMode, ownerUID, ownerGID int, mkAll, chownExisting bool) error { 14 | if err := system.MkdirAll(path, mode); err != nil && !os.IsExist(err) { 15 | return err 16 | } 17 | return nil 18 | } 19 | 20 | // CanAccess takes a valid (existing) directory and a uid, gid pair and determines 21 | // if that uid, gid pair has access (execute bit) to the directory 22 | // Windows does not require/support this function, so always return true 23 | func CanAccess(path string, uid, gid int) bool { 24 | return true 25 | } 26 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/idtools/usergroupadd_unsupported.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package idtools 4 | 5 | import "fmt" 6 | 7 | // AddNamespaceRangesUser takes a name and finds an unused uid, gid pair 8 | // and calls the appropriate helper function to add the group and then 9 | // the user to the group in /etc/group and /etc/passwd respectively. 10 | func AddNamespaceRangesUser(name string) (int, int, error) { 11 | return -1, -1, fmt.Errorf("No support for adding users or groups on this OS") 12 | } 13 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/ioutils/buffer.go: -------------------------------------------------------------------------------- 1 | package ioutils 2 | 3 | import ( 4 | "errors" 5 | "io" 6 | ) 7 | 8 | var errBufferFull = errors.New("buffer is full") 9 | 10 | type fixedBuffer struct { 11 | buf []byte 12 | pos int 13 | lastRead int 14 | } 15 | 16 | func (b *fixedBuffer) Write(p []byte) (int, error) { 17 | n := copy(b.buf[b.pos:cap(b.buf)], p) 18 | b.pos += n 19 | 20 | if n < len(p) { 21 | if b.pos == cap(b.buf) { 22 | return n, errBufferFull 23 | } 24 | return n, io.ErrShortWrite 25 | } 26 | return n, nil 27 | } 28 | 29 | func (b *fixedBuffer) Read(p []byte) (int, error) { 30 | n := copy(p, b.buf[b.lastRead:b.pos]) 31 | b.lastRead += n 32 | return n, nil 33 | } 34 | 35 | func (b *fixedBuffer) Len() int { 36 | return b.pos - b.lastRead 37 | } 38 | 39 | func (b *fixedBuffer) Cap() int { 40 | return cap(b.buf) 41 | } 42 | 43 | func (b *fixedBuffer) Reset() { 44 | b.pos = 0 45 | b.lastRead = 0 46 | b.buf = b.buf[:0] 47 | } 48 | 49 | func (b *fixedBuffer) String() string { 50 | return string(b.buf[b.lastRead:b.pos]) 51 | } 52 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/ioutils/fmt.go: -------------------------------------------------------------------------------- 1 | package ioutils 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | ) 7 | 8 | // FprintfIfNotEmpty prints the string value if it's not empty 9 | func FprintfIfNotEmpty(w io.Writer, format, value string) (int, error) { 10 | if value != "" { 11 | return fmt.Fprintf(w, format, value) 12 | } 13 | return 0, nil 14 | } 15 | 16 | // FprintfIfTrue prints the boolean value if it's true 17 | func FprintfIfTrue(w io.Writer, format string, ok bool) (int, error) { 18 | if ok { 19 | return fmt.Fprintf(w, format, ok) 20 | } 21 | return 0, nil 22 | } 23 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/ioutils/temp_unix.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package ioutils 4 | 5 | import "io/ioutil" 6 | 7 | // TempDir on Unix systems is equivalent to ioutil.TempDir. 8 | func TempDir(dir, prefix string) (string, error) { 9 | return ioutil.TempDir(dir, prefix) 10 | } 11 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/ioutils/temp_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package ioutils 4 | 5 | import ( 6 | "io/ioutil" 7 | 8 | "github.com/docker/docker/pkg/longpath" 9 | ) 10 | 11 | // TempDir is the equivalent of ioutil.TempDir, except that the result is in Windows longpath format. 12 | func TempDir(dir, prefix string) (string, error) { 13 | tempDir, err := ioutil.TempDir(dir, prefix) 14 | if err != nil { 15 | return "", err 16 | } 17 | return longpath.AddPrefix(tempDir), nil 18 | } 19 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/ioutils/writeflusher.go: -------------------------------------------------------------------------------- 1 | package ioutils 2 | 3 | import ( 4 | "io" 5 | "sync" 6 | ) 7 | 8 | // WriteFlusher wraps the Write and Flush operation ensuring that every write 9 | // is a flush. In addition, the Close method can be called to intercept 10 | // Read/Write calls if the targets lifecycle has already ended. 11 | type WriteFlusher struct { 12 | w io.Writer 13 | flusher flusher 14 | flushed chan struct{} 15 | flushedOnce sync.Once 16 | closed chan struct{} 17 | closeLock sync.Mutex 18 | } 19 | 20 | type flusher interface { 21 | Flush() 22 | } 23 | 24 | var errWriteFlusherClosed = io.EOF 25 | 26 | func (wf *WriteFlusher) Write(b []byte) (n int, err error) { 27 | select { 28 | case <-wf.closed: 29 | return 0, errWriteFlusherClosed 30 | default: 31 | } 32 | 33 | n, err = wf.w.Write(b) 34 | wf.Flush() // every write is a flush. 35 | return n, err 36 | } 37 | 38 | // Flush the stream immediately. 39 | func (wf *WriteFlusher) Flush() { 40 | select { 41 | case <-wf.closed: 42 | return 43 | default: 44 | } 45 | 46 | wf.flushedOnce.Do(func() { 47 | close(wf.flushed) 48 | }) 49 | wf.flusher.Flush() 50 | } 51 | 52 | // Flushed returns the state of flushed. 53 | // If it's flushed, return true, or else it return false. 54 | func (wf *WriteFlusher) Flushed() bool { 55 | // BUG(stevvooe): Remove this method. Its use is inherently racy. Seems to 56 | // be used to detect whether or a response code has been issued or not. 57 | // Another hook should be used instead. 58 | var flushed bool 59 | select { 60 | case <-wf.flushed: 61 | flushed = true 62 | default: 63 | } 64 | return flushed 65 | } 66 | 67 | // Close closes the write flusher, disallowing any further writes to the 68 | // target. After the flusher is closed, all calls to write or flush will 69 | // result in an error. 70 | func (wf *WriteFlusher) Close() error { 71 | wf.closeLock.Lock() 72 | defer wf.closeLock.Unlock() 73 | 74 | select { 75 | case <-wf.closed: 76 | return errWriteFlusherClosed 77 | default: 78 | close(wf.closed) 79 | } 80 | return nil 81 | } 82 | 83 | // NewWriteFlusher returns a new WriteFlusher. 84 | func NewWriteFlusher(w io.Writer) *WriteFlusher { 85 | var fl flusher 86 | if f, ok := w.(flusher); ok { 87 | fl = f 88 | } else { 89 | fl = &NopFlusher{} 90 | } 91 | return &WriteFlusher{w: w, flusher: fl, closed: make(chan struct{}), flushed: make(chan struct{})} 92 | } 93 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/ioutils/writers.go: -------------------------------------------------------------------------------- 1 | package ioutils 2 | 3 | import "io" 4 | 5 | // NopWriter represents a type which write operation is nop. 6 | type NopWriter struct{} 7 | 8 | func (*NopWriter) Write(buf []byte) (int, error) { 9 | return len(buf), nil 10 | } 11 | 12 | type nopWriteCloser struct { 13 | io.Writer 14 | } 15 | 16 | func (w *nopWriteCloser) Close() error { return nil } 17 | 18 | // NopWriteCloser returns a nopWriteCloser. 19 | func NopWriteCloser(w io.Writer) io.WriteCloser { 20 | return &nopWriteCloser{w} 21 | } 22 | 23 | // NopFlusher represents a type which flush operation is nop. 24 | type NopFlusher struct{} 25 | 26 | // Flush is a nop operation. 27 | func (f *NopFlusher) Flush() {} 28 | 29 | type writeCloserWrapper struct { 30 | io.Writer 31 | closer func() error 32 | } 33 | 34 | func (r *writeCloserWrapper) Close() error { 35 | return r.closer() 36 | } 37 | 38 | // NewWriteCloserWrapper returns a new io.WriteCloser. 39 | func NewWriteCloserWrapper(r io.Writer, closer func() error) io.WriteCloser { 40 | return &writeCloserWrapper{ 41 | Writer: r, 42 | closer: closer, 43 | } 44 | } 45 | 46 | // WriteCounter wraps a concrete io.Writer and hold a count of the number 47 | // of bytes written to the writer during a "session". 48 | // This can be convenient when write return is masked 49 | // (e.g., json.Encoder.Encode()) 50 | type WriteCounter struct { 51 | Count int64 52 | Writer io.Writer 53 | } 54 | 55 | // NewWriteCounter returns a new WriteCounter. 56 | func NewWriteCounter(w io.Writer) *WriteCounter { 57 | return &WriteCounter{ 58 | Writer: w, 59 | } 60 | } 61 | 62 | func (wc *WriteCounter) Write(p []byte) (count int, err error) { 63 | count, err = wc.Writer.Write(p) 64 | wc.Count += int64(count) 65 | return 66 | } 67 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/longpath/longpath.go: -------------------------------------------------------------------------------- 1 | // longpath introduces some constants and helper functions for handling long paths 2 | // in Windows, which are expected to be prepended with `\\?\` and followed by either 3 | // a drive letter, a UNC server\share, or a volume identifier. 4 | 5 | package longpath 6 | 7 | import ( 8 | "strings" 9 | ) 10 | 11 | // Prefix is the longpath prefix for Windows file paths. 12 | const Prefix = `\\?\` 13 | 14 | // AddPrefix will add the Windows long path prefix to the path provided if 15 | // it does not already have it. 16 | func AddPrefix(path string) string { 17 | if !strings.HasPrefix(path, Prefix) { 18 | if strings.HasPrefix(path, `\\`) { 19 | // This is a UNC path, so we need to add 'UNC' to the path as well. 20 | path = Prefix + `UNC` + path[1:] 21 | } else { 22 | path = Prefix + path 23 | } 24 | } 25 | return path 26 | } 27 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/promise/promise.go: -------------------------------------------------------------------------------- 1 | package promise 2 | 3 | // Go is a basic promise implementation: it wraps calls a function in a goroutine, 4 | // and returns a channel which will later return the function's return value. 5 | func Go(f func() error) chan error { 6 | ch := make(chan error, 1) 7 | go func() { 8 | ch <- f() 9 | }() 10 | return ch 11 | } 12 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/chtimes.go: -------------------------------------------------------------------------------- 1 | package system 2 | 3 | import ( 4 | "os" 5 | "syscall" 6 | "time" 7 | "unsafe" 8 | ) 9 | 10 | var ( 11 | maxTime time.Time 12 | ) 13 | 14 | func init() { 15 | if unsafe.Sizeof(syscall.Timespec{}.Nsec) == 8 { 16 | // This is a 64 bit timespec 17 | // os.Chtimes limits time to the following 18 | maxTime = time.Unix(0, 1<<63-1) 19 | } else { 20 | // This is a 32 bit timespec 21 | maxTime = time.Unix(1<<31-1, 0) 22 | } 23 | } 24 | 25 | // Chtimes changes the access time and modified time of a file at the given path 26 | func Chtimes(name string, atime time.Time, mtime time.Time) error { 27 | unixMinTime := time.Unix(0, 0) 28 | unixMaxTime := maxTime 29 | 30 | // If the modified time is prior to the Unix Epoch, or after the 31 | // end of Unix Time, os.Chtimes has undefined behavior 32 | // default to Unix Epoch in this case, just in case 33 | 34 | if atime.Before(unixMinTime) || atime.After(unixMaxTime) { 35 | atime = unixMinTime 36 | } 37 | 38 | if mtime.Before(unixMinTime) || mtime.After(unixMaxTime) { 39 | mtime = unixMinTime 40 | } 41 | 42 | if err := os.Chtimes(name, atime, mtime); err != nil { 43 | return err 44 | } 45 | 46 | // Take platform specific action for setting create time. 47 | if err := setCTime(name, mtime); err != nil { 48 | return err 49 | } 50 | 51 | return nil 52 | } 53 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/chtimes_unix.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package system 4 | 5 | import ( 6 | "time" 7 | ) 8 | 9 | //setCTime will set the create time on a file. On Unix, the create 10 | //time is updated as a side effect of setting the modified time, so 11 | //no action is required. 12 | func setCTime(path string, ctime time.Time) error { 13 | return nil 14 | } 15 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/chtimes_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package system 4 | 5 | import ( 6 | "syscall" 7 | "time" 8 | ) 9 | 10 | //setCTime will set the create time on a file. On Windows, this requires 11 | //calling SetFileTime and explicitly including the create time. 12 | func setCTime(path string, ctime time.Time) error { 13 | ctimespec := syscall.NsecToTimespec(ctime.UnixNano()) 14 | pathp, e := syscall.UTF16PtrFromString(path) 15 | if e != nil { 16 | return e 17 | } 18 | h, e := syscall.CreateFile(pathp, 19 | syscall.FILE_WRITE_ATTRIBUTES, syscall.FILE_SHARE_WRITE, nil, 20 | syscall.OPEN_EXISTING, syscall.FILE_FLAG_BACKUP_SEMANTICS, 0) 21 | if e != nil { 22 | return e 23 | } 24 | defer syscall.Close(h) 25 | c := syscall.NsecToFiletime(syscall.TimespecToNsec(ctimespec)) 26 | return syscall.SetFileTime(h, &c, nil, nil) 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/errors.go: -------------------------------------------------------------------------------- 1 | package system 2 | 3 | import ( 4 | "errors" 5 | ) 6 | 7 | var ( 8 | // ErrNotSupportedPlatform means the platform is not supported. 9 | ErrNotSupportedPlatform = errors.New("platform and architecture is not supported") 10 | ) 11 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/filesys.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package system 4 | 5 | import ( 6 | "os" 7 | "path/filepath" 8 | ) 9 | 10 | // MkdirAll creates a directory named path along with any necessary parents, 11 | // with permission specified by attribute perm for all dir created. 12 | func MkdirAll(path string, perm os.FileMode) error { 13 | return os.MkdirAll(path, perm) 14 | } 15 | 16 | // IsAbs is a platform-specific wrapper for filepath.IsAbs. 17 | func IsAbs(path string) bool { 18 | return filepath.IsAbs(path) 19 | } 20 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/filesys_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package system 4 | 5 | import ( 6 | "os" 7 | "path/filepath" 8 | "regexp" 9 | "strings" 10 | "syscall" 11 | ) 12 | 13 | // MkdirAll implementation that is volume path aware for Windows. 14 | func MkdirAll(path string, perm os.FileMode) error { 15 | if re := regexp.MustCompile(`^\\\\\?\\Volume{[a-z0-9-]+}$`); re.MatchString(path) { 16 | return nil 17 | } 18 | 19 | // The rest of this method is copied from os.MkdirAll and should be kept 20 | // as-is to ensure compatibility. 21 | 22 | // Fast path: if we can tell whether path is a directory or file, stop with success or error. 23 | dir, err := os.Stat(path) 24 | if err == nil { 25 | if dir.IsDir() { 26 | return nil 27 | } 28 | return &os.PathError{ 29 | Op: "mkdir", 30 | Path: path, 31 | Err: syscall.ENOTDIR, 32 | } 33 | } 34 | 35 | // Slow path: make sure parent exists and then call Mkdir for path. 36 | i := len(path) 37 | for i > 0 && os.IsPathSeparator(path[i-1]) { // Skip trailing path separator. 38 | i-- 39 | } 40 | 41 | j := i 42 | for j > 0 && !os.IsPathSeparator(path[j-1]) { // Scan backward over element. 43 | j-- 44 | } 45 | 46 | if j > 1 { 47 | // Create parent 48 | err = MkdirAll(path[0:j-1], perm) 49 | if err != nil { 50 | return err 51 | } 52 | } 53 | 54 | // Parent now exists; invoke Mkdir and use its result. 55 | err = os.Mkdir(path, perm) 56 | if err != nil { 57 | // Handle arguments like "foo/." by 58 | // double-checking that directory doesn't exist. 59 | dir, err1 := os.Lstat(path) 60 | if err1 == nil && dir.IsDir() { 61 | return nil 62 | } 63 | return err 64 | } 65 | return nil 66 | } 67 | 68 | // IsAbs is a platform-specific wrapper for filepath.IsAbs. On Windows, 69 | // golang filepath.IsAbs does not consider a path \windows\system32 as absolute 70 | // as it doesn't start with a drive-letter/colon combination. However, in 71 | // docker we need to verify things such as WORKDIR /windows/system32 in 72 | // a Dockerfile (which gets translated to \windows\system32 when being processed 73 | // by the daemon. This SHOULD be treated as absolute from a docker processing 74 | // perspective. 75 | func IsAbs(path string) bool { 76 | if !filepath.IsAbs(path) { 77 | if !strings.HasPrefix(path, string(os.PathSeparator)) { 78 | return false 79 | } 80 | } 81 | return true 82 | } 83 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/lstat.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package system 4 | 5 | import ( 6 | "syscall" 7 | ) 8 | 9 | // Lstat takes a path to a file and returns 10 | // a system.StatT type pertaining to that file. 11 | // 12 | // Throws an error if the file does not exist 13 | func Lstat(path string) (*StatT, error) { 14 | s := &syscall.Stat_t{} 15 | if err := syscall.Lstat(path, s); err != nil { 16 | return nil, err 17 | } 18 | return fromStatT(s) 19 | } 20 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/lstat_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package system 4 | 5 | import ( 6 | "os" 7 | ) 8 | 9 | // Lstat calls os.Lstat to get a fileinfo interface back. 10 | // This is then copied into our own locally defined structure. 11 | // Note the Linux version uses fromStatT to do the copy back, 12 | // but that not strictly necessary when already in an OS specific module. 13 | func Lstat(path string) (*StatT, error) { 14 | fi, err := os.Lstat(path) 15 | if err != nil { 16 | return nil, err 17 | } 18 | 19 | return &StatT{ 20 | name: fi.Name(), 21 | size: fi.Size(), 22 | mode: fi.Mode(), 23 | modTime: fi.ModTime(), 24 | isDir: fi.IsDir()}, nil 25 | } 26 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/meminfo.go: -------------------------------------------------------------------------------- 1 | package system 2 | 3 | // MemInfo contains memory statistics of the host system. 4 | type MemInfo struct { 5 | // Total usable RAM (i.e. physical RAM minus a few reserved bits and the 6 | // kernel binary code). 7 | MemTotal int64 8 | 9 | // Amount of free memory. 10 | MemFree int64 11 | 12 | // Total amount of swap space available. 13 | SwapTotal int64 14 | 15 | // Amount of swap space that is currently unused. 16 | SwapFree int64 17 | } 18 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/meminfo_linux.go: -------------------------------------------------------------------------------- 1 | package system 2 | 3 | import ( 4 | "bufio" 5 | "io" 6 | "os" 7 | "strconv" 8 | "strings" 9 | 10 | "github.com/docker/go-units" 11 | ) 12 | 13 | // ReadMemInfo retrieves memory statistics of the host system and returns a 14 | // MemInfo type. 15 | func ReadMemInfo() (*MemInfo, error) { 16 | file, err := os.Open("/proc/meminfo") 17 | if err != nil { 18 | return nil, err 19 | } 20 | defer file.Close() 21 | return parseMemInfo(file) 22 | } 23 | 24 | // parseMemInfo parses the /proc/meminfo file into 25 | // a MemInfo object given an io.Reader to the file. 26 | // Throws error if there are problems reading from the file 27 | func parseMemInfo(reader io.Reader) (*MemInfo, error) { 28 | meminfo := &MemInfo{} 29 | scanner := bufio.NewScanner(reader) 30 | for scanner.Scan() { 31 | // Expected format: ["MemTotal:", "1234", "kB"] 32 | parts := strings.Fields(scanner.Text()) 33 | 34 | // Sanity checks: Skip malformed entries. 35 | if len(parts) < 3 || parts[2] != "kB" { 36 | continue 37 | } 38 | 39 | // Convert to bytes. 40 | size, err := strconv.Atoi(parts[1]) 41 | if err != nil { 42 | continue 43 | } 44 | bytes := int64(size) * units.KiB 45 | 46 | switch parts[0] { 47 | case "MemTotal:": 48 | meminfo.MemTotal = bytes 49 | case "MemFree:": 50 | meminfo.MemFree = bytes 51 | case "SwapTotal:": 52 | meminfo.SwapTotal = bytes 53 | case "SwapFree:": 54 | meminfo.SwapFree = bytes 55 | } 56 | 57 | } 58 | 59 | // Handle errors that may have occurred during the reading of the file. 60 | if err := scanner.Err(); err != nil { 61 | return nil, err 62 | } 63 | 64 | return meminfo, nil 65 | } 66 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/meminfo_unsupported.go: -------------------------------------------------------------------------------- 1 | // +build !linux,!windows,!solaris 2 | 3 | package system 4 | 5 | // ReadMemInfo is not supported on platforms other than linux and windows. 6 | func ReadMemInfo() (*MemInfo, error) { 7 | return nil, ErrNotSupportedPlatform 8 | } 9 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/meminfo_windows.go: -------------------------------------------------------------------------------- 1 | package system 2 | 3 | import ( 4 | "syscall" 5 | "unsafe" 6 | ) 7 | 8 | var ( 9 | modkernel32 = syscall.NewLazyDLL("kernel32.dll") 10 | 11 | procGlobalMemoryStatusEx = modkernel32.NewProc("GlobalMemoryStatusEx") 12 | ) 13 | 14 | // https://msdn.microsoft.com/en-us/library/windows/desktop/aa366589(v=vs.85).aspx 15 | // https://msdn.microsoft.com/en-us/library/windows/desktop/aa366770(v=vs.85).aspx 16 | type memorystatusex struct { 17 | dwLength uint32 18 | dwMemoryLoad uint32 19 | ullTotalPhys uint64 20 | ullAvailPhys uint64 21 | ullTotalPageFile uint64 22 | ullAvailPageFile uint64 23 | ullTotalVirtual uint64 24 | ullAvailVirtual uint64 25 | ullAvailExtendedVirtual uint64 26 | } 27 | 28 | // ReadMemInfo retrieves memory statistics of the host system and returns a 29 | // MemInfo type. 30 | func ReadMemInfo() (*MemInfo, error) { 31 | msi := &memorystatusex{ 32 | dwLength: 64, 33 | } 34 | r1, _, _ := procGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(msi))) 35 | if r1 == 0 { 36 | return &MemInfo{}, nil 37 | } 38 | return &MemInfo{ 39 | MemTotal: int64(msi.ullTotalPhys), 40 | MemFree: int64(msi.ullAvailPhys), 41 | SwapTotal: int64(msi.ullTotalPageFile), 42 | SwapFree: int64(msi.ullAvailPageFile), 43 | }, nil 44 | } 45 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/mknod.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package system 4 | 5 | import ( 6 | "syscall" 7 | ) 8 | 9 | // Mknod creates a filesystem node (file, device special file or named pipe) named path 10 | // with attributes specified by mode and dev. 11 | func Mknod(path string, mode uint32, dev int) error { 12 | return syscall.Mknod(path, mode, dev) 13 | } 14 | 15 | // Mkdev is used to build the value of linux devices (in /dev/) which specifies major 16 | // and minor number of the newly created device special file. 17 | // Linux device nodes are a bit weird due to backwards compat with 16 bit device nodes. 18 | // They are, from low to high: the lower 8 bits of the minor, then 12 bits of the major, 19 | // then the top 12 bits of the minor. 20 | func Mkdev(major int64, minor int64) uint32 { 21 | return uint32(((minor & 0xfff00) << 12) | ((major & 0xfff) << 8) | (minor & 0xff)) 22 | } 23 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/mknod_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package system 4 | 5 | // Mknod is not implemented on Windows. 6 | func Mknod(path string, mode uint32, dev int) error { 7 | return ErrNotSupportedPlatform 8 | } 9 | 10 | // Mkdev is not implemented on Windows. 11 | func Mkdev(major int64, minor int64) uint32 { 12 | panic("Mkdev not implemented on Windows.") 13 | } 14 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/path_unix.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package system 4 | 5 | // DefaultPathEnv is unix style list of directories to search for 6 | // executables. Each directory is separated from the next by a colon 7 | // ':' character . 8 | const DefaultPathEnv = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" 9 | 10 | // CheckSystemDriveAndRemoveDriveLetter verifies that a path, if it includes a drive letter, 11 | // is the system drive. This is a no-op on Linux. 12 | func CheckSystemDriveAndRemoveDriveLetter(path string) (string, error) { 13 | return path, nil 14 | } 15 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/path_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package system 4 | 5 | import ( 6 | "fmt" 7 | "path/filepath" 8 | "strings" 9 | ) 10 | 11 | // DefaultPathEnv is deliberately empty on Windows as the default path will be set by 12 | // the container. Docker has no context of what the default path should be. 13 | const DefaultPathEnv = "" 14 | 15 | // CheckSystemDriveAndRemoveDriveLetter verifies and manipulates a Windows path. 16 | // This is used, for example, when validating a user provided path in docker cp. 17 | // If a drive letter is supplied, it must be the system drive. The drive letter 18 | // is always removed. Also, it translates it to OS semantics (IOW / to \). We 19 | // need the path in this syntax so that it can ultimately be contatenated with 20 | // a Windows long-path which doesn't support drive-letters. Examples: 21 | // C: --> Fail 22 | // C:\ --> \ 23 | // a --> a 24 | // /a --> \a 25 | // d:\ --> Fail 26 | func CheckSystemDriveAndRemoveDriveLetter(path string) (string, error) { 27 | if len(path) == 2 && string(path[1]) == ":" { 28 | return "", fmt.Errorf("No relative path specified in %q", path) 29 | } 30 | if !filepath.IsAbs(path) || len(path) < 2 { 31 | return filepath.FromSlash(path), nil 32 | } 33 | if string(path[1]) == ":" && !strings.EqualFold(string(path[0]), "c") { 34 | return "", fmt.Errorf("The specified path is not on the system drive (C:)") 35 | } 36 | return filepath.FromSlash(path[2:]), nil 37 | } 38 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/stat.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package system 4 | 5 | import ( 6 | "syscall" 7 | ) 8 | 9 | // StatT type contains status of a file. It contains metadata 10 | // like permission, owner, group, size, etc about a file. 11 | type StatT struct { 12 | mode uint32 13 | uid uint32 14 | gid uint32 15 | rdev uint64 16 | size int64 17 | mtim syscall.Timespec 18 | } 19 | 20 | // Mode returns file's permission mode. 21 | func (s StatT) Mode() uint32 { 22 | return s.mode 23 | } 24 | 25 | // UID returns file's user id of owner. 26 | func (s StatT) UID() uint32 { 27 | return s.uid 28 | } 29 | 30 | // GID returns file's group id of owner. 31 | func (s StatT) GID() uint32 { 32 | return s.gid 33 | } 34 | 35 | // Rdev returns file's device ID (if it's special file). 36 | func (s StatT) Rdev() uint64 { 37 | return s.rdev 38 | } 39 | 40 | // Size returns file's size. 41 | func (s StatT) Size() int64 { 42 | return s.size 43 | } 44 | 45 | // Mtim returns file's last modification time. 46 | func (s StatT) Mtim() syscall.Timespec { 47 | return s.mtim 48 | } 49 | 50 | // GetLastModification returns file's last modification time. 51 | func (s StatT) GetLastModification() syscall.Timespec { 52 | return s.Mtim() 53 | } 54 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/stat_darwin.go: -------------------------------------------------------------------------------- 1 | package system 2 | 3 | import ( 4 | "syscall" 5 | ) 6 | 7 | // fromStatT creates a system.StatT type from a syscall.Stat_t type 8 | func fromStatT(s *syscall.Stat_t) (*StatT, error) { 9 | return &StatT{size: s.Size, 10 | mode: uint32(s.Mode), 11 | uid: s.Uid, 12 | gid: s.Gid, 13 | rdev: uint64(s.Rdev), 14 | mtim: s.Mtimespec}, nil 15 | } 16 | 17 | // FromStatT loads a system.StatT from a syscall.Stat_t. 18 | func FromStatT(s *syscall.Stat_t) (*StatT, error) { 19 | return fromStatT(s) 20 | } 21 | 22 | // Stat takes a path to a file and returns 23 | // a system.StatT type pertaining to that file. 24 | // 25 | // Throws an error if the file does not exist 26 | func Stat(path string) (*StatT, error) { 27 | s := &syscall.Stat_t{} 28 | if err := syscall.Stat(path, s); err != nil { 29 | return nil, err 30 | } 31 | return fromStatT(s) 32 | } 33 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/stat_freebsd.go: -------------------------------------------------------------------------------- 1 | package system 2 | 3 | import ( 4 | "syscall" 5 | ) 6 | 7 | // fromStatT converts a syscall.Stat_t type to a system.Stat_t type 8 | func fromStatT(s *syscall.Stat_t) (*StatT, error) { 9 | return &StatT{size: s.Size, 10 | mode: uint32(s.Mode), 11 | uid: s.Uid, 12 | gid: s.Gid, 13 | rdev: uint64(s.Rdev), 14 | mtim: s.Mtimespec}, nil 15 | } 16 | 17 | // Stat takes a path to a file and returns 18 | // a system.Stat_t type pertaining to that file. 19 | // 20 | // Throws an error if the file does not exist 21 | func Stat(path string) (*StatT, error) { 22 | s := &syscall.Stat_t{} 23 | if err := syscall.Stat(path, s); err != nil { 24 | return nil, err 25 | } 26 | return fromStatT(s) 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/stat_linux.go: -------------------------------------------------------------------------------- 1 | package system 2 | 3 | import ( 4 | "syscall" 5 | ) 6 | 7 | // fromStatT converts a syscall.Stat_t type to a system.Stat_t type 8 | func fromStatT(s *syscall.Stat_t) (*StatT, error) { 9 | return &StatT{size: s.Size, 10 | mode: s.Mode, 11 | uid: s.Uid, 12 | gid: s.Gid, 13 | rdev: s.Rdev, 14 | mtim: s.Mtim}, nil 15 | } 16 | 17 | // FromStatT exists only on linux, and loads a system.StatT from a 18 | // syscal.Stat_t. 19 | func FromStatT(s *syscall.Stat_t) (*StatT, error) { 20 | return fromStatT(s) 21 | } 22 | 23 | // Stat takes a path to a file and returns 24 | // a system.StatT type pertaining to that file. 25 | // 26 | // Throws an error if the file does not exist 27 | func Stat(path string) (*StatT, error) { 28 | s := &syscall.Stat_t{} 29 | if err := syscall.Stat(path, s); err != nil { 30 | return nil, err 31 | } 32 | return fromStatT(s) 33 | } 34 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/stat_openbsd.go: -------------------------------------------------------------------------------- 1 | package system 2 | 3 | import ( 4 | "syscall" 5 | ) 6 | 7 | // fromStatT creates a system.StatT type from a syscall.Stat_t type 8 | func fromStatT(s *syscall.Stat_t) (*StatT, error) { 9 | return &StatT{size: s.Size, 10 | mode: uint32(s.Mode), 11 | uid: s.Uid, 12 | gid: s.Gid, 13 | rdev: uint64(s.Rdev), 14 | mtim: s.Mtim}, nil 15 | } 16 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/stat_solaris.go: -------------------------------------------------------------------------------- 1 | // +build solaris 2 | 3 | package system 4 | 5 | import ( 6 | "syscall" 7 | ) 8 | 9 | // fromStatT creates a system.StatT type from a syscall.Stat_t type 10 | func fromStatT(s *syscall.Stat_t) (*StatT, error) { 11 | return &StatT{size: s.Size, 12 | mode: uint32(s.Mode), 13 | uid: s.Uid, 14 | gid: s.Gid, 15 | rdev: uint64(s.Rdev), 16 | mtim: s.Mtim}, nil 17 | } 18 | 19 | // FromStatT loads a system.StatT from a syscal.Stat_t. 20 | func FromStatT(s *syscall.Stat_t) (*StatT, error) { 21 | return fromStatT(s) 22 | } 23 | 24 | // Stat takes a path to a file and returns 25 | // a system.StatT type pertaining to that file. 26 | // 27 | // Throws an error if the file does not exist 28 | func Stat(path string) (*StatT, error) { 29 | s := &syscall.Stat_t{} 30 | if err := syscall.Stat(path, s); err != nil { 31 | return nil, err 32 | } 33 | return fromStatT(s) 34 | } 35 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/stat_unsupported.go: -------------------------------------------------------------------------------- 1 | // +build !linux,!windows,!freebsd,!solaris,!openbsd,!darwin 2 | 3 | package system 4 | 5 | import ( 6 | "syscall" 7 | ) 8 | 9 | // fromStatT creates a system.StatT type from a syscall.Stat_t type 10 | func fromStatT(s *syscall.Stat_t) (*StatT, error) { 11 | return &StatT{size: s.Size, 12 | mode: uint32(s.Mode), 13 | uid: s.Uid, 14 | gid: s.Gid, 15 | rdev: uint64(s.Rdev), 16 | mtim: s.Mtimespec}, nil 17 | } 18 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/stat_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package system 4 | 5 | import ( 6 | "os" 7 | "time" 8 | ) 9 | 10 | // StatT type contains status of a file. It contains metadata 11 | // like name, permission, size, etc about a file. 12 | type StatT struct { 13 | name string 14 | size int64 15 | mode os.FileMode 16 | modTime time.Time 17 | isDir bool 18 | } 19 | 20 | // Name returns file's name. 21 | func (s StatT) Name() string { 22 | return s.name 23 | } 24 | 25 | // Size returns file's size. 26 | func (s StatT) Size() int64 { 27 | return s.size 28 | } 29 | 30 | // Mode returns file's permission mode. 31 | func (s StatT) Mode() os.FileMode { 32 | return s.mode 33 | } 34 | 35 | // ModTime returns file's last modification time. 36 | func (s StatT) ModTime() time.Time { 37 | return s.modTime 38 | } 39 | 40 | // IsDir returns whether file is actually a directory. 41 | func (s StatT) IsDir() bool { 42 | return s.isDir 43 | } 44 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/syscall_unix.go: -------------------------------------------------------------------------------- 1 | // +build linux freebsd 2 | 3 | package system 4 | 5 | import "syscall" 6 | 7 | // Unmount is a platform-specific helper function to call 8 | // the unmount syscall. 9 | func Unmount(dest string) error { 10 | return syscall.Unmount(dest, 0) 11 | } 12 | 13 | // CommandLineToArgv should not be used on Unix. 14 | // It simply returns commandLine in the only element in the returned array. 15 | func CommandLineToArgv(commandLine string) ([]string, error) { 16 | return []string{commandLine}, nil 17 | } 18 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/umask.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package system 4 | 5 | import ( 6 | "syscall" 7 | ) 8 | 9 | // Umask sets current process's file mode creation mask to newmask 10 | // and returns oldmask. 11 | func Umask(newmask int) (oldmask int, err error) { 12 | return syscall.Umask(newmask), nil 13 | } 14 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/umask_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package system 4 | 5 | // Umask is not supported on the windows platform. 6 | func Umask(newmask int) (oldmask int, err error) { 7 | // should not be called on cli code path 8 | return 0, ErrNotSupportedPlatform 9 | } 10 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/utimes_freebsd.go: -------------------------------------------------------------------------------- 1 | package system 2 | 3 | import ( 4 | "syscall" 5 | "unsafe" 6 | ) 7 | 8 | // LUtimesNano is used to change access and modification time of the specified path. 9 | // It's used for symbol link file because syscall.UtimesNano doesn't support a NOFOLLOW flag atm. 10 | func LUtimesNano(path string, ts []syscall.Timespec) error { 11 | var _path *byte 12 | _path, err := syscall.BytePtrFromString(path) 13 | if err != nil { 14 | return err 15 | } 16 | 17 | if _, _, err := syscall.Syscall(syscall.SYS_LUTIMES, uintptr(unsafe.Pointer(_path)), uintptr(unsafe.Pointer(&ts[0])), 0); err != 0 && err != syscall.ENOSYS { 18 | return err 19 | } 20 | 21 | return nil 22 | } 23 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/utimes_linux.go: -------------------------------------------------------------------------------- 1 | package system 2 | 3 | import ( 4 | "syscall" 5 | "unsafe" 6 | ) 7 | 8 | // LUtimesNano is used to change access and modification time of the specified path. 9 | // It's used for symbol link file because syscall.UtimesNano doesn't support a NOFOLLOW flag atm. 10 | func LUtimesNano(path string, ts []syscall.Timespec) error { 11 | // These are not currently available in syscall 12 | atFdCwd := -100 13 | atSymLinkNoFollow := 0x100 14 | 15 | var _path *byte 16 | _path, err := syscall.BytePtrFromString(path) 17 | if err != nil { 18 | return err 19 | } 20 | 21 | if _, _, err := syscall.Syscall6(syscall.SYS_UTIMENSAT, uintptr(atFdCwd), uintptr(unsafe.Pointer(_path)), uintptr(unsafe.Pointer(&ts[0])), uintptr(atSymLinkNoFollow), 0, 0); err != 0 && err != syscall.ENOSYS { 22 | return err 23 | } 24 | 25 | return nil 26 | } 27 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/utimes_unsupported.go: -------------------------------------------------------------------------------- 1 | // +build !linux,!freebsd 2 | 3 | package system 4 | 5 | import "syscall" 6 | 7 | // LUtimesNano is only supported on linux and freebsd. 8 | func LUtimesNano(path string, ts []syscall.Timespec) error { 9 | return ErrNotSupportedPlatform 10 | } 11 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/xattrs_linux.go: -------------------------------------------------------------------------------- 1 | package system 2 | 3 | import ( 4 | "syscall" 5 | "unsafe" 6 | ) 7 | 8 | // Lgetxattr retrieves the value of the extended attribute identified by attr 9 | // and associated with the given path in the file system. 10 | // It will returns a nil slice and nil error if the xattr is not set. 11 | func Lgetxattr(path string, attr string) ([]byte, error) { 12 | pathBytes, err := syscall.BytePtrFromString(path) 13 | if err != nil { 14 | return nil, err 15 | } 16 | attrBytes, err := syscall.BytePtrFromString(attr) 17 | if err != nil { 18 | return nil, err 19 | } 20 | 21 | dest := make([]byte, 128) 22 | destBytes := unsafe.Pointer(&dest[0]) 23 | sz, _, errno := syscall.Syscall6(syscall.SYS_LGETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(destBytes), uintptr(len(dest)), 0, 0) 24 | if errno == syscall.ENODATA { 25 | return nil, nil 26 | } 27 | if errno == syscall.ERANGE { 28 | dest = make([]byte, sz) 29 | destBytes := unsafe.Pointer(&dest[0]) 30 | sz, _, errno = syscall.Syscall6(syscall.SYS_LGETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(destBytes), uintptr(len(dest)), 0, 0) 31 | } 32 | if errno != 0 { 33 | return nil, errno 34 | } 35 | 36 | return dest[:sz], nil 37 | } 38 | 39 | var _zero uintptr 40 | 41 | // Lsetxattr sets the value of the extended attribute identified by attr 42 | // and associated with the given path in the file system. 43 | func Lsetxattr(path string, attr string, data []byte, flags int) error { 44 | pathBytes, err := syscall.BytePtrFromString(path) 45 | if err != nil { 46 | return err 47 | } 48 | attrBytes, err := syscall.BytePtrFromString(attr) 49 | if err != nil { 50 | return err 51 | } 52 | var dataBytes unsafe.Pointer 53 | if len(data) > 0 { 54 | dataBytes = unsafe.Pointer(&data[0]) 55 | } else { 56 | dataBytes = unsafe.Pointer(&_zero) 57 | } 58 | _, _, errno := syscall.Syscall6(syscall.SYS_LSETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(dataBytes), uintptr(len(data)), uintptr(flags), 0) 59 | if errno != 0 { 60 | return errno 61 | } 62 | return nil 63 | } 64 | -------------------------------------------------------------------------------- /vendor/github.com/docker/docker/pkg/system/xattrs_unsupported.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package system 4 | 5 | // Lgetxattr is not supported on platforms other than linux. 6 | func Lgetxattr(path string, attr string) ([]byte, error) { 7 | return nil, ErrNotSupportedPlatform 8 | } 9 | 10 | // Lsetxattr is not supported on platforms other than linux. 11 | func Lsetxattr(path string, attr string, data []byte, flags int) error { 12 | return ErrNotSupportedPlatform 13 | } 14 | -------------------------------------------------------------------------------- /vendor/github.com/docker/engine-api/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Package engineapi provides libraries to implement client and server components compatible with the Docker engine. 3 | 4 | The client package in github.com/docker/engine-api/client implements all necessary requests to implement the official Docker engine cli. 5 | 6 | Create a new client, then use it to send and receive messages to the Docker engine API: 7 | 8 | defaultHeaders := map[string]string{"User-Agent": "engine-api-cli-1.0"} 9 | cli, err := client.NewClient("unix:///var/run/docker.sock", "v1.22", nil, defaultHeaders) 10 | 11 | Other programs, like Docker Machine, can set the default Docker engine environment for you. There is a shortcut to use its variables to configure the client: 12 | 13 | cli, err := client.NewEnvClient() 14 | 15 | All request arguments are defined as typed structures in the types package. For instance, this is how to get all containers running in the host: 16 | 17 | options := types.ContainerListOptions{All: true} 18 | containers, err := cli.ContainerList(context.Background(), options) 19 | 20 | */ 21 | package engineapi 22 | -------------------------------------------------------------------------------- /vendor/github.com/docker/engine-api/types/mount/mount.go: -------------------------------------------------------------------------------- 1 | package mount 2 | 3 | // Type represents the type of a mount. 4 | type Type string 5 | 6 | const ( 7 | // TypeBind BIND 8 | TypeBind Type = "bind" 9 | // TypeVolume VOLUME 10 | TypeVolume Type = "volume" 11 | ) 12 | 13 | // Mount represents a mount (volume). 14 | type Mount struct { 15 | Type Type `json:",omitempty"` 16 | Source string `json:",omitempty"` 17 | Target string `json:",omitempty"` 18 | ReadOnly bool `json:",omitempty"` 19 | 20 | BindOptions *BindOptions `json:",omitempty"` 21 | VolumeOptions *VolumeOptions `json:",omitempty"` 22 | } 23 | 24 | // Propagation represents the propagation of a mount. 25 | type Propagation string 26 | 27 | const ( 28 | // PropagationRPrivate RPRIVATE 29 | PropagationRPrivate Propagation = "rprivate" 30 | // PropagationPrivate PRIVATE 31 | PropagationPrivate Propagation = "private" 32 | // PropagationRShared RSHARED 33 | PropagationRShared Propagation = "rshared" 34 | // PropagationShared SHARED 35 | PropagationShared Propagation = "shared" 36 | // PropagationRSlave RSLAVE 37 | PropagationRSlave Propagation = "rslave" 38 | // PropagationSlave SLAVE 39 | PropagationSlave Propagation = "slave" 40 | ) 41 | 42 | // BindOptions defines options specific to mounts of type "bind". 43 | type BindOptions struct { 44 | Propagation Propagation `json:",omitempty"` 45 | } 46 | 47 | // VolumeOptions represents the options for a mount of type volume. 48 | type VolumeOptions struct { 49 | NoCopy bool `json:",omitempty"` 50 | Labels map[string]string `json:",omitempty"` 51 | DriverConfig *Driver `json:",omitempty"` 52 | } 53 | 54 | // Driver represents a volume driver. 55 | type Driver struct { 56 | Name string `json:",omitempty"` 57 | Options map[string]string `json:",omitempty"` 58 | } 59 | -------------------------------------------------------------------------------- /vendor/github.com/docker/engine-api/types/swarm/common.go: -------------------------------------------------------------------------------- 1 | package swarm 2 | 3 | import "time" 4 | 5 | // Version represent the internal object version. 6 | type Version struct { 7 | Index uint64 `json:",omitempty"` 8 | } 9 | 10 | // Meta is base object inherited by most of the other once. 11 | type Meta struct { 12 | Version Version `json:",omitempty"` 13 | CreatedAt time.Time `json:",omitempty"` 14 | UpdatedAt time.Time `json:",omitempty"` 15 | } 16 | 17 | // Annotations represents how to describe an object. 18 | type Annotations struct { 19 | Name string `json:",omitempty"` 20 | Labels map[string]string `json:",omitempty"` 21 | } 22 | -------------------------------------------------------------------------------- /vendor/github.com/docker/engine-api/types/swarm/container.go: -------------------------------------------------------------------------------- 1 | package swarm 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/docker/engine-api/types/mount" 7 | ) 8 | 9 | // ContainerSpec represents the spec of a container. 10 | type ContainerSpec struct { 11 | Image string `json:",omitempty"` 12 | Labels map[string]string `json:",omitempty"` 13 | Command []string `json:",omitempty"` 14 | Args []string `json:",omitempty"` 15 | Env []string `json:",omitempty"` 16 | Dir string `json:",omitempty"` 17 | User string `json:",omitempty"` 18 | Groups []string `json:",omitempty"` 19 | TTY bool `json:",omitempty"` 20 | Mounts []mount.Mount `json:",omitempty"` 21 | StopGracePeriod *time.Duration `json:",omitempty"` 22 | } 23 | -------------------------------------------------------------------------------- /vendor/github.com/docker/engine-api/types/swarm/service.go: -------------------------------------------------------------------------------- 1 | package swarm 2 | 3 | import "time" 4 | 5 | // Service represents a service. 6 | type Service struct { 7 | ID string 8 | Meta 9 | Spec ServiceSpec `json:",omitempty"` 10 | Endpoint Endpoint `json:",omitempty"` 11 | UpdateStatus UpdateStatus `json:",omitempty"` 12 | } 13 | 14 | // ServiceSpec represents the spec of a service. 15 | type ServiceSpec struct { 16 | Annotations 17 | 18 | // TaskTemplate defines how the service should construct new tasks when 19 | // orchestrating this service. 20 | TaskTemplate TaskSpec `json:",omitempty"` 21 | Mode ServiceMode `json:",omitempty"` 22 | UpdateConfig *UpdateConfig `json:",omitempty"` 23 | 24 | // Networks field in ServiceSpec is being deprecated. Users of 25 | // engine-api should start using the same field in 26 | // TaskSpec. This field will be removed in future releases. 27 | Networks []NetworkAttachmentConfig `json:",omitempty"` 28 | EndpointSpec *EndpointSpec `json:",omitempty"` 29 | } 30 | 31 | // ServiceMode represents the mode of a service. 32 | type ServiceMode struct { 33 | Replicated *ReplicatedService `json:",omitempty"` 34 | Global *GlobalService `json:",omitempty"` 35 | } 36 | 37 | // UpdateState is the state of a service update. 38 | type UpdateState string 39 | 40 | const ( 41 | // UpdateStateUpdating is the updating state. 42 | UpdateStateUpdating UpdateState = "updating" 43 | // UpdateStatePaused is the paused state. 44 | UpdateStatePaused UpdateState = "paused" 45 | // UpdateStateCompleted is the completed state. 46 | UpdateStateCompleted UpdateState = "completed" 47 | ) 48 | 49 | // UpdateStatus reports the status of a service update. 50 | type UpdateStatus struct { 51 | State UpdateState `json:",omitempty"` 52 | StartedAt time.Time `json:",omitempty"` 53 | CompletedAt time.Time `json:",omitempty"` 54 | Message string `json:",omitempty"` 55 | } 56 | 57 | // ReplicatedService is a kind of ServiceMode. 58 | type ReplicatedService struct { 59 | Replicas *uint64 `json:",omitempty"` 60 | } 61 | 62 | // GlobalService is a kind of ServiceMode. 63 | type GlobalService struct{} 64 | 65 | const ( 66 | // UpdateFailureActionPause PAUSE 67 | UpdateFailureActionPause = "pause" 68 | // UpdateFailureActionContinue CONTINUE 69 | UpdateFailureActionContinue = "continue" 70 | ) 71 | 72 | // UpdateConfig represents the update configuration. 73 | type UpdateConfig struct { 74 | Parallelism uint64 `json:",omitempty"` 75 | Delay time.Duration `json:",omitempty"` 76 | FailureAction string `json:",omitempty"` 77 | } 78 | -------------------------------------------------------------------------------- /vendor/github.com/docker/go-units/duration.go: -------------------------------------------------------------------------------- 1 | // Package units provides helper function to parse and print size and time units 2 | // in human-readable format. 3 | package units 4 | 5 | import ( 6 | "fmt" 7 | "time" 8 | ) 9 | 10 | // HumanDuration returns a human-readable approximation of a duration 11 | // (eg. "About a minute", "4 hours ago", etc.). 12 | func HumanDuration(d time.Duration) string { 13 | if seconds := int(d.Seconds()); seconds < 1 { 14 | return "Less than a second" 15 | } else if seconds == 1 { 16 | return "1 second" 17 | } else if seconds < 60 { 18 | return fmt.Sprintf("%d seconds", seconds) 19 | } else if minutes := int(d.Minutes()); minutes == 1 { 20 | return "About a minute" 21 | } else if minutes < 60 { 22 | return fmt.Sprintf("%d minutes", minutes) 23 | } else if hours := int(d.Hours()); hours == 1 { 24 | return "About an hour" 25 | } else if hours < 48 { 26 | return fmt.Sprintf("%d hours", hours) 27 | } else if hours < 24*7*2 { 28 | return fmt.Sprintf("%d days", hours/24) 29 | } else if hours < 24*30*3 { 30 | return fmt.Sprintf("%d weeks", hours/24/7) 31 | } else if hours < 24*365*2 { 32 | return fmt.Sprintf("%d months", hours/24/30) 33 | } 34 | return fmt.Sprintf("%d years", int(d.Hours())/24/365) 35 | } 36 | -------------------------------------------------------------------------------- /vendor/github.com/fsouza/go-dockerclient/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2016, go-dockerclient authors 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 17 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 20 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 21 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | -------------------------------------------------------------------------------- /vendor/github.com/fsouza/go-dockerclient/change.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 go-dockerclient authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package docker 6 | 7 | import "fmt" 8 | 9 | // ChangeType is a type for constants indicating the type of change 10 | // in a container 11 | type ChangeType int 12 | 13 | const ( 14 | // ChangeModify is the ChangeType for container modifications 15 | ChangeModify ChangeType = iota 16 | 17 | // ChangeAdd is the ChangeType for additions to a container 18 | ChangeAdd 19 | 20 | // ChangeDelete is the ChangeType for deletions from a container 21 | ChangeDelete 22 | ) 23 | 24 | // Change represents a change in a container. 25 | // 26 | // See https://goo.gl/9GsTIF for more details. 27 | type Change struct { 28 | Path string 29 | Kind ChangeType 30 | } 31 | 32 | func (change *Change) String() string { 33 | var kind string 34 | switch change.Kind { 35 | case ChangeModify: 36 | kind = "C" 37 | case ChangeAdd: 38 | kind = "A" 39 | case ChangeDelete: 40 | kind = "D" 41 | } 42 | return fmt.Sprintf("%s %s", kind, change.Path) 43 | } 44 | -------------------------------------------------------------------------------- /vendor/github.com/fsouza/go-dockerclient/client_unix.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | // Copyright 2016 go-dockerclient authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style 4 | // license that can be found in the LICENSE file. 5 | 6 | // Package docker provides a client for the Docker remote API. 7 | // 8 | // See https://goo.gl/G3plxW for more details on the remote API. 9 | package docker 10 | 11 | import ( 12 | "net" 13 | "net/http" 14 | 15 | "github.com/hashicorp/go-cleanhttp" 16 | ) 17 | 18 | // initializeNativeClient initializes the native Unix domain socket client on 19 | // Unix-style operating systems 20 | func (c *Client) initializeNativeClient() { 21 | if c.endpointURL.Scheme != unixProtocol { 22 | return 23 | } 24 | socketPath := c.endpointURL.Path 25 | tr := cleanhttp.DefaultTransport() 26 | tr.Dial = func(network, addr string) (net.Conn, error) { 27 | return c.Dialer.Dial(unixProtocol, socketPath) 28 | } 29 | c.nativeHTTPClient = &http.Client{Transport: tr} 30 | } 31 | -------------------------------------------------------------------------------- /vendor/github.com/fsouza/go-dockerclient/client_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | // Copyright 2016 go-dockerclient authors. All rights reserved. 3 | // Use of this source code is governed by a BSD-style 4 | // license that can be found in the LICENSE file. 5 | 6 | // Package docker provides a client for the Docker remote API. 7 | // 8 | // See https://goo.gl/G3plxW for more details on the remote API. 9 | package docker 10 | 11 | import ( 12 | "net" 13 | "net/http" 14 | "time" 15 | 16 | "github.com/Microsoft/go-winio" 17 | "github.com/hashicorp/go-cleanhttp" 18 | ) 19 | 20 | const namedPipeConnectTimeout = 2 * time.Second 21 | 22 | type pipeDialer struct { 23 | dialFunc func(network, addr string) (net.Conn, error) 24 | } 25 | 26 | func (p pipeDialer) Dial(network, address string) (net.Conn, error) { 27 | return p.dialFunc(network, address) 28 | } 29 | 30 | // initializeNativeClient initializes the native Named Pipe client for Windows 31 | func (c *Client) initializeNativeClient() { 32 | if c.endpointURL.Scheme != namedPipeProtocol { 33 | return 34 | } 35 | namedPipePath := c.endpointURL.Path 36 | dialFunc := func(network, addr string) (net.Conn, error) { 37 | timeout := namedPipeConnectTimeout 38 | return winio.DialPipe(namedPipePath, &timeout) 39 | } 40 | tr := cleanhttp.DefaultTransport() 41 | tr.Dial = dialFunc 42 | c.Dialer = &pipeDialer{dialFunc} 43 | c.nativeHTTPClient = &http.Client{Transport: tr} 44 | } 45 | -------------------------------------------------------------------------------- /vendor/github.com/fsouza/go-dockerclient/signal.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 go-dockerclient authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package docker 6 | 7 | // Signal represents a signal that can be send to the container on 8 | // KillContainer call. 9 | type Signal int 10 | 11 | // These values represent all signals available on Linux, where containers will 12 | // be running. 13 | const ( 14 | SIGABRT = Signal(0x6) 15 | SIGALRM = Signal(0xe) 16 | SIGBUS = Signal(0x7) 17 | SIGCHLD = Signal(0x11) 18 | SIGCLD = Signal(0x11) 19 | SIGCONT = Signal(0x12) 20 | SIGFPE = Signal(0x8) 21 | SIGHUP = Signal(0x1) 22 | SIGILL = Signal(0x4) 23 | SIGINT = Signal(0x2) 24 | SIGIO = Signal(0x1d) 25 | SIGIOT = Signal(0x6) 26 | SIGKILL = Signal(0x9) 27 | SIGPIPE = Signal(0xd) 28 | SIGPOLL = Signal(0x1d) 29 | SIGPROF = Signal(0x1b) 30 | SIGPWR = Signal(0x1e) 31 | SIGQUIT = Signal(0x3) 32 | SIGSEGV = Signal(0xb) 33 | SIGSTKFLT = Signal(0x10) 34 | SIGSTOP = Signal(0x13) 35 | SIGSYS = Signal(0x1f) 36 | SIGTERM = Signal(0xf) 37 | SIGTRAP = Signal(0x5) 38 | SIGTSTP = Signal(0x14) 39 | SIGTTIN = Signal(0x15) 40 | SIGTTOU = Signal(0x16) 41 | SIGUNUSED = Signal(0x1f) 42 | SIGURG = Signal(0x17) 43 | SIGUSR1 = Signal(0xa) 44 | SIGUSR2 = Signal(0xc) 45 | SIGVTALRM = Signal(0x1a) 46 | SIGWINCH = Signal(0x1c) 47 | SIGXCPU = Signal(0x18) 48 | SIGXFSZ = Signal(0x19) 49 | ) 50 | -------------------------------------------------------------------------------- /vendor/github.com/fsouza/go-dockerclient/task.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 go-dockerclient authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package docker 6 | 7 | import ( 8 | "encoding/json" 9 | "net/http" 10 | 11 | "github.com/docker/engine-api/types/swarm" 12 | "golang.org/x/net/context" 13 | ) 14 | 15 | // NoSuchTask is the error returned when a given task does not exist. 16 | type NoSuchTask struct { 17 | ID string 18 | Err error 19 | } 20 | 21 | func (err *NoSuchTask) Error() string { 22 | if err.Err != nil { 23 | return err.Err.Error() 24 | } 25 | return "No such task: " + err.ID 26 | } 27 | 28 | // ListTasksOptions specify parameters to the ListTasks function. 29 | // 30 | // See http://goo.gl/rByLzw for more details. 31 | type ListTasksOptions struct { 32 | Filters map[string][]string 33 | Context context.Context 34 | } 35 | 36 | // ListTasks returns a slice of tasks matching the given criteria. 37 | // 38 | // See http://goo.gl/rByLzw for more details. 39 | func (c *Client) ListTasks(opts ListTasksOptions) ([]swarm.Task, error) { 40 | path := "/tasks?" + queryString(opts) 41 | resp, err := c.do("GET", path, doOptions{context: opts.Context}) 42 | if err != nil { 43 | return nil, err 44 | } 45 | defer resp.Body.Close() 46 | var tasks []swarm.Task 47 | if err := json.NewDecoder(resp.Body).Decode(&tasks); err != nil { 48 | return nil, err 49 | } 50 | return tasks, nil 51 | } 52 | 53 | // InspectTask returns information about a task by its ID. 54 | // 55 | // See http://goo.gl/kyziuq for more details. 56 | func (c *Client) InspectTask(id string) (*swarm.Task, error) { 57 | resp, err := c.do("GET", "/tasks/"+id, doOptions{}) 58 | if err != nil { 59 | if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound { 60 | return nil, &NoSuchTask{ID: id} 61 | } 62 | return nil, err 63 | } 64 | defer resp.Body.Close() 65 | var task swarm.Task 66 | if err := json.NewDecoder(resp.Body).Decode(&task); err != nil { 67 | return nil, err 68 | } 69 | return &task, nil 70 | } 71 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-cleanhttp/cleanhttp.go: -------------------------------------------------------------------------------- 1 | package cleanhttp 2 | 3 | import ( 4 | "net" 5 | "net/http" 6 | "time" 7 | ) 8 | 9 | // DefaultTransport returns a new http.Transport with the same default values 10 | // as http.DefaultTransport, but with idle connections and keepalives disabled. 11 | func DefaultTransport() *http.Transport { 12 | transport := DefaultPooledTransport() 13 | transport.DisableKeepAlives = true 14 | transport.MaxIdleConnsPerHost = -1 15 | return transport 16 | } 17 | 18 | // DefaultPooledTransport returns a new http.Transport with similar default 19 | // values to http.DefaultTransport. Do not use this for transient transports as 20 | // it can leak file descriptors over time. Only use this for transports that 21 | // will be re-used for the same host(s). 22 | func DefaultPooledTransport() *http.Transport { 23 | transport := &http.Transport{ 24 | Proxy: http.ProxyFromEnvironment, 25 | Dial: (&net.Dialer{ 26 | Timeout: 30 * time.Second, 27 | KeepAlive: 30 * time.Second, 28 | }).Dial, 29 | TLSHandshakeTimeout: 10 * time.Second, 30 | DisableKeepAlives: false, 31 | MaxIdleConnsPerHost: 1, 32 | } 33 | return transport 34 | } 35 | 36 | // DefaultClient returns a new http.Client with similar default values to 37 | // http.Client, but with a non-shared Transport, idle connections disabled, and 38 | // keepalives disabled. 39 | func DefaultClient() *http.Client { 40 | return &http.Client{ 41 | Transport: DefaultTransport(), 42 | } 43 | } 44 | 45 | // DefaultPooledClient returns a new http.Client with the same default values 46 | // as http.Client, but with a shared Transport. Do not use this function 47 | // for transient clients as it can leak file descriptors over time. Only use 48 | // this for clients that will be re-used for the same host(s). 49 | func DefaultPooledClient() *http.Client { 50 | return &http.Client{ 51 | Transport: DefaultPooledTransport(), 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-cleanhttp/doc.go: -------------------------------------------------------------------------------- 1 | // Package cleanhttp offers convenience utilities for acquiring "clean" 2 | // http.Transport and http.Client structs. 3 | // 4 | // Values set on http.DefaultClient and http.DefaultTransport affect all 5 | // callers. This can have detrimental effects, esepcially in TLS contexts, 6 | // where client or root certificates set to talk to multiple endpoints can end 7 | // up displacing each other, leading to hard-to-debug issues. This package 8 | // provides non-shared http.Client and http.Transport structs to ensure that 9 | // the configuration will not be overwritten by other parts of the application 10 | // or dependencies. 11 | // 12 | // The DefaultClient and DefaultTransport functions disable idle connections 13 | // and keepalives. Without ensuring that idle connections are closed before 14 | // garbage collection, short-term clients/transports can leak file descriptors, 15 | // eventually leading to "too many open files" errors. If you will be 16 | // connecting to the same hosts repeatedly from the same client, you can use 17 | // DefaultPooledClient to receive a client that has connection pooling 18 | // semantics similar to http.DefaultClient. 19 | // 20 | package cleanhttp 21 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/NOTICE: -------------------------------------------------------------------------------- 1 | runc 2 | 3 | Copyright 2012-2015 Docker, Inc. 4 | 5 | This product includes software developed at Docker, Inc. (http://www.docker.com). 6 | 7 | The following is courtesy of our legal counsel: 8 | 9 | 10 | Use and transfer of Docker may be subject to certain restrictions by the 11 | United States and other governments. 12 | It is your responsibility to ensure that your use and/or transfer does not 13 | violate applicable laws. 14 | 15 | For more information, please see http://www.bis.doc.gov 16 | 17 | See also http://www.apache.org/dev/crypto.html and/or seek legal counsel. 18 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/create.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | 6 | "github.com/urfave/cli" 7 | ) 8 | 9 | var createCommand = cli.Command{ 10 | Name: "create", 11 | Usage: "create a container", 12 | ArgsUsage: ` 13 | 14 | Where "" is your name for the instance of the container that you 15 | are starting. The name you provide for the container instance must be unique on 16 | your host.`, 17 | Description: `The create command creates an instance of a container for a bundle. The bundle 18 | is a directory with a specification file named "` + specConfig + `" and a root 19 | filesystem. 20 | 21 | The specification file includes an args parameter. The args parameter is used 22 | to specify command(s) that get run when the container is started. To change the 23 | command(s) that get executed on start, edit the args parameter of the spec. See 24 | "runc spec --help" for more explanation.`, 25 | Flags: []cli.Flag{ 26 | cli.StringFlag{ 27 | Name: "bundle, b", 28 | Value: "", 29 | Usage: `path to the root of the bundle directory, defaults to the current directory`, 30 | }, 31 | cli.StringFlag{ 32 | Name: "console", 33 | Value: "", 34 | Usage: "specify the pty slave path for use with the container", 35 | }, 36 | cli.StringFlag{ 37 | Name: "pid-file", 38 | Value: "", 39 | Usage: "specify the file to write the process id to", 40 | }, 41 | cli.BoolFlag{ 42 | Name: "no-pivot", 43 | Usage: "do not use pivot root to jail process inside rootfs. This should be used whenever the rootfs is on top of a ramdisk", 44 | }, 45 | cli.BoolFlag{ 46 | Name: "no-new-keyring", 47 | Usage: "do not create a new session keyring for the container. This will cause the container to inherit the calling processes session key", 48 | }, 49 | }, 50 | Action: func(context *cli.Context) error { 51 | spec, err := setupSpec(context) 52 | if err != nil { 53 | return err 54 | } 55 | status, err := startContainer(context, spec, true) 56 | if err != nil { 57 | return err 58 | } 59 | // exit with the container's exit status so any external supervisor is 60 | // notified of the exit with the correct exit status. 61 | os.Exit(status) 62 | return nil 63 | }, 64 | } 65 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/libcontainer/system/proc.go: -------------------------------------------------------------------------------- 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 | 18 | parts := strings.Split(string(data), " ") 19 | // the starttime is located at pos 22 20 | // from the man page 21 | // 22 | // starttime %llu (was %lu before Linux 2.6) 23 | // (22) The time the process started after system boot. In kernels before Linux 2.6, this 24 | // value was expressed in jiffies. Since Linux 2.6, the value is expressed in clock ticks 25 | // (divide by sysconf(_SC_CLK_TCK)). 26 | return parts[22-1], nil // starts at 1 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/libcontainer/system/setns_linux.go: -------------------------------------------------------------------------------- 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/386": 346, 15 | "linux/arm64": 268, 16 | "linux/amd64": 308, 17 | "linux/arm": 375, 18 | "linux/ppc": 350, 19 | "linux/ppc64": 350, 20 | "linux/ppc64le": 350, 21 | "linux/s390x": 339, 22 | } 23 | 24 | var sysSetns = setNsMap[fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)] 25 | 26 | func SysSetns() uint32 { 27 | return uint32(sysSetns) 28 | } 29 | 30 | func Setns(fd uintptr, flags uintptr) error { 31 | ns, exists := setNsMap[fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)] 32 | if !exists { 33 | return fmt.Errorf("unsupported platform %s/%s", runtime.GOOS, runtime.GOARCH) 34 | } 35 | _, _, err := syscall.RawSyscall(ns, fd, flags, 0) 36 | if err != 0 { 37 | return err 38 | } 39 | return nil 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/libcontainer/system/syscall_linux_386.go: -------------------------------------------------------------------------------- 1 | // +build linux,386 2 | 3 | package system 4 | 5 | import ( 6 | "syscall" 7 | ) 8 | 9 | // Setuid sets the uid of the calling thread to the specified uid. 10 | func Setuid(uid int) (err error) { 11 | _, _, e1 := syscall.RawSyscall(syscall.SYS_SETUID32, uintptr(uid), 0, 0) 12 | if e1 != 0 { 13 | err = e1 14 | } 15 | return 16 | } 17 | 18 | // Setgid sets the gid of the calling thread to the specified gid. 19 | func Setgid(gid int) (err error) { 20 | _, _, e1 := syscall.RawSyscall(syscall.SYS_SETGID32, uintptr(gid), 0, 0) 21 | if e1 != 0 { 22 | err = e1 23 | } 24 | return 25 | } 26 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/libcontainer/system/syscall_linux_64.go: -------------------------------------------------------------------------------- 1 | // +build linux,arm64 linux,amd64 linux,ppc linux,ppc64 linux,ppc64le linux,s390x 2 | 3 | package system 4 | 5 | import ( 6 | "syscall" 7 | ) 8 | 9 | // Setuid sets the uid of the calling thread to the specified uid. 10 | func Setuid(uid int) (err error) { 11 | _, _, e1 := syscall.RawSyscall(syscall.SYS_SETUID, uintptr(uid), 0, 0) 12 | if e1 != 0 { 13 | err = e1 14 | } 15 | return 16 | } 17 | 18 | // Setgid sets the gid of the calling thread to the specified gid. 19 | func Setgid(gid int) (err error) { 20 | _, _, e1 := syscall.RawSyscall(syscall.SYS_SETGID, uintptr(gid), 0, 0) 21 | if e1 != 0 { 22 | err = e1 23 | } 24 | return 25 | } 26 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/libcontainer/system/syscall_linux_arm.go: -------------------------------------------------------------------------------- 1 | // +build linux,arm 2 | 3 | package system 4 | 5 | import ( 6 | "syscall" 7 | ) 8 | 9 | // Setuid sets the uid of the calling thread to the specified uid. 10 | func Setuid(uid int) (err error) { 11 | _, _, e1 := syscall.RawSyscall(syscall.SYS_SETUID32, uintptr(uid), 0, 0) 12 | if e1 != 0 { 13 | err = e1 14 | } 15 | return 16 | } 17 | 18 | // Setgid sets the gid of the calling thread to the specified gid. 19 | func Setgid(gid int) (err error) { 20 | _, _, e1 := syscall.RawSyscall(syscall.SYS_SETGID32, uintptr(gid), 0, 0) 21 | if e1 != 0 { 22 | err = e1 23 | } 24 | return 25 | } 26 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/libcontainer/system/sysconfig.go: -------------------------------------------------------------------------------- 1 | // +build cgo,linux cgo,freebsd 2 | 3 | package system 4 | 5 | /* 6 | #include 7 | */ 8 | import "C" 9 | 10 | func GetClockTicks() int { 11 | return int(C.sysconf(C._SC_CLK_TCK)) 12 | } 13 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/libcontainer/system/sysconfig_notcgo.go: -------------------------------------------------------------------------------- 1 | // +build !cgo windows 2 | 3 | package system 4 | 5 | func GetClockTicks() int { 6 | // TODO figure out a better alternative for platforms where we're missing cgo 7 | // 8 | // TODO Windows. This could be implemented using Win32 QueryPerformanceFrequency(). 9 | // https://msdn.microsoft.com/en-us/library/windows/desktop/ms644905(v=vs.85).aspx 10 | // 11 | // An example of its usage can be found here. 12 | // https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx 13 | 14 | return 100 15 | } 16 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/libcontainer/system/unsupported.go: -------------------------------------------------------------------------------- 1 | // +build !linux 2 | 3 | package system 4 | 5 | // RunningInUserNS is a stub for non-Linux systems 6 | // Always returns false 7 | func RunningInUserNS() bool { 8 | return false 9 | } 10 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/libcontainer/user/lookup_unix.go: -------------------------------------------------------------------------------- 1 | // +build darwin dragonfly freebsd linux netbsd openbsd solaris 2 | 3 | package user 4 | 5 | import ( 6 | "io" 7 | "os" 8 | ) 9 | 10 | // Unix-specific path to the passwd and group formatted files. 11 | const ( 12 | unixPasswdPath = "/etc/passwd" 13 | unixGroupPath = "/etc/group" 14 | ) 15 | 16 | func GetPasswdPath() (string, error) { 17 | return unixPasswdPath, nil 18 | } 19 | 20 | func GetPasswd() (io.ReadCloser, error) { 21 | return os.Open(unixPasswdPath) 22 | } 23 | 24 | func GetGroupPath() (string, error) { 25 | return unixGroupPath, nil 26 | } 27 | 28 | func GetGroup() (io.ReadCloser, error) { 29 | return os.Open(unixGroupPath) 30 | } 31 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/libcontainer/user/lookup_unsupported.go: -------------------------------------------------------------------------------- 1 | // +build !darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris 2 | 3 | package user 4 | 5 | import "io" 6 | 7 | func GetPasswdPath() (string, error) { 8 | return "", ErrUnsupported 9 | } 10 | 11 | func GetPasswd() (io.ReadCloser, error) { 12 | return nil, ErrUnsupported 13 | } 14 | 15 | func GetGroupPath() (string, error) { 16 | return "", ErrUnsupported 17 | } 18 | 19 | func GetGroup() (io.ReadCloser, error) { 20 | return nil, ErrUnsupported 21 | } 22 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/main_solaris.go: -------------------------------------------------------------------------------- 1 | // +build solaris 2 | 3 | package main 4 | 5 | import "github.com/urfave/cli" 6 | 7 | var ( 8 | checkpointCommand cli.Command 9 | eventsCommand cli.Command 10 | restoreCommand cli.Command 11 | specCommand cli.Command 12 | killCommand cli.Command 13 | deleteCommand cli.Command 14 | execCommand cli.Command 15 | initCommand cli.Command 16 | listCommand cli.Command 17 | pauseCommand cli.Command 18 | resumeCommand cli.Command 19 | startCommand cli.Command 20 | stateCommand cli.Command 21 | ) 22 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/main_unix.go: -------------------------------------------------------------------------------- 1 | // +build linux 2 | 3 | package main 4 | 5 | import ( 6 | "os" 7 | "runtime" 8 | 9 | "github.com/opencontainers/runc/libcontainer" 10 | _ "github.com/opencontainers/runc/libcontainer/nsenter" 11 | "github.com/urfave/cli" 12 | ) 13 | 14 | func init() { 15 | if len(os.Args) > 1 && os.Args[1] == "init" { 16 | runtime.GOMAXPROCS(1) 17 | runtime.LockOSThread() 18 | } 19 | } 20 | 21 | var initCommand = cli.Command{ 22 | Name: "init", 23 | Usage: `initialize the namespaces and launch the process (do not call it outside of runc)`, 24 | Action: func(context *cli.Context) error { 25 | factory, _ := libcontainer.New("") 26 | if err := factory.StartInitialization(); err != nil { 27 | // as the error is sent back to the parent there is no need to log 28 | // or write it to stderr because the parent process will handle this 29 | os.Exit(1) 30 | } 31 | panic("libcontainer: container init failed to exec") 32 | }, 33 | } 34 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/main_unsupported.go: -------------------------------------------------------------------------------- 1 | // +build !linux,!solaris 2 | 3 | package main 4 | 5 | import "github.com/urfave/cli" 6 | 7 | var ( 8 | checkpointCommand cli.Command 9 | eventsCommand cli.Command 10 | restoreCommand cli.Command 11 | specCommand cli.Command 12 | killCommand cli.Command 13 | ) 14 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/pause.go: -------------------------------------------------------------------------------- 1 | // +build linux 2 | 3 | package main 4 | 5 | import "github.com/urfave/cli" 6 | 7 | var pauseCommand = cli.Command{ 8 | Name: "pause", 9 | Usage: "pause suspends all processes inside the container", 10 | ArgsUsage: ` 11 | 12 | Where "" is the name for the instance of the container to be 13 | paused. `, 14 | Description: `The pause command suspends all processes in the instance of the container. 15 | 16 | Use runc list to identiy instances of containers and their current status.`, 17 | Action: func(context *cli.Context) error { 18 | container, err := getContainer(context) 19 | if err != nil { 20 | return err 21 | } 22 | if err := container.Pause(); err != nil { 23 | return err 24 | } 25 | return nil 26 | }, 27 | } 28 | 29 | var resumeCommand = cli.Command{ 30 | Name: "resume", 31 | Usage: "resumes all processes that have been previously paused", 32 | ArgsUsage: ` 33 | 34 | Where "" is the name for the instance of the container to be 35 | resumed.`, 36 | Description: `The resume command resumes all processes in the instance of the container. 37 | 38 | Use runc list to identiy instances of containers and their current status.`, 39 | Action: func(context *cli.Context) error { 40 | container, err := getContainer(context) 41 | if err != nil { 42 | return err 43 | } 44 | if err := container.Resume(); err != nil { 45 | return err 46 | } 47 | return nil 48 | }, 49 | } 50 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/ps.go: -------------------------------------------------------------------------------- 1 | // +build linux 2 | 3 | package main 4 | 5 | import ( 6 | "encoding/json" 7 | "fmt" 8 | "os" 9 | "os/exec" 10 | "strconv" 11 | "strings" 12 | 13 | "github.com/urfave/cli" 14 | ) 15 | 16 | var psCommand = cli.Command{ 17 | Name: "ps", 18 | Usage: "ps displays the processes running inside a container", 19 | ArgsUsage: ` [-- ps options]`, 20 | Flags: []cli.Flag{ 21 | cli.StringFlag{ 22 | Name: "format, f", 23 | Value: "", 24 | Usage: `select one of: ` + formatOptions, 25 | }, 26 | }, 27 | Action: func(context *cli.Context) error { 28 | container, err := getContainer(context) 29 | if err != nil { 30 | return err 31 | } 32 | 33 | pids, err := container.Processes() 34 | if err != nil { 35 | return err 36 | } 37 | 38 | if context.String("format") == "json" { 39 | if err := json.NewEncoder(os.Stdout).Encode(pids); err != nil { 40 | return err 41 | } 42 | return nil 43 | } 44 | 45 | // [1:] is to remove command name, ex: 46 | // context.Args(): [containet_id ps_arg1 ps_arg2 ...] 47 | // psArgs: [ps_arg1 ps_arg2 ...] 48 | // 49 | psArgs := context.Args()[1:] 50 | 51 | if len(psArgs) > 0 && psArgs[0] == "--" { 52 | psArgs = psArgs[1:] 53 | } 54 | 55 | if len(psArgs) == 0 { 56 | psArgs = []string{"-ef"} 57 | } 58 | 59 | output, err := exec.Command("ps", psArgs...).Output() 60 | if err != nil { 61 | return err 62 | } 63 | 64 | lines := strings.Split(string(output), "\n") 65 | pidIndex, err := getPidIndex(lines[0]) 66 | if err != nil { 67 | return err 68 | } 69 | 70 | fmt.Println(lines[0]) 71 | for _, line := range lines[1:] { 72 | if len(line) == 0 { 73 | continue 74 | } 75 | fields := strings.Fields(line) 76 | p, err := strconv.Atoi(fields[pidIndex]) 77 | if err != nil { 78 | return fmt.Errorf("unexpected pid '%s': %s", fields[pidIndex], err) 79 | } 80 | 81 | for _, pid := range pids { 82 | if pid == p { 83 | fmt.Println(line) 84 | break 85 | } 86 | } 87 | } 88 | return nil 89 | }, 90 | SkipArgReorder: true, 91 | } 92 | 93 | func getPidIndex(title string) (int, error) { 94 | titles := strings.Fields(title) 95 | 96 | pidIndex := -1 97 | for i, name := range titles { 98 | if name == "PID" { 99 | return i, nil 100 | } 101 | } 102 | 103 | return pidIndex, fmt.Errorf("couldn't find PID field in ps output") 104 | } 105 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/rlimit_linux.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | const ( 6 | RLIMIT_CPU = iota // CPU time in sec 7 | RLIMIT_FSIZE // Maximum filesize 8 | RLIMIT_DATA // max data size 9 | RLIMIT_STACK // max stack size 10 | RLIMIT_CORE // max core file size 11 | RLIMIT_RSS // max resident set size 12 | RLIMIT_NPROC // max number of processes 13 | RLIMIT_NOFILE // max number of open files 14 | RLIMIT_MEMLOCK // max locked-in-memory address space 15 | RLIMIT_AS // address space limit 16 | RLIMIT_LOCKS // maximum file locks held 17 | RLIMIT_SIGPENDING // max number of pending signals 18 | RLIMIT_MSGQUEUE // maximum bytes in POSIX mqueues 19 | RLIMIT_NICE // max nice prio allowed to raise to 20 | RLIMIT_RTPRIO // maximum realtime priority 21 | RLIMIT_RTTIME // timeout for RT tasks in us 22 | ) 23 | 24 | var rlimitMap = map[string]int{ 25 | "RLIMIT_CPU": RLIMIT_CPU, 26 | "RLIMIT_FSIZE": RLIMIT_FSIZE, 27 | "RLIMIT_DATA": RLIMIT_DATA, 28 | "RLIMIT_STACK": RLIMIT_STACK, 29 | "RLIMIT_CORE": RLIMIT_CORE, 30 | "RLIMIT_RSS": RLIMIT_RSS, 31 | "RLIMIT_NPROC": RLIMIT_NPROC, 32 | "RLIMIT_NOFILE": RLIMIT_NOFILE, 33 | "RLIMIT_MEMLOCK": RLIMIT_MEMLOCK, 34 | "RLIMIT_AS": RLIMIT_AS, 35 | "RLIMIT_LOCKS": RLIMIT_LOCKS, 36 | "RLIMIT_SIGPENDING": RLIMIT_SIGPENDING, 37 | "RLIMIT_MSGQUEUE": RLIMIT_MSGQUEUE, 38 | "RLIMIT_NICE": RLIMIT_NICE, 39 | "RLIMIT_RTPRIO": RLIMIT_RTPRIO, 40 | "RLIMIT_RTTIME": RLIMIT_RTTIME, 41 | } 42 | 43 | func strToRlimit(key string) (int, error) { 44 | rl, ok := rlimitMap[key] 45 | if !ok { 46 | return 0, fmt.Errorf("Wrong rlimit value: %s", key) 47 | } 48 | return rl, nil 49 | } 50 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/run.go: -------------------------------------------------------------------------------- 1 | // +build linux 2 | 3 | package main 4 | 5 | import ( 6 | "os" 7 | 8 | "github.com/urfave/cli" 9 | ) 10 | 11 | // default action is to start a container 12 | var runCommand = cli.Command{ 13 | Name: "run", 14 | Usage: "create and run a container", 15 | ArgsUsage: ` 16 | 17 | Where "" is your name for the instance of the container that you 18 | are starting. The name you provide for the container instance must be unique on 19 | your host.`, 20 | Description: `The run command creates an instance of a container for a bundle. The bundle 21 | is a directory with a specification file named "` + specConfig + `" and a root 22 | filesystem. 23 | 24 | The specification file includes an args parameter. The args parameter is used 25 | to specify command(s) that get run when the container is started. To change the 26 | command(s) that get executed on start, edit the args parameter of the spec. See 27 | "runc spec --help" for more explanation.`, 28 | Flags: []cli.Flag{ 29 | cli.StringFlag{ 30 | Name: "bundle, b", 31 | Value: "", 32 | Usage: `path to the root of the bundle directory, defaults to the current directory`, 33 | }, 34 | cli.StringFlag{ 35 | Name: "console", 36 | Value: "", 37 | Usage: "specify the pty slave path for use with the container", 38 | }, 39 | cli.BoolFlag{ 40 | Name: "detach, d", 41 | Usage: "detach from the container's process", 42 | }, 43 | cli.StringFlag{ 44 | Name: "pid-file", 45 | Value: "", 46 | Usage: "specify the file to write the process id to", 47 | }, 48 | cli.BoolFlag{ 49 | Name: "no-subreaper", 50 | Usage: "disable the use of the subreaper used to reap reparented processes", 51 | }, 52 | cli.BoolFlag{ 53 | Name: "no-pivot", 54 | Usage: "do not use pivot root to jail process inside rootfs. This should be used whenever the rootfs is on top of a ramdisk", 55 | }, 56 | cli.BoolFlag{ 57 | Name: "no-new-keyring", 58 | Usage: "do not create a new session keyring for the container. This will cause the container to inherit the calling processes session key", 59 | }, 60 | }, 61 | Action: func(context *cli.Context) error { 62 | spec, err := setupSpec(context) 63 | if err != nil { 64 | return err 65 | } 66 | status, err := startContainer(context, spec, false) 67 | if err == nil { 68 | // exit with the container's exit status so any external supervisor is 69 | // notified of the exit with the correct exit status. 70 | os.Exit(status) 71 | } 72 | return err 73 | }, 74 | } 75 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/start.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/opencontainers/runc/libcontainer" 7 | "github.com/urfave/cli" 8 | ) 9 | 10 | var startCommand = cli.Command{ 11 | Name: "start", 12 | Usage: "executes the user defined process in a created container", 13 | ArgsUsage: ` 14 | 15 | Where "" is your name for the instance of the container that you 16 | are starting. The name you provide for the container instance must be unique on 17 | your host.`, 18 | Description: `The start command executes the user defined process in a created container.`, 19 | Action: func(context *cli.Context) error { 20 | container, err := getContainer(context) 21 | if err != nil { 22 | return err 23 | } 24 | status, err := container.Status() 25 | if err != nil { 26 | return err 27 | } 28 | switch status { 29 | case libcontainer.Created: 30 | return container.Exec() 31 | case libcontainer.Stopped: 32 | return fmt.Errorf("cannot start a container that has run and stopped") 33 | case libcontainer.Running: 34 | return fmt.Errorf("cannot start an already running container") 35 | default: 36 | return fmt.Errorf("cannot start a container in the %s state", status) 37 | } 38 | }, 39 | } 40 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/state.go: -------------------------------------------------------------------------------- 1 | // +build linux 2 | 3 | package main 4 | 5 | import ( 6 | "encoding/json" 7 | "os" 8 | 9 | "github.com/opencontainers/runc/libcontainer" 10 | "github.com/opencontainers/runc/libcontainer/utils" 11 | "github.com/urfave/cli" 12 | ) 13 | 14 | var stateCommand = cli.Command{ 15 | Name: "state", 16 | Usage: "output the state of a container", 17 | ArgsUsage: ` 18 | 19 | Where "" is your name for the instance of the container.`, 20 | Description: `The state command outputs current state information for the 21 | instance of a container.`, 22 | Action: func(context *cli.Context) error { 23 | container, err := getContainer(context) 24 | if err != nil { 25 | return err 26 | } 27 | containerStatus, err := container.Status() 28 | if err != nil { 29 | return err 30 | } 31 | state, err := container.State() 32 | if err != nil { 33 | return err 34 | } 35 | pid := state.BaseState.InitProcessPid 36 | if containerStatus == libcontainer.Stopped { 37 | pid = 0 38 | } 39 | bundle, annotations := utils.Annotations(state.Config.Labels) 40 | cs := containerState{ 41 | Version: state.BaseState.Config.Version, 42 | ID: state.BaseState.ID, 43 | InitProcessPid: pid, 44 | Status: containerStatus.String(), 45 | Bundle: bundle, 46 | Rootfs: state.BaseState.Config.Rootfs, 47 | Created: state.BaseState.Created, 48 | Annotations: annotations, 49 | } 50 | data, err := json.MarshalIndent(cs, "", " ") 51 | if err != nil { 52 | return err 53 | } 54 | os.Stdout.Write(data) 55 | return nil 56 | }, 57 | } 58 | -------------------------------------------------------------------------------- /vendor/github.com/opencontainers/runc/utils.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/Sirupsen/logrus" 8 | "github.com/opencontainers/runtime-spec/specs-go" 9 | "github.com/urfave/cli" 10 | ) 11 | 12 | // fatal prints the error's details if it is a libcontainer specific error type 13 | // then exits the program with an exit status of 1. 14 | func fatal(err error) { 15 | // make sure the error is written to the logger 16 | logrus.Error(err) 17 | fmt.Fprintln(os.Stderr, err) 18 | os.Exit(1) 19 | } 20 | 21 | // setupSpec performs inital setup based on the cli.Context for the container 22 | func setupSpec(context *cli.Context) (*specs.Spec, error) { 23 | bundle := context.String("bundle") 24 | if bundle != "" { 25 | if err := os.Chdir(bundle); err != nil { 26 | return nil, err 27 | } 28 | } 29 | spec, err := loadSpec(specConfig) 30 | if err != nil { 31 | return nil, err 32 | } 33 | notifySocket := os.Getenv("NOTIFY_SOCKET") 34 | if notifySocket != "" { 35 | setupSdNotify(spec, notifySocket) 36 | } 37 | if os.Geteuid() != 0 { 38 | return nil, fmt.Errorf("runc should be run as root") 39 | } 40 | return spec, nil 41 | } 42 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/context/ctxhttp/ctxhttp.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.7 6 | 7 | // Package ctxhttp provides helper functions for performing context-aware HTTP requests. 8 | package ctxhttp // import "golang.org/x/net/context/ctxhttp" 9 | 10 | import ( 11 | "io" 12 | "net/http" 13 | "net/url" 14 | "strings" 15 | 16 | "golang.org/x/net/context" 17 | ) 18 | 19 | // Do sends an HTTP request with the provided http.Client and returns 20 | // an HTTP response. 21 | // 22 | // If the client is nil, http.DefaultClient is used. 23 | // 24 | // The provided ctx must be non-nil. If it is canceled or times out, 25 | // ctx.Err() will be returned. 26 | func Do(ctx context.Context, client *http.Client, req *http.Request) (*http.Response, error) { 27 | if client == nil { 28 | client = http.DefaultClient 29 | } 30 | resp, err := client.Do(req.WithContext(ctx)) 31 | // If we got an error, and the context has been canceled, 32 | // the context's error is probably more useful. 33 | if err != nil { 34 | select { 35 | case <-ctx.Done(): 36 | err = ctx.Err() 37 | default: 38 | } 39 | } 40 | return resp, err 41 | } 42 | 43 | // Get issues a GET request via the Do function. 44 | func Get(ctx context.Context, client *http.Client, url string) (*http.Response, error) { 45 | req, err := http.NewRequest("GET", url, nil) 46 | if err != nil { 47 | return nil, err 48 | } 49 | return Do(ctx, client, req) 50 | } 51 | 52 | // Head issues a HEAD request via the Do function. 53 | func Head(ctx context.Context, client *http.Client, url string) (*http.Response, error) { 54 | req, err := http.NewRequest("HEAD", url, nil) 55 | if err != nil { 56 | return nil, err 57 | } 58 | return Do(ctx, client, req) 59 | } 60 | 61 | // Post issues a POST request via the Do function. 62 | func Post(ctx context.Context, client *http.Client, url string, bodyType string, body io.Reader) (*http.Response, error) { 63 | req, err := http.NewRequest("POST", url, body) 64 | if err != nil { 65 | return nil, err 66 | } 67 | req.Header.Set("Content-Type", bodyType) 68 | return Do(ctx, client, req) 69 | } 70 | 71 | // PostForm issues a POST request via the Do function. 72 | func PostForm(ctx context.Context, client *http.Client, url string, data url.Values) (*http.Response, error) { 73 | return Post(ctx, client, url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode())) 74 | } 75 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm.s: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | TEXT ·use(SB),NOSPLIT,$0 10 | RET 11 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_darwin_386.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System call support for 386, Darwin 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-28 17 | JMP syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-40 20 | JMP syscall·Syscall6(SB) 21 | 22 | TEXT ·Syscall9(SB),NOSPLIT,$0-52 23 | JMP syscall·Syscall9(SB) 24 | 25 | TEXT ·RawSyscall(SB),NOSPLIT,$0-28 26 | JMP syscall·RawSyscall(SB) 27 | 28 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-40 29 | JMP syscall·RawSyscall6(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_darwin_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System call support for AMD64, Darwin 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-56 17 | JMP syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-80 20 | JMP syscall·Syscall6(SB) 21 | 22 | TEXT ·Syscall9(SB),NOSPLIT,$0-104 23 | JMP syscall·Syscall9(SB) 24 | 25 | TEXT ·RawSyscall(SB),NOSPLIT,$0-56 26 | JMP syscall·RawSyscall(SB) 27 | 28 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-80 29 | JMP syscall·RawSyscall6(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_dragonfly_386.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System call support for 386, FreeBSD 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-32 17 | JMP syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-44 20 | JMP syscall·Syscall6(SB) 21 | 22 | TEXT ·Syscall9(SB),NOSPLIT,$0-56 23 | JMP syscall·Syscall9(SB) 24 | 25 | TEXT ·RawSyscall(SB),NOSPLIT,$0-32 26 | JMP syscall·RawSyscall(SB) 27 | 28 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-44 29 | JMP syscall·RawSyscall6(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_dragonfly_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System call support for AMD64, DragonFly 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-64 17 | JMP syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-88 20 | JMP syscall·Syscall6(SB) 21 | 22 | TEXT ·Syscall9(SB),NOSPLIT,$0-112 23 | JMP syscall·Syscall9(SB) 24 | 25 | TEXT ·RawSyscall(SB),NOSPLIT,$0-64 26 | JMP syscall·RawSyscall(SB) 27 | 28 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-88 29 | JMP syscall·RawSyscall6(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_freebsd_386.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System call support for 386, FreeBSD 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-28 17 | JMP syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-40 20 | JMP syscall·Syscall6(SB) 21 | 22 | TEXT ·Syscall9(SB),NOSPLIT,$0-52 23 | JMP syscall·Syscall9(SB) 24 | 25 | TEXT ·RawSyscall(SB),NOSPLIT,$0-28 26 | JMP syscall·RawSyscall(SB) 27 | 28 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-40 29 | JMP syscall·RawSyscall6(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_freebsd_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System call support for AMD64, FreeBSD 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-56 17 | JMP syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-80 20 | JMP syscall·Syscall6(SB) 21 | 22 | TEXT ·Syscall9(SB),NOSPLIT,$0-104 23 | JMP syscall·Syscall9(SB) 24 | 25 | TEXT ·RawSyscall(SB),NOSPLIT,$0-56 26 | JMP syscall·RawSyscall(SB) 27 | 28 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-80 29 | JMP syscall·RawSyscall6(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_freebsd_arm.s: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System call support for ARM, FreeBSD 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-28 17 | B syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-40 20 | B syscall·Syscall6(SB) 21 | 22 | TEXT ·Syscall9(SB),NOSPLIT,$0-52 23 | B syscall·Syscall9(SB) 24 | 25 | TEXT ·RawSyscall(SB),NOSPLIT,$0-28 26 | B syscall·RawSyscall(SB) 27 | 28 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-40 29 | B syscall·RawSyscall6(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_linux_386.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System calls for 386, Linux 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-28 17 | JMP syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-40 20 | JMP syscall·Syscall6(SB) 21 | 22 | TEXT ·RawSyscall(SB),NOSPLIT,$0-28 23 | JMP syscall·RawSyscall(SB) 24 | 25 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-40 26 | JMP syscall·RawSyscall6(SB) 27 | 28 | TEXT ·socketcall(SB),NOSPLIT,$0-36 29 | JMP syscall·socketcall(SB) 30 | 31 | TEXT ·rawsocketcall(SB),NOSPLIT,$0-36 32 | JMP syscall·rawsocketcall(SB) 33 | 34 | TEXT ·seek(SB),NOSPLIT,$0-28 35 | JMP syscall·seek(SB) 36 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_linux_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System calls for AMD64, Linux 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-56 17 | JMP syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-80 20 | JMP syscall·Syscall6(SB) 21 | 22 | TEXT ·RawSyscall(SB),NOSPLIT,$0-56 23 | JMP syscall·RawSyscall(SB) 24 | 25 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-80 26 | JMP syscall·RawSyscall6(SB) 27 | 28 | TEXT ·gettimeofday(SB),NOSPLIT,$0-16 29 | JMP syscall·gettimeofday(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_linux_arm.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System calls for arm, Linux 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-28 17 | B syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-40 20 | B syscall·Syscall6(SB) 21 | 22 | TEXT ·RawSyscall(SB),NOSPLIT,$0-28 23 | B syscall·RawSyscall(SB) 24 | 25 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-40 26 | B syscall·RawSyscall6(SB) 27 | 28 | TEXT ·seek(SB),NOSPLIT,$0-32 29 | B syscall·seek(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_netbsd_386.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System call support for 386, NetBSD 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-28 17 | JMP syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-40 20 | JMP syscall·Syscall6(SB) 21 | 22 | TEXT ·Syscall9(SB),NOSPLIT,$0-52 23 | JMP syscall·Syscall9(SB) 24 | 25 | TEXT ·RawSyscall(SB),NOSPLIT,$0-28 26 | JMP syscall·RawSyscall(SB) 27 | 28 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-40 29 | JMP syscall·RawSyscall6(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_netbsd_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System call support for AMD64, NetBSD 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-56 17 | JMP syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-80 20 | JMP syscall·Syscall6(SB) 21 | 22 | TEXT ·Syscall9(SB),NOSPLIT,$0-104 23 | JMP syscall·Syscall9(SB) 24 | 25 | TEXT ·RawSyscall(SB),NOSPLIT,$0-56 26 | JMP syscall·RawSyscall(SB) 27 | 28 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-80 29 | JMP syscall·RawSyscall6(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_netbsd_arm.s: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System call support for ARM, NetBSD 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-28 17 | B syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-40 20 | B syscall·Syscall6(SB) 21 | 22 | TEXT ·Syscall9(SB),NOSPLIT,$0-52 23 | B syscall·Syscall9(SB) 24 | 25 | TEXT ·RawSyscall(SB),NOSPLIT,$0-28 26 | B syscall·RawSyscall(SB) 27 | 28 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-40 29 | B syscall·RawSyscall6(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_openbsd_386.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System call support for 386, OpenBSD 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-28 17 | JMP syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-40 20 | JMP syscall·Syscall6(SB) 21 | 22 | TEXT ·Syscall9(SB),NOSPLIT,$0-52 23 | JMP syscall·Syscall9(SB) 24 | 25 | TEXT ·RawSyscall(SB),NOSPLIT,$0-28 26 | JMP syscall·RawSyscall(SB) 27 | 28 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-40 29 | JMP syscall·RawSyscall6(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_openbsd_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System call support for AMD64, OpenBSD 11 | // 12 | 13 | // Just jump to package syscall's implementation for all these functions. 14 | // The runtime may know about them. 15 | 16 | TEXT ·Syscall(SB),NOSPLIT,$0-56 17 | JMP syscall·Syscall(SB) 18 | 19 | TEXT ·Syscall6(SB),NOSPLIT,$0-80 20 | JMP syscall·Syscall6(SB) 21 | 22 | TEXT ·Syscall9(SB),NOSPLIT,$0-104 23 | JMP syscall·Syscall9(SB) 24 | 25 | TEXT ·RawSyscall(SB),NOSPLIT,$0-56 26 | JMP syscall·RawSyscall(SB) 27 | 28 | TEXT ·RawSyscall6(SB),NOSPLIT,$0-80 29 | JMP syscall·RawSyscall6(SB) 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/asm_solaris_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !gccgo 6 | 7 | // 8 | // System calls for amd64, Solaris are implemented in runtime/syscall_solaris.goc 9 | // 10 | 11 | TEXT ·sysvicall6(SB), 7, $0-64 12 | JMP syscall·sysvicall6(SB) 13 | 14 | TEXT ·rawSysvicall6(SB), 7, $0-64 15 | JMP syscall·rawSysvicall6(SB) 16 | 17 | TEXT ·dlopen(SB), 7, $0-16 18 | JMP syscall·dlopen(SB) 19 | 20 | TEXT ·dlclose(SB), 7, $0-8 21 | JMP syscall·dlclose(SB) 22 | 23 | TEXT ·dlsym(SB), 7, $0-16 24 | JMP syscall·dlsym(SB) 25 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/constants.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build darwin dragonfly freebsd linux netbsd openbsd solaris 6 | 7 | package unix 8 | 9 | const ( 10 | R_OK = 0x4 11 | W_OK = 0x2 12 | X_OK = 0x1 13 | ) 14 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/env_unix.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build darwin dragonfly freebsd linux netbsd openbsd solaris 6 | 7 | // Unix environment variables. 8 | 9 | package unix 10 | 11 | import "syscall" 12 | 13 | func Getenv(key string) (value string, found bool) { 14 | return syscall.Getenv(key) 15 | } 16 | 17 | func Setenv(key, value string) error { 18 | return syscall.Setenv(key, value) 19 | } 20 | 21 | func Clearenv() { 22 | syscall.Clearenv() 23 | } 24 | 25 | func Environ() []string { 26 | return syscall.Environ() 27 | } 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/env_unset.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.4 6 | 7 | package unix 8 | 9 | import "syscall" 10 | 11 | func Unsetenv(key string) error { 12 | // This was added in Go 1.4. 13 | return syscall.Unsetenv(key) 14 | } 15 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/flock.go: -------------------------------------------------------------------------------- 1 | // +build linux darwin freebsd openbsd netbsd dragonfly 2 | 3 | // Copyright 2014 The Go Authors. All rights reserved. 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file. 6 | 7 | // +build darwin dragonfly freebsd linux netbsd openbsd 8 | 9 | package unix 10 | 11 | import "unsafe" 12 | 13 | // fcntl64Syscall is usually SYS_FCNTL, but is overridden on 32-bit Linux 14 | // systems by flock_linux_32bit.go to be SYS_FCNTL64. 15 | var fcntl64Syscall uintptr = SYS_FCNTL 16 | 17 | // FcntlFlock performs a fcntl syscall for the F_GETLK, F_SETLK or F_SETLKW command. 18 | func FcntlFlock(fd uintptr, cmd int, lk *Flock_t) error { 19 | _, _, errno := Syscall(fcntl64Syscall, fd, uintptr(cmd), uintptr(unsafe.Pointer(lk))) 20 | if errno == 0 { 21 | return nil 22 | } 23 | return errno 24 | } 25 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/flock_linux_32bit.go: -------------------------------------------------------------------------------- 1 | // +build linux,386 linux,arm 2 | 3 | // Copyright 2014 The Go Authors. All rights reserved. 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file. 6 | 7 | package unix 8 | 9 | func init() { 10 | // On 32-bit Linux systems, the fcntl syscall that matches Go's 11 | // Flock_t type is SYS_FCNTL64, not SYS_FCNTL. 12 | fcntl64Syscall = SYS_FCNTL64 13 | } 14 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/gccgo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build gccgo 6 | 7 | package unix 8 | 9 | import "syscall" 10 | 11 | // We can't use the gc-syntax .s files for gccgo. On the plus side 12 | // much of the functionality can be written directly in Go. 13 | 14 | //extern gccgoRealSyscall 15 | func realSyscall(trap, a1, a2, a3, a4, a5, a6 uintptr) (r, errno uintptr) 16 | 17 | func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno) { 18 | syscall.Entersyscall() 19 | r, errno := realSyscall(trap, a1, a2, a3, 0, 0, 0) 20 | syscall.Exitsyscall() 21 | return r, 0, syscall.Errno(errno) 22 | } 23 | 24 | func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno) { 25 | syscall.Entersyscall() 26 | r, errno := realSyscall(trap, a1, a2, a3, a4, a5, a6) 27 | syscall.Exitsyscall() 28 | return r, 0, syscall.Errno(errno) 29 | } 30 | 31 | func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno) { 32 | r, errno := realSyscall(trap, a1, a2, a3, 0, 0, 0) 33 | return r, 0, syscall.Errno(errno) 34 | } 35 | 36 | func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno) { 37 | r, errno := realSyscall(trap, a1, a2, a3, a4, a5, a6) 38 | return r, 0, syscall.Errno(errno) 39 | } 40 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/gccgo_c.c: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build gccgo 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #define _STRINGIFY2_(x) #x 12 | #define _STRINGIFY_(x) _STRINGIFY2_(x) 13 | #define GOSYM_PREFIX _STRINGIFY_(__USER_LABEL_PREFIX__) 14 | 15 | // Call syscall from C code because the gccgo support for calling from 16 | // Go to C does not support varargs functions. 17 | 18 | struct ret { 19 | uintptr_t r; 20 | uintptr_t err; 21 | }; 22 | 23 | struct ret 24 | gccgoRealSyscall(uintptr_t trap, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5, uintptr_t a6) 25 | { 26 | struct ret r; 27 | 28 | errno = 0; 29 | r.r = syscall(trap, a1, a2, a3, a4, a5, a6); 30 | r.err = errno; 31 | return r; 32 | } 33 | 34 | // Define the use function in C so that it is not inlined. 35 | 36 | extern void use(void *) __asm__ (GOSYM_PREFIX GOPKGPATH ".use") __attribute__((noinline)); 37 | 38 | void 39 | use(void *p __attribute__ ((unused))) 40 | { 41 | } 42 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/gccgo_linux_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build gccgo,linux,amd64 6 | 7 | package unix 8 | 9 | import "syscall" 10 | 11 | //extern gettimeofday 12 | func realGettimeofday(*Timeval, *byte) int32 13 | 14 | func gettimeofday(tv *Timeval) (err syscall.Errno) { 15 | r := realGettimeofday(tv, nil) 16 | if r < 0 { 17 | return syscall.GetErrno() 18 | } 19 | return 0 20 | } 21 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/race.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build darwin,race linux,race freebsd,race 6 | 7 | package unix 8 | 9 | import ( 10 | "runtime" 11 | "unsafe" 12 | ) 13 | 14 | const raceenabled = true 15 | 16 | func raceAcquire(addr unsafe.Pointer) { 17 | runtime.RaceAcquire(addr) 18 | } 19 | 20 | func raceReleaseMerge(addr unsafe.Pointer) { 21 | runtime.RaceReleaseMerge(addr) 22 | } 23 | 24 | func raceReadRange(addr unsafe.Pointer, len int) { 25 | runtime.RaceReadRange(addr, len) 26 | } 27 | 28 | func raceWriteRange(addr unsafe.Pointer, len int) { 29 | runtime.RaceWriteRange(addr, len) 30 | } 31 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/race0.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build darwin,!race linux,!race freebsd,!race netbsd openbsd solaris dragonfly 6 | 7 | package unix 8 | 9 | import ( 10 | "unsafe" 11 | ) 12 | 13 | const raceenabled = false 14 | 15 | func raceAcquire(addr unsafe.Pointer) { 16 | } 17 | 18 | func raceReleaseMerge(addr unsafe.Pointer) { 19 | } 20 | 21 | func raceReadRange(addr unsafe.Pointer, len int) { 22 | } 23 | 24 | func raceWriteRange(addr unsafe.Pointer, len int) { 25 | } 26 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/sockcmsg_linux.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Socket control messages 6 | 7 | package unix 8 | 9 | import "unsafe" 10 | 11 | // UnixCredentials encodes credentials into a socket control message 12 | // for sending to another process. This can be used for 13 | // authentication. 14 | func UnixCredentials(ucred *Ucred) []byte { 15 | b := make([]byte, CmsgSpace(SizeofUcred)) 16 | h := (*Cmsghdr)(unsafe.Pointer(&b[0])) 17 | h.Level = SOL_SOCKET 18 | h.Type = SCM_CREDENTIALS 19 | h.SetLen(CmsgLen(SizeofUcred)) 20 | *((*Ucred)(cmsgData(h))) = *ucred 21 | return b 22 | } 23 | 24 | // ParseUnixCredentials decodes a socket control message that contains 25 | // credentials in a Ucred structure. To receive such a message, the 26 | // SO_PASSCRED option must be enabled on the socket. 27 | func ParseUnixCredentials(m *SocketControlMessage) (*Ucred, error) { 28 | if m.Header.Level != SOL_SOCKET { 29 | return nil, EINVAL 30 | } 31 | if m.Header.Type != SCM_CREDENTIALS { 32 | return nil, EINVAL 33 | } 34 | ucred := *(*Ucred)(unsafe.Pointer(&m.Data[0])) 35 | return &ucred, nil 36 | } 37 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/str.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build darwin dragonfly freebsd linux netbsd openbsd solaris 6 | 7 | package unix 8 | 9 | func itoa(val int) string { // do it here rather than with fmt to avoid dependency 10 | if val < 0 { 11 | return "-" + itoa(-val) 12 | } 13 | var buf [32]byte // big enough for int64 14 | i := len(buf) - 1 15 | for val >= 10 { 16 | buf[i] = byte(val%10 + '0') 17 | i-- 18 | val /= 10 19 | } 20 | buf[i] = byte(val + '0') 21 | return string(buf[i:]) 22 | } 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_darwin_386.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | import ( 8 | "syscall" 9 | "unsafe" 10 | ) 11 | 12 | func Getpagesize() int { return 4096 } 13 | 14 | func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } 15 | 16 | func NsecToTimespec(nsec int64) (ts Timespec) { 17 | ts.Sec = int32(nsec / 1e9) 18 | ts.Nsec = int32(nsec % 1e9) 19 | return 20 | } 21 | 22 | func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } 23 | 24 | func NsecToTimeval(nsec int64) (tv Timeval) { 25 | nsec += 999 // round up to microsecond 26 | tv.Usec = int32(nsec % 1e9 / 1e3) 27 | tv.Sec = int32(nsec / 1e9) 28 | return 29 | } 30 | 31 | //sysnb gettimeofday(tp *Timeval) (sec int32, usec int32, err error) 32 | func Gettimeofday(tv *Timeval) (err error) { 33 | // The tv passed to gettimeofday must be non-nil 34 | // but is otherwise unused. The answers come back 35 | // in the two registers. 36 | sec, usec, err := gettimeofday(tv) 37 | tv.Sec = int32(sec) 38 | tv.Usec = int32(usec) 39 | return err 40 | } 41 | 42 | func SetKevent(k *Kevent_t, fd, mode, flags int) { 43 | k.Ident = uint32(fd) 44 | k.Filter = int16(mode) 45 | k.Flags = uint16(flags) 46 | } 47 | 48 | func (iov *Iovec) SetLen(length int) { 49 | iov.Len = uint32(length) 50 | } 51 | 52 | func (msghdr *Msghdr) SetControllen(length int) { 53 | msghdr.Controllen = uint32(length) 54 | } 55 | 56 | func (cmsg *Cmsghdr) SetLen(length int) { 57 | cmsg.Len = uint32(length) 58 | } 59 | 60 | func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { 61 | var length = uint64(count) 62 | 63 | _, _, e1 := Syscall9(SYS_SENDFILE, uintptr(infd), uintptr(outfd), uintptr(*offset), uintptr(*offset>>32), uintptr(unsafe.Pointer(&length)), 0, 0, 0, 0) 64 | 65 | written = int(length) 66 | 67 | if e1 != 0 { 68 | err = e1 69 | } 70 | return 71 | } 72 | 73 | func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno) 74 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_darwin_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | import ( 8 | "syscall" 9 | "unsafe" 10 | ) 11 | 12 | func Getpagesize() int { return 4096 } 13 | 14 | func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } 15 | 16 | func NsecToTimespec(nsec int64) (ts Timespec) { 17 | ts.Sec = nsec / 1e9 18 | ts.Nsec = nsec % 1e9 19 | return 20 | } 21 | 22 | func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } 23 | 24 | func NsecToTimeval(nsec int64) (tv Timeval) { 25 | nsec += 999 // round up to microsecond 26 | tv.Usec = int32(nsec % 1e9 / 1e3) 27 | tv.Sec = int64(nsec / 1e9) 28 | return 29 | } 30 | 31 | //sysnb gettimeofday(tp *Timeval) (sec int64, usec int32, err error) 32 | func Gettimeofday(tv *Timeval) (err error) { 33 | // The tv passed to gettimeofday must be non-nil 34 | // but is otherwise unused. The answers come back 35 | // in the two registers. 36 | sec, usec, err := gettimeofday(tv) 37 | tv.Sec = sec 38 | tv.Usec = usec 39 | return err 40 | } 41 | 42 | func SetKevent(k *Kevent_t, fd, mode, flags int) { 43 | k.Ident = uint64(fd) 44 | k.Filter = int16(mode) 45 | k.Flags = uint16(flags) 46 | } 47 | 48 | func (iov *Iovec) SetLen(length int) { 49 | iov.Len = uint64(length) 50 | } 51 | 52 | func (msghdr *Msghdr) SetControllen(length int) { 53 | msghdr.Controllen = uint32(length) 54 | } 55 | 56 | func (cmsg *Cmsghdr) SetLen(length int) { 57 | cmsg.Len = uint32(length) 58 | } 59 | 60 | func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { 61 | var length = uint64(count) 62 | 63 | _, _, e1 := Syscall6(SYS_SENDFILE, uintptr(infd), uintptr(outfd), uintptr(*offset), uintptr(unsafe.Pointer(&length)), 0, 0) 64 | 65 | written = int(length) 66 | 67 | if e1 != 0 { 68 | err = e1 69 | } 70 | return 71 | } 72 | 73 | func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno) 74 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_dragonfly_386.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | import ( 8 | "syscall" 9 | "unsafe" 10 | ) 11 | 12 | func Getpagesize() int { return 4096 } 13 | 14 | func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } 15 | 16 | func NsecToTimespec(nsec int64) (ts Timespec) { 17 | ts.Sec = int32(nsec / 1e9) 18 | ts.Nsec = int32(nsec % 1e9) 19 | return 20 | } 21 | 22 | func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } 23 | 24 | func NsecToTimeval(nsec int64) (tv Timeval) { 25 | nsec += 999 // round up to microsecond 26 | tv.Usec = int32(nsec % 1e9 / 1e3) 27 | tv.Sec = int32(nsec / 1e9) 28 | return 29 | } 30 | 31 | func SetKevent(k *Kevent_t, fd, mode, flags int) { 32 | k.Ident = uint32(fd) 33 | k.Filter = int16(mode) 34 | k.Flags = uint16(flags) 35 | } 36 | 37 | func (iov *Iovec) SetLen(length int) { 38 | iov.Len = uint32(length) 39 | } 40 | 41 | func (msghdr *Msghdr) SetControllen(length int) { 42 | msghdr.Controllen = uint32(length) 43 | } 44 | 45 | func (cmsg *Cmsghdr) SetLen(length int) { 46 | cmsg.Len = uint32(length) 47 | } 48 | 49 | func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { 50 | var writtenOut uint64 = 0 51 | _, _, e1 := Syscall9(SYS_SENDFILE, uintptr(infd), uintptr(outfd), uintptr(*offset), uintptr((*offset)>>32), uintptr(count), 0, uintptr(unsafe.Pointer(&writtenOut)), 0, 0) 52 | 53 | written = int(writtenOut) 54 | 55 | if e1 != 0 { 56 | err = e1 57 | } 58 | return 59 | } 60 | 61 | func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno) 62 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_dragonfly_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | import ( 8 | "syscall" 9 | "unsafe" 10 | ) 11 | 12 | func Getpagesize() int { return 4096 } 13 | 14 | func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } 15 | 16 | func NsecToTimespec(nsec int64) (ts Timespec) { 17 | ts.Sec = nsec / 1e9 18 | ts.Nsec = nsec % 1e9 19 | return 20 | } 21 | 22 | func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } 23 | 24 | func NsecToTimeval(nsec int64) (tv Timeval) { 25 | nsec += 999 // round up to microsecond 26 | tv.Usec = nsec % 1e9 / 1e3 27 | tv.Sec = int64(nsec / 1e9) 28 | return 29 | } 30 | 31 | func SetKevent(k *Kevent_t, fd, mode, flags int) { 32 | k.Ident = uint64(fd) 33 | k.Filter = int16(mode) 34 | k.Flags = uint16(flags) 35 | } 36 | 37 | func (iov *Iovec) SetLen(length int) { 38 | iov.Len = uint64(length) 39 | } 40 | 41 | func (msghdr *Msghdr) SetControllen(length int) { 42 | msghdr.Controllen = uint32(length) 43 | } 44 | 45 | func (cmsg *Cmsghdr) SetLen(length int) { 46 | cmsg.Len = uint32(length) 47 | } 48 | 49 | func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { 50 | var writtenOut uint64 = 0 51 | _, _, e1 := Syscall9(SYS_SENDFILE, uintptr(infd), uintptr(outfd), uintptr(*offset), uintptr(count), 0, uintptr(unsafe.Pointer(&writtenOut)), 0, 0, 0) 52 | 53 | written = int(writtenOut) 54 | 55 | if e1 != 0 { 56 | err = e1 57 | } 58 | return 59 | } 60 | 61 | func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno) 62 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_freebsd_386.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | import ( 8 | "syscall" 9 | "unsafe" 10 | ) 11 | 12 | func Getpagesize() int { return 4096 } 13 | 14 | func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } 15 | 16 | func NsecToTimespec(nsec int64) (ts Timespec) { 17 | ts.Sec = int32(nsec / 1e9) 18 | ts.Nsec = int32(nsec % 1e9) 19 | return 20 | } 21 | 22 | func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } 23 | 24 | func NsecToTimeval(nsec int64) (tv Timeval) { 25 | nsec += 999 // round up to microsecond 26 | tv.Usec = int32(nsec % 1e9 / 1e3) 27 | tv.Sec = int32(nsec / 1e9) 28 | return 29 | } 30 | 31 | func SetKevent(k *Kevent_t, fd, mode, flags int) { 32 | k.Ident = uint32(fd) 33 | k.Filter = int16(mode) 34 | k.Flags = uint16(flags) 35 | } 36 | 37 | func (iov *Iovec) SetLen(length int) { 38 | iov.Len = uint32(length) 39 | } 40 | 41 | func (msghdr *Msghdr) SetControllen(length int) { 42 | msghdr.Controllen = uint32(length) 43 | } 44 | 45 | func (cmsg *Cmsghdr) SetLen(length int) { 46 | cmsg.Len = uint32(length) 47 | } 48 | 49 | func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { 50 | var writtenOut uint64 = 0 51 | _, _, e1 := Syscall9(SYS_SENDFILE, uintptr(infd), uintptr(outfd), uintptr(*offset), uintptr((*offset)>>32), uintptr(count), 0, uintptr(unsafe.Pointer(&writtenOut)), 0, 0) 52 | 53 | written = int(writtenOut) 54 | 55 | if e1 != 0 { 56 | err = e1 57 | } 58 | return 59 | } 60 | 61 | func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno) 62 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_freebsd_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | import ( 8 | "syscall" 9 | "unsafe" 10 | ) 11 | 12 | func Getpagesize() int { return 4096 } 13 | 14 | func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } 15 | 16 | func NsecToTimespec(nsec int64) (ts Timespec) { 17 | ts.Sec = nsec / 1e9 18 | ts.Nsec = nsec % 1e9 19 | return 20 | } 21 | 22 | func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } 23 | 24 | func NsecToTimeval(nsec int64) (tv Timeval) { 25 | nsec += 999 // round up to microsecond 26 | tv.Usec = nsec % 1e9 / 1e3 27 | tv.Sec = int64(nsec / 1e9) 28 | return 29 | } 30 | 31 | func SetKevent(k *Kevent_t, fd, mode, flags int) { 32 | k.Ident = uint64(fd) 33 | k.Filter = int16(mode) 34 | k.Flags = uint16(flags) 35 | } 36 | 37 | func (iov *Iovec) SetLen(length int) { 38 | iov.Len = uint64(length) 39 | } 40 | 41 | func (msghdr *Msghdr) SetControllen(length int) { 42 | msghdr.Controllen = uint32(length) 43 | } 44 | 45 | func (cmsg *Cmsghdr) SetLen(length int) { 46 | cmsg.Len = uint32(length) 47 | } 48 | 49 | func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { 50 | var writtenOut uint64 = 0 51 | _, _, e1 := Syscall9(SYS_SENDFILE, uintptr(infd), uintptr(outfd), uintptr(*offset), uintptr(count), 0, uintptr(unsafe.Pointer(&writtenOut)), 0, 0, 0) 52 | 53 | written = int(writtenOut) 54 | 55 | if e1 != 0 { 56 | err = e1 57 | } 58 | return 59 | } 60 | 61 | func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno) 62 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_freebsd_arm.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | import ( 8 | "syscall" 9 | "unsafe" 10 | ) 11 | 12 | func Getpagesize() int { return 4096 } 13 | 14 | func TimespecToNsec(ts Timespec) int64 { return ts.Sec*1e9 + int64(ts.Nsec) } 15 | 16 | func NsecToTimespec(nsec int64) (ts Timespec) { 17 | ts.Sec = nsec / 1e9 18 | ts.Nsec = int32(nsec % 1e9) 19 | return 20 | } 21 | 22 | func TimevalToNsec(tv Timeval) int64 { return tv.Sec*1e9 + int64(tv.Usec)*1e3 } 23 | 24 | func NsecToTimeval(nsec int64) (tv Timeval) { 25 | nsec += 999 // round up to microsecond 26 | tv.Usec = int32(nsec % 1e9 / 1e3) 27 | tv.Sec = nsec / 1e9 28 | return 29 | } 30 | 31 | func SetKevent(k *Kevent_t, fd, mode, flags int) { 32 | k.Ident = uint32(fd) 33 | k.Filter = int16(mode) 34 | k.Flags = uint16(flags) 35 | } 36 | 37 | func (iov *Iovec) SetLen(length int) { 38 | iov.Len = uint32(length) 39 | } 40 | 41 | func (msghdr *Msghdr) SetControllen(length int) { 42 | msghdr.Controllen = uint32(length) 43 | } 44 | 45 | func (cmsg *Cmsghdr) SetLen(length int) { 46 | cmsg.Len = uint32(length) 47 | } 48 | 49 | func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { 50 | var writtenOut uint64 = 0 51 | _, _, e1 := Syscall9(SYS_SENDFILE, uintptr(infd), uintptr(outfd), uintptr(*offset), uintptr((*offset)>>32), uintptr(count), 0, uintptr(unsafe.Pointer(&writtenOut)), 0, 0) 52 | 53 | written = int(writtenOut) 54 | 55 | if e1 != 0 { 56 | err = e1 57 | } 58 | return 59 | } 60 | 61 | func Syscall9(num, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno) 62 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_netbsd_386.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | func Getpagesize() int { return 4096 } 8 | 9 | func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } 10 | 11 | func NsecToTimespec(nsec int64) (ts Timespec) { 12 | ts.Sec = int64(nsec / 1e9) 13 | ts.Nsec = int32(nsec % 1e9) 14 | return 15 | } 16 | 17 | func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } 18 | 19 | func NsecToTimeval(nsec int64) (tv Timeval) { 20 | nsec += 999 // round up to microsecond 21 | tv.Usec = int32(nsec % 1e9 / 1e3) 22 | tv.Sec = int64(nsec / 1e9) 23 | return 24 | } 25 | 26 | func SetKevent(k *Kevent_t, fd, mode, flags int) { 27 | k.Ident = uint32(fd) 28 | k.Filter = uint32(mode) 29 | k.Flags = uint32(flags) 30 | } 31 | 32 | func (iov *Iovec) SetLen(length int) { 33 | iov.Len = uint32(length) 34 | } 35 | 36 | func (msghdr *Msghdr) SetControllen(length int) { 37 | msghdr.Controllen = uint32(length) 38 | } 39 | 40 | func (cmsg *Cmsghdr) SetLen(length int) { 41 | cmsg.Len = uint32(length) 42 | } 43 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_netbsd_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | func Getpagesize() int { return 4096 } 8 | 9 | func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } 10 | 11 | func NsecToTimespec(nsec int64) (ts Timespec) { 12 | ts.Sec = int64(nsec / 1e9) 13 | ts.Nsec = int64(nsec % 1e9) 14 | return 15 | } 16 | 17 | func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } 18 | 19 | func NsecToTimeval(nsec int64) (tv Timeval) { 20 | nsec += 999 // round up to microsecond 21 | tv.Usec = int32(nsec % 1e9 / 1e3) 22 | tv.Sec = int64(nsec / 1e9) 23 | return 24 | } 25 | 26 | func SetKevent(k *Kevent_t, fd, mode, flags int) { 27 | k.Ident = uint64(fd) 28 | k.Filter = uint32(mode) 29 | k.Flags = uint32(flags) 30 | } 31 | 32 | func (iov *Iovec) SetLen(length int) { 33 | iov.Len = uint64(length) 34 | } 35 | 36 | func (msghdr *Msghdr) SetControllen(length int) { 37 | msghdr.Controllen = uint32(length) 38 | } 39 | 40 | func (cmsg *Cmsghdr) SetLen(length int) { 41 | cmsg.Len = uint32(length) 42 | } 43 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_netbsd_arm.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | func Getpagesize() int { return 4096 } 8 | 9 | func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } 10 | 11 | func NsecToTimespec(nsec int64) (ts Timespec) { 12 | ts.Sec = int64(nsec / 1e9) 13 | ts.Nsec = int32(nsec % 1e9) 14 | return 15 | } 16 | 17 | func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } 18 | 19 | func NsecToTimeval(nsec int64) (tv Timeval) { 20 | nsec += 999 // round up to microsecond 21 | tv.Usec = int32(nsec % 1e9 / 1e3) 22 | tv.Sec = int64(nsec / 1e9) 23 | return 24 | } 25 | 26 | func SetKevent(k *Kevent_t, fd, mode, flags int) { 27 | k.Ident = uint32(fd) 28 | k.Filter = uint32(mode) 29 | k.Flags = uint32(flags) 30 | } 31 | 32 | func (iov *Iovec) SetLen(length int) { 33 | iov.Len = uint32(length) 34 | } 35 | 36 | func (msghdr *Msghdr) SetControllen(length int) { 37 | msghdr.Controllen = uint32(length) 38 | } 39 | 40 | func (cmsg *Cmsghdr) SetLen(length int) { 41 | cmsg.Len = uint32(length) 42 | } 43 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_no_getwd.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build dragonfly freebsd netbsd openbsd 6 | 7 | package unix 8 | 9 | const ImplementsGetwd = false 10 | 11 | func Getwd() (string, error) { return "", ENOTSUP } 12 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_openbsd_386.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | func Getpagesize() int { return 4096 } 8 | 9 | func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } 10 | 11 | func NsecToTimespec(nsec int64) (ts Timespec) { 12 | ts.Sec = int64(nsec / 1e9) 13 | ts.Nsec = int32(nsec % 1e9) 14 | return 15 | } 16 | 17 | func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } 18 | 19 | func NsecToTimeval(nsec int64) (tv Timeval) { 20 | nsec += 999 // round up to microsecond 21 | tv.Usec = int32(nsec % 1e9 / 1e3) 22 | tv.Sec = int64(nsec / 1e9) 23 | return 24 | } 25 | 26 | func SetKevent(k *Kevent_t, fd, mode, flags int) { 27 | k.Ident = uint32(fd) 28 | k.Filter = int16(mode) 29 | k.Flags = uint16(flags) 30 | } 31 | 32 | func (iov *Iovec) SetLen(length int) { 33 | iov.Len = uint32(length) 34 | } 35 | 36 | func (msghdr *Msghdr) SetControllen(length int) { 37 | msghdr.Controllen = uint32(length) 38 | } 39 | 40 | func (cmsg *Cmsghdr) SetLen(length int) { 41 | cmsg.Len = uint32(length) 42 | } 43 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_openbsd_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | func Getpagesize() int { return 4096 } 8 | 9 | func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } 10 | 11 | func NsecToTimespec(nsec int64) (ts Timespec) { 12 | ts.Sec = nsec / 1e9 13 | ts.Nsec = nsec % 1e9 14 | return 15 | } 16 | 17 | func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } 18 | 19 | func NsecToTimeval(nsec int64) (tv Timeval) { 20 | nsec += 999 // round up to microsecond 21 | tv.Usec = nsec % 1e9 / 1e3 22 | tv.Sec = nsec / 1e9 23 | return 24 | } 25 | 26 | func SetKevent(k *Kevent_t, fd, mode, flags int) { 27 | k.Ident = uint64(fd) 28 | k.Filter = int16(mode) 29 | k.Flags = uint16(flags) 30 | } 31 | 32 | func (iov *Iovec) SetLen(length int) { 33 | iov.Len = uint64(length) 34 | } 35 | 36 | func (msghdr *Msghdr) SetControllen(length int) { 37 | msghdr.Controllen = uint32(length) 38 | } 39 | 40 | func (cmsg *Cmsghdr) SetLen(length int) { 41 | cmsg.Len = uint32(length) 42 | } 43 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/syscall_solaris_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | func Getpagesize() int { return 4096 } 8 | 9 | func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } 10 | 11 | func NsecToTimespec(nsec int64) (ts Timespec) { 12 | ts.Sec = nsec / 1e9 13 | ts.Nsec = nsec % 1e9 14 | return 15 | } 16 | 17 | func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } 18 | 19 | func NsecToTimeval(nsec int64) (tv Timeval) { 20 | nsec += 999 // round up to microsecond 21 | tv.Usec = nsec % 1e9 / 1e3 22 | tv.Sec = int64(nsec / 1e9) 23 | return 24 | } 25 | 26 | func (iov *Iovec) SetLen(length int) { 27 | iov.Len = uint64(length) 28 | } 29 | 30 | func (cmsg *Cmsghdr) SetLen(length int) { 31 | cmsg.Len = uint32(length) 32 | } 33 | 34 | func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { 35 | // TODO(aram): implement this, see issue 5847. 36 | panic("unimplemented") 37 | } 38 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/unix/zsysnum_solaris_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package unix 6 | 7 | // TODO(aram): remove these before Go 1.3. 8 | const ( 9 | SYS_EXECVE = 59 10 | SYS_FCNTL = 62 11 | ) 12 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/asm.s: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "textflag.h" 6 | 7 | TEXT ·use(SB),NOSPLIT,$0 8 | RET 9 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/asm_windows_386.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // 6 | // System calls for 386, Windows are implemented in runtime/syscall_windows.goc 7 | // 8 | 9 | TEXT ·getprocaddress(SB), 7, $0-8 10 | JMP syscall·getprocaddress(SB) 11 | 12 | TEXT ·loadlibrary(SB), 7, $0-4 13 | JMP syscall·loadlibrary(SB) 14 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/asm_windows_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // 6 | // System calls for amd64, Windows are implemented in runtime/syscall_windows.goc 7 | // 8 | 9 | TEXT ·getprocaddress(SB), 7, $0-32 10 | JMP syscall·getprocaddress(SB) 11 | 12 | TEXT ·loadlibrary(SB), 7, $0-8 13 | JMP syscall·loadlibrary(SB) 14 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/env_unset.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.4 6 | 7 | package windows 8 | 9 | import "syscall" 10 | 11 | func Unsetenv(key string) error { 12 | // This was added in Go 1.4. 13 | return syscall.Unsetenv(key) 14 | } 15 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/env_windows.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Windows environment variables. 6 | 7 | package windows 8 | 9 | import ( 10 | "unicode/utf16" 11 | "unsafe" 12 | ) 13 | 14 | func Getenv(key string) (value string, found bool) { 15 | keyp, err := UTF16PtrFromString(key) 16 | if err != nil { 17 | return "", false 18 | } 19 | n := uint32(100) 20 | for { 21 | b := make([]uint16, n) 22 | n, err = GetEnvironmentVariable(keyp, &b[0], uint32(len(b))) 23 | if n == 0 && err == ERROR_ENVVAR_NOT_FOUND { 24 | return "", false 25 | } 26 | if n <= uint32(len(b)) { 27 | return string(utf16.Decode(b[:n])), true 28 | } 29 | } 30 | } 31 | 32 | func Setenv(key, value string) error { 33 | v, err := UTF16PtrFromString(value) 34 | if err != nil { 35 | return err 36 | } 37 | keyp, err := UTF16PtrFromString(key) 38 | if err != nil { 39 | return err 40 | } 41 | e := SetEnvironmentVariable(keyp, v) 42 | if e != nil { 43 | return e 44 | } 45 | return nil 46 | } 47 | 48 | func Clearenv() { 49 | for _, s := range Environ() { 50 | // Environment variables can begin with = 51 | // so start looking for the separator = at j=1. 52 | // http://blogs.msdn.com/b/oldnewthing/archive/2010/05/06/10008132.aspx 53 | for j := 1; j < len(s); j++ { 54 | if s[j] == '=' { 55 | Setenv(s[0:j], "") 56 | break 57 | } 58 | } 59 | } 60 | } 61 | 62 | func Environ() []string { 63 | s, e := GetEnvironmentStrings() 64 | if e != nil { 65 | return nil 66 | } 67 | defer FreeEnvironmentStrings(s) 68 | r := make([]string, 0, 50) // Empty with room to grow. 69 | for from, i, p := 0, 0, (*[1 << 24]uint16)(unsafe.Pointer(s)); true; i++ { 70 | if p[i] == 0 { 71 | // empty string marks the end 72 | if i <= from { 73 | break 74 | } 75 | r = append(r, string(utf16.Decode(p[from:i]))) 76 | from = i + 1 77 | } 78 | } 79 | return r 80 | } 81 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/eventlog.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package windows 8 | 9 | const ( 10 | EVENTLOG_SUCCESS = 0 11 | EVENTLOG_ERROR_TYPE = 1 12 | EVENTLOG_WARNING_TYPE = 2 13 | EVENTLOG_INFORMATION_TYPE = 4 14 | EVENTLOG_AUDIT_SUCCESS = 8 15 | EVENTLOG_AUDIT_FAILURE = 16 16 | ) 17 | 18 | //sys RegisterEventSource(uncServerName *uint16, sourceName *uint16) (handle Handle, err error) [failretval==0] = advapi32.RegisterEventSourceW 19 | //sys DeregisterEventSource(handle Handle) (err error) = advapi32.DeregisterEventSource 20 | //sys ReportEvent(log Handle, etype uint16, category uint16, eventId uint32, usrSId uintptr, numStrings uint16, dataSize uint32, strings **uint16, rawData *byte) (err error) = advapi32.ReportEventW 21 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/exec_windows.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Fork, exec, wait, etc. 6 | 7 | package windows 8 | 9 | // EscapeArg rewrites command line argument s as prescribed 10 | // in http://msdn.microsoft.com/en-us/library/ms880421. 11 | // This function returns "" (2 double quotes) if s is empty. 12 | // Alternatively, these transformations are done: 13 | // - every back slash (\) is doubled, but only if immediately 14 | // followed by double quote ("); 15 | // - every double quote (") is escaped by back slash (\); 16 | // - finally, s is wrapped with double quotes (arg -> "arg"), 17 | // but only if there is space or tab inside s. 18 | func EscapeArg(s string) string { 19 | if len(s) == 0 { 20 | return "\"\"" 21 | } 22 | n := len(s) 23 | hasSpace := false 24 | for i := 0; i < len(s); i++ { 25 | switch s[i] { 26 | case '"', '\\': 27 | n++ 28 | case ' ', '\t': 29 | hasSpace = true 30 | } 31 | } 32 | if hasSpace { 33 | n += 2 34 | } 35 | if n == len(s) { 36 | return s 37 | } 38 | 39 | qs := make([]byte, n) 40 | j := 0 41 | if hasSpace { 42 | qs[j] = '"' 43 | j++ 44 | } 45 | slashes := 0 46 | for i := 0; i < len(s); i++ { 47 | switch s[i] { 48 | default: 49 | slashes = 0 50 | qs[j] = s[i] 51 | case '\\': 52 | slashes++ 53 | qs[j] = s[i] 54 | case '"': 55 | for ; slashes > 0; slashes-- { 56 | qs[j] = '\\' 57 | j++ 58 | } 59 | qs[j] = '\\' 60 | j++ 61 | qs[j] = s[i] 62 | } 63 | j++ 64 | } 65 | if hasSpace { 66 | for ; slashes > 0; slashes-- { 67 | qs[j] = '\\' 68 | j++ 69 | } 70 | qs[j] = '"' 71 | j++ 72 | } 73 | return string(qs[:j]) 74 | } 75 | 76 | func CloseOnExec(fd Handle) { 77 | SetHandleInformation(Handle(fd), HANDLE_FLAG_INHERIT, 0) 78 | } 79 | 80 | // FullPath retrieves the full path of the specified file. 81 | func FullPath(name string) (path string, err error) { 82 | p, err := UTF16PtrFromString(name) 83 | if err != nil { 84 | return "", err 85 | } 86 | n := uint32(100) 87 | for { 88 | buf := make([]uint16, n) 89 | n, err = GetFullPathName(p, uint32(len(buf)), &buf[0], nil) 90 | if err != nil { 91 | return "", err 92 | } 93 | if n <= uint32(len(buf)) { 94 | return UTF16ToString(buf[:n]), nil 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/race.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows,race 6 | 7 | package windows 8 | 9 | import ( 10 | "runtime" 11 | "unsafe" 12 | ) 13 | 14 | const raceenabled = true 15 | 16 | func raceAcquire(addr unsafe.Pointer) { 17 | runtime.RaceAcquire(addr) 18 | } 19 | 20 | func raceReleaseMerge(addr unsafe.Pointer) { 21 | runtime.RaceReleaseMerge(addr) 22 | } 23 | 24 | func raceReadRange(addr unsafe.Pointer, len int) { 25 | runtime.RaceReadRange(addr, len) 26 | } 27 | 28 | func raceWriteRange(addr unsafe.Pointer, len int) { 29 | runtime.RaceWriteRange(addr, len) 30 | } 31 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/race0.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows,!race 6 | 7 | package windows 8 | 9 | import ( 10 | "unsafe" 11 | ) 12 | 13 | const raceenabled = false 14 | 15 | func raceAcquire(addr unsafe.Pointer) { 16 | } 17 | 18 | func raceReleaseMerge(addr unsafe.Pointer) { 19 | } 20 | 21 | func raceReadRange(addr unsafe.Pointer, len int) { 22 | } 23 | 24 | func raceWriteRange(addr unsafe.Pointer, len int) { 25 | } 26 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/str.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build windows 6 | 7 | package windows 8 | 9 | func itoa(val int) string { // do it here rather than with fmt to avoid dependency 10 | if val < 0 { 11 | return "-" + itoa(-val) 12 | } 13 | var buf [32]byte // big enough for int64 14 | i := len(buf) - 1 15 | for val >= 10 { 16 | buf[i] = byte(val%10 + '0') 17 | i-- 18 | val /= 10 19 | } 20 | buf[i] = byte(val + '0') 21 | return string(buf[i:]) 22 | } 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/ztypes_windows_386.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package windows 6 | 7 | type WSAData struct { 8 | Version uint16 9 | HighVersion uint16 10 | Description [WSADESCRIPTION_LEN + 1]byte 11 | SystemStatus [WSASYS_STATUS_LEN + 1]byte 12 | MaxSockets uint16 13 | MaxUdpDg uint16 14 | VendorInfo *byte 15 | } 16 | 17 | type Servent struct { 18 | Name *byte 19 | Aliases **byte 20 | Port uint16 21 | Proto *byte 22 | } 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/ztypes_windows_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package windows 6 | 7 | type WSAData struct { 8 | Version uint16 9 | HighVersion uint16 10 | MaxSockets uint16 11 | MaxUdpDg uint16 12 | VendorInfo *byte 13 | Description [WSADESCRIPTION_LEN + 1]byte 14 | SystemStatus [WSASYS_STATUS_LEN + 1]byte 15 | } 16 | 17 | type Servent struct { 18 | Name *byte 19 | Aliases **byte 20 | Proto *byte 21 | Port uint16 22 | } 23 | --------------------------------------------------------------------------------