Various minor vendoring bumps
| ... | ... |
@@ -71,8 +71,7 @@ github.com/vbatts/tar-split 620714a4c508c880ac1bdda9c837 |
| 71 | 71 |
github.com/opencontainers/go-digest 279bed98673dd5bef374d3b6e4b09e2af76183bf # v1.0.0-rc1 |
| 72 | 72 |
|
| 73 | 73 |
# get go-zfs packages |
| 74 |
-github.com/mistifyio/go-zfs 22c9b32c84eb0d0c6f4043b6e90fc94073de92fa |
|
| 75 |
-github.com/pborman/uuid a97ce2ca70fa5a848076093f05e639a89ca34d06 # v1.0 |
|
| 74 |
+github.com/mistifyio/go-zfs f784269be439d704d3dfa1906f45dd848fed2beb |
|
| 76 | 75 |
|
| 77 | 76 |
google.golang.org/grpc 7a6a684ca69eb4cae85ad0a484f2e531598c047b # v1.12.2 |
| 78 | 77 |
|
| ... | ... |
@@ -89,7 +88,7 @@ github.com/seccomp/libseccomp-golang 32f571b70023028bd57d9288c20e |
| 89 | 89 |
# libcontainer deps (see src/github.com/opencontainers/runc/Godeps/Godeps.json) |
| 90 | 90 |
github.com/coreos/go-systemd 39ca1b05acc7ad1220e09f133283b8859a8b71ab # v17 |
| 91 | 91 |
github.com/godbus/dbus 5f6efc7ef2759c81b7ba876593971bfce311eab3 # v4.0.0 |
| 92 |
-github.com/syndtr/gocapability 2c00daeb6c3b45114c80ac44119e7b8801fdd852 |
|
| 92 |
+github.com/syndtr/gocapability d98352740cb2c55f81556b63d4a1ec64c5a319c2 |
|
| 93 | 93 |
github.com/golang/protobuf aa810b61a9c79d51363740d207bb46cf8e620ed5 # v1.2.0 |
| 94 | 94 |
|
| 95 | 95 |
# gelf logging driver deps |
| ... | ... |
@@ -121,12 +120,12 @@ google.golang.org/genproto 694d95ba50e67b2e363f3483057d |
| 121 | 121 |
|
| 122 | 122 |
# containerd |
| 123 | 123 |
github.com/containerd/containerd ceba56893a76f22cf0126c46d835c80fb3833408 |
| 124 |
-github.com/containerd/fifo 3d5202aec260678c48179c56f40e6f38a095738c |
|
| 124 |
+github.com/containerd/fifo a9fb20d87448d386e6d50b1f2e1fa70dcf0de43c |
|
| 125 | 125 |
github.com/containerd/continuity 004b46473808b3e7a4a3049c20e4376c91eb966d |
| 126 | 126 |
github.com/containerd/cgroups 4994991857f9b0ae8dc439551e8bebdbb4bf66c1 |
| 127 | 127 |
github.com/containerd/console c12b1e7919c14469339a5d38f2f8ed9b64a9de23 |
| 128 |
-github.com/containerd/go-runc 5a6d9f37cfa36b15efba46dc7ea349fa9b7143c3 |
|
| 129 |
-github.com/containerd/typeurl a93fcdb778cd272c6e9b3028b2f42d813e785d40 |
|
| 128 |
+github.com/containerd/go-runc 7d11b49dc0769f6dbb0d1b19f3d48524d1bad9ad |
|
| 129 |
+github.com/containerd/typeurl 2a93cfde8c20b23de8eb84a5adbc234ddf7a9e8d |
|
| 130 | 130 |
github.com/containerd/ttrpc f02858b1457c5ca3aaec3a0803eb0d59f96e41d6 |
| 131 | 131 |
github.com/gogo/googleapis 08a7655d27152912db7aaf4f983275eaf8d128ef |
| 132 | 132 |
|
| ... | ... |
@@ -140,17 +139,17 @@ golang.org/x/crypto 38d8ce5564a5b71b2e3a00553993 |
| 140 | 140 |
golang.org/x/time fbb02b2291d28baffd63558aa44b4b56f178d650 |
| 141 | 141 |
github.com/hashicorp/go-memdb cb9a474f84cc5e41b273b20c6927680b2a8776ad |
| 142 | 142 |
github.com/hashicorp/go-immutable-radix 826af9ccf0feeee615d546d69b11f8e98da8c8f1 git://github.com/tonistiigi/go-immutable-radix.git |
| 143 |
-github.com/hashicorp/golang-lru 0fb14efe8c47ae851c0034ed7a448854d3d34cf3 |
|
| 143 |
+github.com/hashicorp/golang-lru 7087cb70de9f7a8bc0a10c375cb0d2280a8edf9c # v0.5.1 |
|
| 144 | 144 |
github.com/coreos/pkg 3ac0863d7acf3bc44daf49afef8919af12f704ef # v3 |
| 145 | 145 |
github.com/pivotal-golang/clock 3fd3c1944c59d9742e1cd333672181cd1a6f9fa0 |
| 146 | 146 |
|
| 147 | 147 |
# prometheus |
| 148 | 148 |
github.com/prometheus/client_golang c5b7fccd204277076155f10851dad72b76a49317 # v0.8.0 |
| 149 |
-github.com/beorn7/perks 3a771d992973f24aa725d07868b467d1ddfceafb |
|
| 149 |
+github.com/beorn7/perks e7f67b54abbeac9c40a31de0f81159e4cafebd6a |
|
| 150 | 150 |
github.com/prometheus/client_model 6f3806018612930941127f2a7c6c453ba2c527d2 |
| 151 | 151 |
github.com/prometheus/common 7600349dcfe1abd18d72d3a1770870d9800a7801 |
| 152 | 152 |
github.com/prometheus/procfs 7d6f385de8bea29190f15ba9931442a0eaef9af7 |
| 153 |
-github.com/matttproud/golang_protobuf_extensions 3247c84500bff8d9fb6d579d800f20b3e091582c # v1.0.0 |
|
| 153 |
+github.com/matttproud/golang_protobuf_extensions c12348ce28de40eed0136aa2b644d0ee0650e56c # v1.0.1 |
|
| 154 | 154 |
github.com/pkg/errors 645ef00459ed84a119197bfb8d8205042c6df63d # v0.8.0 |
| 155 | 155 |
github.com/grpc-ecosystem/go-grpc-prometheus c225b8c3b01faf2899099b768856a9e916e5087b # v1.2.0 |
| 156 | 156 |
|
| 157 | 157 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,116 @@ |
| 0 |
+// +build go1.12 |
|
| 1 |
+ |
|
| 2 |
+/* |
|
| 3 |
+ Copyright The containerd Authors. |
|
| 4 |
+ |
|
| 5 |
+ Licensed under the Apache License, Version 2.0 (the "License"); |
|
| 6 |
+ you may not use this file except in compliance with the License. |
|
| 7 |
+ You may obtain a copy of the License at |
|
| 8 |
+ |
|
| 9 |
+ http://www.apache.org/licenses/LICENSE-2.0 |
|
| 10 |
+ |
|
| 11 |
+ Unless required by applicable law or agreed to in writing, software |
|
| 12 |
+ distributed under the License is distributed on an "AS IS" BASIS, |
|
| 13 |
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
| 14 |
+ See the License for the specific language governing permissions and |
|
| 15 |
+ limitations under the License. |
|
| 16 |
+*/ |
|
| 17 |
+ |
|
| 18 |
+package fifo |
|
| 19 |
+ |
|
| 20 |
+import ( |
|
| 21 |
+ "syscall" |
|
| 22 |
+ |
|
| 23 |
+ "github.com/pkg/errors" |
|
| 24 |
+) |
|
| 25 |
+ |
|
| 26 |
+// SyscallConn provides raw access to the fifo's underlying filedescrptor. |
|
| 27 |
+// See syscall.Conn for guarentees provided by this interface. |
|
| 28 |
+func (f *fifo) SyscallConn() (syscall.RawConn, error) {
|
|
| 29 |
+ // deterministic check for closed |
|
| 30 |
+ select {
|
|
| 31 |
+ case <-f.closed: |
|
| 32 |
+ return nil, errors.New("fifo closed")
|
|
| 33 |
+ default: |
|
| 34 |
+ } |
|
| 35 |
+ |
|
| 36 |
+ select {
|
|
| 37 |
+ case <-f.closed: |
|
| 38 |
+ return nil, errors.New("fifo closed")
|
|
| 39 |
+ case <-f.opened: |
|
| 40 |
+ return f.file.SyscallConn() |
|
| 41 |
+ default: |
|
| 42 |
+ } |
|
| 43 |
+ |
|
| 44 |
+ // Not opened and not closed, this means open is non-blocking AND it's not open yet |
|
| 45 |
+ // Use rawConn to deal with non-blocking open. |
|
| 46 |
+ rc := &rawConn{f: f, ready: make(chan struct{})}
|
|
| 47 |
+ go func() {
|
|
| 48 |
+ select {
|
|
| 49 |
+ case <-f.closed: |
|
| 50 |
+ return |
|
| 51 |
+ case <-f.opened: |
|
| 52 |
+ rc.raw, rc.err = f.file.SyscallConn() |
|
| 53 |
+ close(rc.ready) |
|
| 54 |
+ } |
|
| 55 |
+ }() |
|
| 56 |
+ |
|
| 57 |
+ return rc, nil |
|
| 58 |
+} |
|
| 59 |
+ |
|
| 60 |
+type rawConn struct {
|
|
| 61 |
+ f *fifo |
|
| 62 |
+ ready chan struct{}
|
|
| 63 |
+ raw syscall.RawConn |
|
| 64 |
+ err error |
|
| 65 |
+} |
|
| 66 |
+ |
|
| 67 |
+func (r *rawConn) Control(f func(fd uintptr)) error {
|
|
| 68 |
+ select {
|
|
| 69 |
+ case <-r.f.closed: |
|
| 70 |
+ return errors.New("control of closed fifo")
|
|
| 71 |
+ case <-r.ready: |
|
| 72 |
+ } |
|
| 73 |
+ |
|
| 74 |
+ if r.err != nil {
|
|
| 75 |
+ return r.err |
|
| 76 |
+ } |
|
| 77 |
+ |
|
| 78 |
+ return r.raw.Control(f) |
|
| 79 |
+} |
|
| 80 |
+ |
|
| 81 |
+func (r *rawConn) Read(f func(fd uintptr) (done bool)) error {
|
|
| 82 |
+ if r.f.flag&syscall.O_WRONLY > 0 {
|
|
| 83 |
+ return errors.New("reading from write-only fifo")
|
|
| 84 |
+ } |
|
| 85 |
+ |
|
| 86 |
+ select {
|
|
| 87 |
+ case <-r.f.closed: |
|
| 88 |
+ return errors.New("reading of a closed fifo")
|
|
| 89 |
+ case <-r.ready: |
|
| 90 |
+ } |
|
| 91 |
+ |
|
| 92 |
+ if r.err != nil {
|
|
| 93 |
+ return r.err |
|
| 94 |
+ } |
|
| 95 |
+ |
|
| 96 |
+ return r.raw.Read(f) |
|
| 97 |
+} |
|
| 98 |
+ |
|
| 99 |
+func (r *rawConn) Write(f func(fd uintptr) (done bool)) error {
|
|
| 100 |
+ if r.f.flag&(syscall.O_WRONLY|syscall.O_RDWR) == 0 {
|
|
| 101 |
+ return errors.New("writing to read-only fifo")
|
|
| 102 |
+ } |
|
| 103 |
+ |
|
| 104 |
+ select {
|
|
| 105 |
+ case <-r.f.closed: |
|
| 106 |
+ return errors.New("writing to a closed fifo")
|
|
| 107 |
+ case <-r.ready: |
|
| 108 |
+ } |
|
| 109 |
+ |
|
| 110 |
+ if r.err != nil {
|
|
| 111 |
+ return r.err |
|
| 112 |
+ } |
|
| 113 |
+ |
|
| 114 |
+ return r.raw.Write(f) |
|
| 115 |
+} |
| ... | ... |
@@ -1,6 +1,7 @@ |
| 1 | 1 |
### fifo |
| 2 | 2 |
|
| 3 | 3 |
[](https://travis-ci.org/containerd/fifo) |
| 4 |
+[](https://codecov.io/gh/containerd/fifo) |
|
| 4 | 5 |
|
| 5 | 6 |
Go package for handling fifos in a sane way. |
| 6 | 7 |
|
| ... | ... |
@@ -30,3 +31,14 @@ func (f *fifo) Write(b []byte) (int, error) |
| 30 | 30 |
// before open(2) has returned and fifo was never opened. |
| 31 | 31 |
func (f *fifo) Close() error |
| 32 | 32 |
``` |
| 33 |
+ |
|
| 34 |
+## Project details |
|
| 35 |
+ |
|
| 36 |
+The fifo is a containerd sub-project, licensed under the [Apache 2.0 license](./LICENSE). |
|
| 37 |
+As a containerd sub-project, you will find the: |
|
| 38 |
+ |
|
| 39 |
+ * [Project governance](https://github.com/containerd/project/blob/master/GOVERNANCE.md), |
|
| 40 |
+ * [Maintainers](https://github.com/containerd/project/blob/master/MAINTAINERS), |
|
| 41 |
+ * and [Contributing guidelines](https://github.com/containerd/project/blob/master/CONTRIBUTING.md) |
|
| 42 |
+ |
|
| 43 |
+information in our [`containerd/project`](https://github.com/containerd/project) repository. |
| ... | ... |
@@ -1,7 +1,7 @@ |
| 1 | 1 |
# go-runc |
| 2 | 2 |
|
| 3 | 3 |
[](https://travis-ci.org/containerd/go-runc) |
| 4 |
- |
|
| 4 |
+[](https://codecov.io/gh/containerd/go-runc) |
|
| 5 | 5 |
|
| 6 | 6 |
This is a package for consuming the [runc](https://github.com/opencontainers/runc) binary in your Go applications. |
| 7 | 7 |
It tries to expose all the settings and features of the runc CLI. If there is something missing then add it, its opensource! |
| ... | ... |
@@ -12,3 +12,14 @@ or greater. |
| 12 | 12 |
## Docs |
| 13 | 13 |
|
| 14 | 14 |
Docs can be found at [godoc.org](https://godoc.org/github.com/containerd/go-runc). |
| 15 |
+ |
|
| 16 |
+## Project details |
|
| 17 |
+ |
|
| 18 |
+The go-runc is a containerd sub-project, licensed under the [Apache 2.0 license](./LICENSE). |
|
| 19 |
+As a containerd sub-project, you will find the: |
|
| 20 |
+ |
|
| 21 |
+ * [Project governance](https://github.com/containerd/project/blob/master/GOVERNANCE.md), |
|
| 22 |
+ * [Maintainers](https://github.com/containerd/project/blob/master/MAINTAINERS), |
|
| 23 |
+ * and [Contributing guidelines](https://github.com/containerd/project/blob/master/CONTRIBUTING.md) |
|
| 24 |
+ |
|
| 25 |
+information in our [`containerd/project`](https://github.com/containerd/project) repository. |
| ... | ... |
@@ -1,6 +1,7 @@ |
| 1 |
+ |
|
| 1 | 2 |
Apache License |
| 2 | 3 |
Version 2.0, January 2004 |
| 3 |
- http://www.apache.org/licenses/ |
|
| 4 |
+ https://www.apache.org/licenses/ |
|
| 4 | 5 |
|
| 5 | 6 |
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION |
| 6 | 7 |
|
| ... | ... |
@@ -175,24 +176,13 @@ |
| 175 | 175 |
|
| 176 | 176 |
END OF TERMS AND CONDITIONS |
| 177 | 177 |
|
| 178 |
- APPENDIX: How to apply the Apache License to your work. |
|
| 179 |
- |
|
| 180 |
- To apply the Apache License to your work, attach the following |
|
| 181 |
- boilerplate notice, with the fields enclosed by brackets "[]" |
|
| 182 |
- replaced with your own identifying information. (Don't include |
|
| 183 |
- the brackets!) The text should be enclosed in the appropriate |
|
| 184 |
- comment syntax for the file format. We also recommend that a |
|
| 185 |
- file or class name and description of purpose be included on the |
|
| 186 |
- same "printed page" as the copyright notice for easier |
|
| 187 |
- identification within third-party archives. |
|
| 188 |
- |
|
| 189 |
- Copyright [yyyy] [name of copyright owner] |
|
| 178 |
+ Copyright The containerd Authors |
|
| 190 | 179 |
|
| 191 | 180 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 192 | 181 |
you may not use this file except in compliance with the License. |
| 193 | 182 |
You may obtain a copy of the License at |
| 194 | 183 |
|
| 195 |
- http://www.apache.org/licenses/LICENSE-2.0 |
|
| 184 |
+ https://www.apache.org/licenses/LICENSE-2.0 |
|
| 196 | 185 |
|
| 197 | 186 |
Unless required by applicable law or agreed to in writing, software |
| 198 | 187 |
distributed under the License is distributed on an "AS IS" BASIS, |
| ... | ... |
@@ -7,3 +7,13 @@ |
| 7 | 7 |
A Go package for managing the registration, marshaling, and unmarshaling of encoded types. |
| 8 | 8 |
|
| 9 | 9 |
This package helps when types are sent over a GRPC API and marshaled as a [protobuf.Any](). |
| 10 |
+ |
|
| 11 |
+## Project details |
|
| 12 |
+ |
|
| 13 |
+**typeurl** is a containerd sub-project, licensed under the [Apache 2.0 license](./LICENSE). |
|
| 14 |
+As a containerd sub-project, you will find the: |
|
| 15 |
+ * [Project governance](https://github.com/containerd/project/blob/master/GOVERNANCE.md), |
|
| 16 |
+ * [Maintainers](https://github.com/containerd/project/blob/master/MAINTAINERS), |
|
| 17 |
+ * and [Contributing guidelines](https://github.com/containerd/project/blob/master/CONTRIBUTING.md) |
|
| 18 |
+ |
|
| 19 |
+information in our [`containerd/project`](https://github.com/containerd/project) repository. |
| 10 | 20 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,83 @@ |
| 0 |
+/* |
|
| 1 |
+ Copyright The containerd Authors. |
|
| 2 |
+ |
|
| 3 |
+ Licensed under the Apache License, Version 2.0 (the "License"); |
|
| 4 |
+ you may not use this file except in compliance with the License. |
|
| 5 |
+ You may obtain a copy of the License at |
|
| 6 |
+ |
|
| 7 |
+ http://www.apache.org/licenses/LICENSE-2.0 |
|
| 8 |
+ |
|
| 9 |
+ Unless required by applicable law or agreed to in writing, software |
|
| 10 |
+ distributed under the License is distributed on an "AS IS" BASIS, |
|
| 11 |
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
| 12 |
+ See the License for the specific language governing permissions and |
|
| 13 |
+ limitations under the License. |
|
| 14 |
+*/ |
|
| 15 |
+ |
|
| 16 |
+package typeurl |
|
| 17 |
+ |
|
| 18 |
+// Package typeurl assists with managing the registration, marshaling, and |
|
| 19 |
+// unmarshaling of types encoded as protobuf.Any. |
|
| 20 |
+// |
|
| 21 |
+// A protobuf.Any is a proto message that can contain any arbitrary data. It |
|
| 22 |
+// consists of two components, a TypeUrl and a Value, and its proto definition |
|
| 23 |
+// looks like this: |
|
| 24 |
+// |
|
| 25 |
+// message Any {
|
|
| 26 |
+// string type_url = 1; |
|
| 27 |
+// bytes value = 2; |
|
| 28 |
+// } |
|
| 29 |
+// |
|
| 30 |
+// The TypeUrl is used to distinguish the contents from other proto.Any |
|
| 31 |
+// messages. This typeurl library manages these URLs to enable automagic |
|
| 32 |
+// marshaling and unmarshaling of the contents. |
|
| 33 |
+// |
|
| 34 |
+// For example, consider this go struct: |
|
| 35 |
+// |
|
| 36 |
+// type Foo struct {
|
|
| 37 |
+// Field1 string |
|
| 38 |
+// Field2 string |
|
| 39 |
+// } |
|
| 40 |
+// |
|
| 41 |
+// To use typeurl, types must first be registered. This is typically done in |
|
| 42 |
+// the init function |
|
| 43 |
+// |
|
| 44 |
+// func init() {
|
|
| 45 |
+// typeurl.Register(&Foo{}, "Foo")
|
|
| 46 |
+// } |
|
| 47 |
+// |
|
| 48 |
+// This will register the type Foo with the url path "Foo". The arguments to |
|
| 49 |
+// Register are variadic, and are used to construct a url path. Consider this |
|
| 50 |
+// example, from the github.com/containerd/containerd/client package: |
|
| 51 |
+// |
|
| 52 |
+// func init() {
|
|
| 53 |
+// const prefix = "types.containerd.io" |
|
| 54 |
+// // register TypeUrls for commonly marshaled external types |
|
| 55 |
+// major := strconv.Itoa(specs.VersionMajor) |
|
| 56 |
+// typeurl.Register(&specs.Spec{}, prefix, "opencontainers/runtime-spec", major, "Spec")
|
|
| 57 |
+// // this function has more Register calls, which are elided. |
|
| 58 |
+// } |
|
| 59 |
+// |
|
| 60 |
+// This registers several types under a more complex url, which ends up mapping |
|
| 61 |
+// to `types.containerd.io/opencontainers/runtime-spec/1/Spec` (or some other |
|
| 62 |
+// value for major). |
|
| 63 |
+// |
|
| 64 |
+// Once a type is registered, it can be marshaled to a proto.Any message simply |
|
| 65 |
+// by calling `MarshalAny`, like this: |
|
| 66 |
+// |
|
| 67 |
+// foo := &Foo{Field1: "value1", Field2: "value2"}
|
|
| 68 |
+// anyFoo, err := typeurl.MarshalAny(foo) |
|
| 69 |
+// |
|
| 70 |
+// MarshalAny will resolve the correct URL for the type. If the type in |
|
| 71 |
+// question implements the proto.Message interface, then it will be marshaled |
|
| 72 |
+// as a proto message. Otherwise, it will be marshaled as json. This means that |
|
| 73 |
+// typeurl will work on any arbitrary data, whether or not it has a proto |
|
| 74 |
+// definition, as long as it can be serialized to json. |
|
| 75 |
+// |
|
| 76 |
+// To unmarshal, the process is simply inverse: |
|
| 77 |
+// |
|
| 78 |
+// iface, err := typeurl.UnmarshalAny(anyFoo) |
|
| 79 |
+// foo := iface.(*Foo) |
|
| 80 |
+// |
|
| 81 |
+// The correct type is automatically chosen from the type registry, and the |
|
| 82 |
+// returned interface can be cast straight to that type. |
| ... | ... |
@@ -78,7 +78,10 @@ func Is(any *types.Any, v interface{}) bool {
|
| 78 | 78 |
return any.TypeUrl == url |
| 79 | 79 |
} |
| 80 | 80 |
|
| 81 |
-// MarshalAny marshals the value v into an any with the correct TypeUrl |
|
| 81 |
+// MarshalAny marshals the value v into an any with the correct TypeUrl. |
|
| 82 |
+// If the provided object is already a proto.Any message, then it will be |
|
| 83 |
+// returned verbatim. If it is of type proto.Message, it will be marshaled as a |
|
| 84 |
+// protocol buffer. Otherwise, the object will be marshaled to json. |
|
| 82 | 85 |
func MarshalAny(v interface{}) (*types.Any, error) {
|
| 83 | 86 |
var marshal func(v interface{}) ([]byte, error)
|
| 84 | 87 |
switch t := v.(type) {
|
| ... | ... |
@@ -1,37 +1,36 @@ |
| 1 | 1 |
package simplelru |
| 2 | 2 |
|
| 3 |
- |
|
| 4 | 3 |
// LRUCache is the interface for simple LRU cache. |
| 5 | 4 |
type LRUCache interface {
|
| 6 |
- // Adds a value to the cache, returns true if an eviction occurred and |
|
| 7 |
- // updates the "recently used"-ness of the key. |
|
| 8 |
- Add(key, value interface{}) bool
|
|
| 5 |
+ // Adds a value to the cache, returns true if an eviction occurred and |
|
| 6 |
+ // updates the "recently used"-ness of the key. |
|
| 7 |
+ Add(key, value interface{}) bool
|
|
| 9 | 8 |
|
| 10 |
- // Returns key's value from the cache and |
|
| 11 |
- // updates the "recently used"-ness of the key. #value, isFound |
|
| 12 |
- Get(key interface{}) (value interface{}, ok bool)
|
|
| 9 |
+ // Returns key's value from the cache and |
|
| 10 |
+ // updates the "recently used"-ness of the key. #value, isFound |
|
| 11 |
+ Get(key interface{}) (value interface{}, ok bool)
|
|
| 13 | 12 |
|
| 14 |
- // Check if a key exsists in cache without updating the recent-ness. |
|
| 15 |
- Contains(key interface{}) (ok bool)
|
|
| 13 |
+ // Check if a key exsists in cache without updating the recent-ness. |
|
| 14 |
+ Contains(key interface{}) (ok bool)
|
|
| 16 | 15 |
|
| 17 |
- // Returns key's value without updating the "recently used"-ness of the key. |
|
| 18 |
- Peek(key interface{}) (value interface{}, ok bool)
|
|
| 16 |
+ // Returns key's value without updating the "recently used"-ness of the key. |
|
| 17 |
+ Peek(key interface{}) (value interface{}, ok bool)
|
|
| 19 | 18 |
|
| 20 |
- // Removes a key from the cache. |
|
| 21 |
- Remove(key interface{}) bool
|
|
| 19 |
+ // Removes a key from the cache. |
|
| 20 |
+ Remove(key interface{}) bool
|
|
| 22 | 21 |
|
| 23 |
- // Removes the oldest entry from cache. |
|
| 24 |
- RemoveOldest() (interface{}, interface{}, bool)
|
|
| 22 |
+ // Removes the oldest entry from cache. |
|
| 23 |
+ RemoveOldest() (interface{}, interface{}, bool)
|
|
| 25 | 24 |
|
| 26 |
- // Returns the oldest entry from the cache. #key, value, isFound |
|
| 27 |
- GetOldest() (interface{}, interface{}, bool)
|
|
| 25 |
+ // Returns the oldest entry from the cache. #key, value, isFound |
|
| 26 |
+ GetOldest() (interface{}, interface{}, bool)
|
|
| 28 | 27 |
|
| 29 |
- // Returns a slice of the keys in the cache, from oldest to newest. |
|
| 30 |
- Keys() []interface{}
|
|
| 28 |
+ // Returns a slice of the keys in the cache, from oldest to newest. |
|
| 29 |
+ Keys() []interface{}
|
|
| 31 | 30 |
|
| 32 |
- // Returns the number of items in the cache. |
|
| 33 |
- Len() int |
|
| 31 |
+ // Returns the number of items in the cache. |
|
| 32 |
+ Len() int |
|
| 34 | 33 |
|
| 35 |
- // Clear all cache entries |
|
| 36 |
- Purge() |
|
| 34 |
+ // Clear all cache entries |
|
| 35 |
+ Purge() |
|
| 37 | 36 |
} |
| ... | ... |
@@ -11,7 +11,7 @@ import ( |
| 11 | 11 |
"strconv" |
| 12 | 12 |
"strings" |
| 13 | 13 |
|
| 14 |
- "github.com/pborman/uuid" |
|
| 14 |
+ "github.com/google/uuid" |
|
| 15 | 15 |
) |
| 16 | 16 |
|
| 17 | 17 |
type command struct {
|
| ... | ... |
@@ -38,7 +38,7 @@ func (c *command) Run(arg ...string) ([][]string, error) {
|
| 38 | 38 |
} |
| 39 | 39 |
cmd.Stderr = &stderr |
| 40 | 40 |
|
| 41 |
- id := uuid.New() |
|
| 41 |
+ id := uuid.New().String() |
|
| 42 | 42 |
joinedArgs := strings.Join(cmd.Args, " ") |
| 43 | 43 |
|
| 44 | 44 |
logger.Log([]string{"ID:" + id, "START", joinedArgs})
|
| ... | ... |
@@ -48,7 +48,7 @@ func (c *command) Run(arg ...string) ([][]string, error) {
|
| 48 | 48 |
if err != nil {
|
| 49 | 49 |
return nil, &Error{
|
| 50 | 50 |
Err: err, |
| 51 |
- Debug: strings.Join([]string{cmd.Path, joinedArgs}, " "),
|
|
| 51 |
+ Debug: strings.Join([]string{cmd.Path, joinedArgs[1:]}, " "),
|
|
| 52 | 52 |
Stderr: stderr.String(), |
| 53 | 53 |
} |
| 54 | 54 |
} |
| ... | ... |
@@ -118,20 +118,24 @@ func (ds *Dataset) parseLine(line []string) error {
|
| 118 | 118 |
if err = setUint(&ds.Quota, line[8]); err != nil {
|
| 119 | 119 |
return err |
| 120 | 120 |
} |
| 121 |
+ if err = setUint(&ds.Referenced, line[9]); err != nil {
|
|
| 122 |
+ return err |
|
| 123 |
+ } |
|
| 121 | 124 |
|
| 122 | 125 |
if runtime.GOOS == "solaris" {
|
| 123 | 126 |
return nil |
| 124 | 127 |
} |
| 125 | 128 |
|
| 126 |
- if err = setUint(&ds.Written, line[9]); err != nil {
|
|
| 129 |
+ if err = setUint(&ds.Written, line[10]); err != nil {
|
|
| 127 | 130 |
return err |
| 128 | 131 |
} |
| 129 |
- if err = setUint(&ds.Logicalused, line[10]); err != nil {
|
|
| 132 |
+ if err = setUint(&ds.Logicalused, line[11]); err != nil {
|
|
| 130 | 133 |
return err |
| 131 | 134 |
} |
| 132 |
- if err = setUint(&ds.Usedbydataset, line[11]); err != nil {
|
|
| 135 |
+ if err = setUint(&ds.Usedbydataset, line[12]); err != nil {
|
|
| 133 | 136 |
return err |
| 134 | 137 |
} |
| 138 |
+ |
|
| 135 | 139 |
return nil |
| 136 | 140 |
} |
| 137 | 141 |
|
| ... | ... |
@@ -337,7 +341,11 @@ func (z *Zpool) parseLine(line []string) error {
|
| 337 | 337 |
err = setUint(&z.Free, val) |
| 338 | 338 |
case "fragmentation": |
| 339 | 339 |
// Trim trailing "%" before parsing uint |
| 340 |
- err = setUint(&z.Fragmentation, val[:len(val)-1]) |
|
| 340 |
+ i := strings.Index(val, "%") |
|
| 341 |
+ if i < 0 {
|
|
| 342 |
+ i = len(val) |
|
| 343 |
+ } |
|
| 344 |
+ err = setUint(&z.Fragmentation, val[:i]) |
|
| 341 | 345 |
case "readonly": |
| 342 | 346 |
z.ReadOnly = val == "on" |
| 343 | 347 |
case "freeing": |
| ... | ... |
@@ -7,7 +7,7 @@ import ( |
| 7 | 7 |
) |
| 8 | 8 |
|
| 9 | 9 |
// List of ZFS properties to retrieve from zfs list command on a non-Solaris platform |
| 10 |
-var dsPropList = []string{"name", "origin", "used", "available", "mountpoint", "compression", "type", "volsize", "quota", "written", "logicalused", "usedbydataset"}
|
|
| 10 |
+var dsPropList = []string{"name", "origin", "used", "available", "mountpoint", "compression", "type", "volsize", "quota", "referenced", "written", "logicalused", "usedbydataset"}
|
|
| 11 | 11 |
|
| 12 | 12 |
var dsPropListOptions = strings.Join(dsPropList, ",") |
| 13 | 13 |
|
| ... | ... |
@@ -7,7 +7,7 @@ import ( |
| 7 | 7 |
) |
| 8 | 8 |
|
| 9 | 9 |
// List of ZFS properties to retrieve from zfs list command on a Solaris platform |
| 10 |
-var dsPropList = []string{"name", "origin", "used", "available", "mountpoint", "compression", "type", "volsize", "quota"}
|
|
| 10 |
+var dsPropList = []string{"name", "origin", "used", "available", "mountpoint", "compression", "type", "volsize", "quota", "referenced"}
|
|
| 11 | 11 |
|
| 12 | 12 |
var dsPropListOptions = strings.Join(dsPropList, ",") |
| 13 | 13 |
|
| ... | ... |
@@ -35,6 +35,7 @@ type Dataset struct {
|
| 35 | 35 |
Logicalused uint64 |
| 36 | 36 |
Usedbydataset uint64 |
| 37 | 37 |
Quota uint64 |
| 38 |
+ Referenced uint64 |
|
| 38 | 39 |
} |
| 39 | 40 |
|
| 40 | 41 |
// InodeType is the type of inode as reported by Diff |
| ... | ... |
@@ -307,7 +308,7 @@ func (d *Dataset) SetProperty(key, val string) error {
|
| 307 | 307 |
// A full list of available ZFS properties may be found here: |
| 308 | 308 |
// https://www.freebsd.org/cgi/man.cgi?zfs(8). |
| 309 | 309 |
func (d *Dataset) GetProperty(key string) (string, error) {
|
| 310 |
- out, err := zfs("get", key, d.Name)
|
|
| 310 |
+ out, err := zfs("get", "-H", key, d.Name)
|
|
| 311 | 311 |
if err != nil {
|
| 312 | 312 |
return "", err |
| 313 | 313 |
} |
| 314 | 314 |
deleted file mode 100644 |
| ... | ... |
@@ -1,27 +0,0 @@ |
| 1 |
-Copyright (c) 2009,2014 Google Inc. 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 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,13 +0,0 @@ |
| 1 |
-This project was automatically exported from code.google.com/p/go-uuid |
|
| 2 |
- |
|
| 3 |
-# uuid  |
|
| 4 |
-The uuid package generates and inspects UUIDs based on [RFC 412](http://tools.ietf.org/html/rfc4122) and DCE 1.1: Authentication and Security Services. |
|
| 5 |
- |
|
| 6 |
-###### Install |
|
| 7 |
-`go get github.com/pborman/uuid` |
|
| 8 |
- |
|
| 9 |
-###### Documentation |
|
| 10 |
-[](http://godoc.org/github.com/pborman/uuid) |
|
| 11 |
- |
|
| 12 |
-Full `go doc` style documentation for the package can be viewed online without installing this package by using the GoDoc site here: |
|
| 13 |
-http://godoc.org/github.com/pborman/uuid |
| 14 | 1 |
deleted file mode 100755 |
| ... | ... |
@@ -1,84 +0,0 @@ |
| 1 |
-// Copyright 2011 Google Inc. 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 uuid |
|
| 6 |
- |
|
| 7 |
-import ( |
|
| 8 |
- "encoding/binary" |
|
| 9 |
- "fmt" |
|
| 10 |
- "os" |
|
| 11 |
-) |
|
| 12 |
- |
|
| 13 |
-// A Domain represents a Version 2 domain |
|
| 14 |
-type Domain byte |
|
| 15 |
- |
|
| 16 |
-// Domain constants for DCE Security (Version 2) UUIDs. |
|
| 17 |
-const ( |
|
| 18 |
- Person = Domain(0) |
|
| 19 |
- Group = Domain(1) |
|
| 20 |
- Org = Domain(2) |
|
| 21 |
-) |
|
| 22 |
- |
|
| 23 |
-// NewDCESecurity returns a DCE Security (Version 2) UUID. |
|
| 24 |
-// |
|
| 25 |
-// The domain should be one of Person, Group or Org. |
|
| 26 |
-// On a POSIX system the id should be the users UID for the Person |
|
| 27 |
-// domain and the users GID for the Group. The meaning of id for |
|
| 28 |
-// the domain Org or on non-POSIX systems is site defined. |
|
| 29 |
-// |
|
| 30 |
-// For a given domain/id pair the same token may be returned for up to |
|
| 31 |
-// 7 minutes and 10 seconds. |
|
| 32 |
-func NewDCESecurity(domain Domain, id uint32) UUID {
|
|
| 33 |
- uuid := NewUUID() |
|
| 34 |
- if uuid != nil {
|
|
| 35 |
- uuid[6] = (uuid[6] & 0x0f) | 0x20 // Version 2 |
|
| 36 |
- uuid[9] = byte(domain) |
|
| 37 |
- binary.BigEndian.PutUint32(uuid[0:], id) |
|
| 38 |
- } |
|
| 39 |
- return uuid |
|
| 40 |
-} |
|
| 41 |
- |
|
| 42 |
-// NewDCEPerson returns a DCE Security (Version 2) UUID in the person |
|
| 43 |
-// domain with the id returned by os.Getuid. |
|
| 44 |
-// |
|
| 45 |
-// NewDCEPerson(Person, uint32(os.Getuid())) |
|
| 46 |
-func NewDCEPerson() UUID {
|
|
| 47 |
- return NewDCESecurity(Person, uint32(os.Getuid())) |
|
| 48 |
-} |
|
| 49 |
- |
|
| 50 |
-// NewDCEGroup returns a DCE Security (Version 2) UUID in the group |
|
| 51 |
-// domain with the id returned by os.Getgid. |
|
| 52 |
-// |
|
| 53 |
-// NewDCEGroup(Group, uint32(os.Getgid())) |
|
| 54 |
-func NewDCEGroup() UUID {
|
|
| 55 |
- return NewDCESecurity(Group, uint32(os.Getgid())) |
|
| 56 |
-} |
|
| 57 |
- |
|
| 58 |
-// Domain returns the domain for a Version 2 UUID or false. |
|
| 59 |
-func (uuid UUID) Domain() (Domain, bool) {
|
|
| 60 |
- if v, _ := uuid.Version(); v != 2 {
|
|
| 61 |
- return 0, false |
|
| 62 |
- } |
|
| 63 |
- return Domain(uuid[9]), true |
|
| 64 |
-} |
|
| 65 |
- |
|
| 66 |
-// Id returns the id for a Version 2 UUID or false. |
|
| 67 |
-func (uuid UUID) Id() (uint32, bool) {
|
|
| 68 |
- if v, _ := uuid.Version(); v != 2 {
|
|
| 69 |
- return 0, false |
|
| 70 |
- } |
|
| 71 |
- return binary.BigEndian.Uint32(uuid[0:4]), true |
|
| 72 |
-} |
|
| 73 |
- |
|
| 74 |
-func (d Domain) String() string {
|
|
| 75 |
- switch d {
|
|
| 76 |
- case Person: |
|
| 77 |
- return "Person" |
|
| 78 |
- case Group: |
|
| 79 |
- return "Group" |
|
| 80 |
- case Org: |
|
| 81 |
- return "Org" |
|
| 82 |
- } |
|
| 83 |
- return fmt.Sprintf("Domain%d", int(d))
|
|
| 84 |
-} |
| 85 | 1 |
deleted file mode 100755 |
| ... | ... |
@@ -1,8 +0,0 @@ |
| 1 |
-// Copyright 2011 Google Inc. 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 |
-// The uuid package generates and inspects UUIDs. |
|
| 6 |
-// |
|
| 7 |
-// UUIDs are based on RFC 4122 and DCE 1.1: Authentication and Security Services. |
|
| 8 |
-package uuid |
| 9 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,53 +0,0 @@ |
| 1 |
-// Copyright 2011 Google Inc. 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 uuid |
|
| 6 |
- |
|
| 7 |
-import ( |
|
| 8 |
- "crypto/md5" |
|
| 9 |
- "crypto/sha1" |
|
| 10 |
- "hash" |
|
| 11 |
-) |
|
| 12 |
- |
|
| 13 |
-// Well known Name Space IDs and UUIDs |
|
| 14 |
-var ( |
|
| 15 |
- NameSpace_DNS = Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
|
|
| 16 |
- NameSpace_URL = Parse("6ba7b811-9dad-11d1-80b4-00c04fd430c8")
|
|
| 17 |
- NameSpace_OID = Parse("6ba7b812-9dad-11d1-80b4-00c04fd430c8")
|
|
| 18 |
- NameSpace_X500 = Parse("6ba7b814-9dad-11d1-80b4-00c04fd430c8")
|
|
| 19 |
- NIL = Parse("00000000-0000-0000-0000-000000000000")
|
|
| 20 |
-) |
|
| 21 |
- |
|
| 22 |
-// NewHash returns a new UUID derived from the hash of space concatenated with |
|
| 23 |
-// data generated by h. The hash should be at least 16 byte in length. The |
|
| 24 |
-// first 16 bytes of the hash are used to form the UUID. The version of the |
|
| 25 |
-// UUID will be the lower 4 bits of version. NewHash is used to implement |
|
| 26 |
-// NewMD5 and NewSHA1. |
|
| 27 |
-func NewHash(h hash.Hash, space UUID, data []byte, version int) UUID {
|
|
| 28 |
- h.Reset() |
|
| 29 |
- h.Write(space) |
|
| 30 |
- h.Write([]byte(data)) |
|
| 31 |
- s := h.Sum(nil) |
|
| 32 |
- uuid := make([]byte, 16) |
|
| 33 |
- copy(uuid, s) |
|
| 34 |
- uuid[6] = (uuid[6] & 0x0f) | uint8((version&0xf)<<4) |
|
| 35 |
- uuid[8] = (uuid[8] & 0x3f) | 0x80 // RFC 4122 variant |
|
| 36 |
- return uuid |
|
| 37 |
-} |
|
| 38 |
- |
|
| 39 |
-// NewMD5 returns a new MD5 (Version 3) UUID based on the |
|
| 40 |
-// supplied name space and data. |
|
| 41 |
-// |
|
| 42 |
-// NewHash(md5.New(), space, data, 3) |
|
| 43 |
-func NewMD5(space UUID, data []byte) UUID {
|
|
| 44 |
- return NewHash(md5.New(), space, data, 3) |
|
| 45 |
-} |
|
| 46 |
- |
|
| 47 |
-// NewSHA1 returns a new SHA1 (Version 5) UUID based on the |
|
| 48 |
-// supplied name space and data. |
|
| 49 |
-// |
|
| 50 |
-// NewHash(sha1.New(), space, data, 5) |
|
| 51 |
-func NewSHA1(space UUID, data []byte) UUID {
|
|
| 52 |
- return NewHash(sha1.New(), space, data, 5) |
|
| 53 |
-} |
| 54 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,34 +0,0 @@ |
| 1 |
-// Copyright 2014 Google Inc. 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 uuid |
|
| 6 |
- |
|
| 7 |
-import "errors" |
|
| 8 |
- |
|
| 9 |
-func (u UUID) MarshalJSON() ([]byte, error) {
|
|
| 10 |
- if len(u) != 16 {
|
|
| 11 |
- return []byte(`""`), nil |
|
| 12 |
- } |
|
| 13 |
- var js [38]byte |
|
| 14 |
- js[0] = '"' |
|
| 15 |
- encodeHex(js[1:], u) |
|
| 16 |
- js[37] = '"' |
|
| 17 |
- return js[:], nil |
|
| 18 |
-} |
|
| 19 |
- |
|
| 20 |
-func (u *UUID) UnmarshalJSON(data []byte) error {
|
|
| 21 |
- if string(data) == `""` {
|
|
| 22 |
- return nil |
|
| 23 |
- } |
|
| 24 |
- if data[0] != '"' {
|
|
| 25 |
- return errors.New("invalid UUID format")
|
|
| 26 |
- } |
|
| 27 |
- data = data[1 : len(data)-1] |
|
| 28 |
- uu := Parse(string(data)) |
|
| 29 |
- if uu == nil {
|
|
| 30 |
- return errors.New("invalid UUID format")
|
|
| 31 |
- } |
|
| 32 |
- *u = uu |
|
| 33 |
- return nil |
|
| 34 |
-} |
| 35 | 1 |
deleted file mode 100755 |
| ... | ... |
@@ -1,117 +0,0 @@ |
| 1 |
-// Copyright 2011 Google Inc. 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 uuid |
|
| 6 |
- |
|
| 7 |
-import ( |
|
| 8 |
- "net" |
|
| 9 |
- "sync" |
|
| 10 |
-) |
|
| 11 |
- |
|
| 12 |
-var ( |
|
| 13 |
- nodeMu sync.Mutex |
|
| 14 |
- interfaces []net.Interface // cached list of interfaces |
|
| 15 |
- ifname string // name of interface being used |
|
| 16 |
- nodeID []byte // hardware for version 1 UUIDs |
|
| 17 |
-) |
|
| 18 |
- |
|
| 19 |
-// NodeInterface returns the name of the interface from which the NodeID was |
|
| 20 |
-// derived. The interface "user" is returned if the NodeID was set by |
|
| 21 |
-// SetNodeID. |
|
| 22 |
-func NodeInterface() string {
|
|
| 23 |
- defer nodeMu.Unlock() |
|
| 24 |
- nodeMu.Lock() |
|
| 25 |
- return ifname |
|
| 26 |
-} |
|
| 27 |
- |
|
| 28 |
-// SetNodeInterface selects the hardware address to be used for Version 1 UUIDs. |
|
| 29 |
-// If name is "" then the first usable interface found will be used or a random |
|
| 30 |
-// Node ID will be generated. If a named interface cannot be found then false |
|
| 31 |
-// is returned. |
|
| 32 |
-// |
|
| 33 |
-// SetNodeInterface never fails when name is "". |
|
| 34 |
-func SetNodeInterface(name string) bool {
|
|
| 35 |
- defer nodeMu.Unlock() |
|
| 36 |
- nodeMu.Lock() |
|
| 37 |
- return setNodeInterface(name) |
|
| 38 |
-} |
|
| 39 |
- |
|
| 40 |
-func setNodeInterface(name string) bool {
|
|
| 41 |
- if interfaces == nil {
|
|
| 42 |
- var err error |
|
| 43 |
- interfaces, err = net.Interfaces() |
|
| 44 |
- if err != nil && name != "" {
|
|
| 45 |
- return false |
|
| 46 |
- } |
|
| 47 |
- } |
|
| 48 |
- |
|
| 49 |
- for _, ifs := range interfaces {
|
|
| 50 |
- if len(ifs.HardwareAddr) >= 6 && (name == "" || name == ifs.Name) {
|
|
| 51 |
- if setNodeID(ifs.HardwareAddr) {
|
|
| 52 |
- ifname = ifs.Name |
|
| 53 |
- return true |
|
| 54 |
- } |
|
| 55 |
- } |
|
| 56 |
- } |
|
| 57 |
- |
|
| 58 |
- // We found no interfaces with a valid hardware address. If name |
|
| 59 |
- // does not specify a specific interface generate a random Node ID |
|
| 60 |
- // (section 4.1.6) |
|
| 61 |
- if name == "" {
|
|
| 62 |
- if nodeID == nil {
|
|
| 63 |
- nodeID = make([]byte, 6) |
|
| 64 |
- } |
|
| 65 |
- randomBits(nodeID) |
|
| 66 |
- return true |
|
| 67 |
- } |
|
| 68 |
- return false |
|
| 69 |
-} |
|
| 70 |
- |
|
| 71 |
-// NodeID returns a slice of a copy of the current Node ID, setting the Node ID |
|
| 72 |
-// if not already set. |
|
| 73 |
-func NodeID() []byte {
|
|
| 74 |
- defer nodeMu.Unlock() |
|
| 75 |
- nodeMu.Lock() |
|
| 76 |
- if nodeID == nil {
|
|
| 77 |
- setNodeInterface("")
|
|
| 78 |
- } |
|
| 79 |
- nid := make([]byte, 6) |
|
| 80 |
- copy(nid, nodeID) |
|
| 81 |
- return nid |
|
| 82 |
-} |
|
| 83 |
- |
|
| 84 |
-// SetNodeID sets the Node ID to be used for Version 1 UUIDs. The first 6 bytes |
|
| 85 |
-// of id are used. If id is less than 6 bytes then false is returned and the |
|
| 86 |
-// Node ID is not set. |
|
| 87 |
-func SetNodeID(id []byte) bool {
|
|
| 88 |
- defer nodeMu.Unlock() |
|
| 89 |
- nodeMu.Lock() |
|
| 90 |
- if setNodeID(id) {
|
|
| 91 |
- ifname = "user" |
|
| 92 |
- return true |
|
| 93 |
- } |
|
| 94 |
- return false |
|
| 95 |
-} |
|
| 96 |
- |
|
| 97 |
-func setNodeID(id []byte) bool {
|
|
| 98 |
- if len(id) < 6 {
|
|
| 99 |
- return false |
|
| 100 |
- } |
|
| 101 |
- if nodeID == nil {
|
|
| 102 |
- nodeID = make([]byte, 6) |
|
| 103 |
- } |
|
| 104 |
- copy(nodeID, id) |
|
| 105 |
- return true |
|
| 106 |
-} |
|
| 107 |
- |
|
| 108 |
-// NodeID returns the 6 byte node id encoded in uuid. It returns nil if uuid is |
|
| 109 |
-// not valid. The NodeID is only well defined for version 1 and 2 UUIDs. |
|
| 110 |
-func (uuid UUID) NodeID() []byte {
|
|
| 111 |
- if len(uuid) != 16 {
|
|
| 112 |
- return nil |
|
| 113 |
- } |
|
| 114 |
- node := make([]byte, 6) |
|
| 115 |
- copy(node, uuid[10:]) |
|
| 116 |
- return node |
|
| 117 |
-} |
| 118 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,58 +0,0 @@ |
| 1 |
-// Copyright 2015 Google Inc. 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 uuid |
|
| 6 |
- |
|
| 7 |
-import ( |
|
| 8 |
- "errors" |
|
| 9 |
- "fmt" |
|
| 10 |
-) |
|
| 11 |
- |
|
| 12 |
-// Scan implements sql.Scanner so UUIDs can be read from databases transparently |
|
| 13 |
-// Currently, database types that map to string and []byte are supported. Please |
|
| 14 |
-// consult database-specific driver documentation for matching types. |
|
| 15 |
-func (uuid *UUID) Scan(src interface{}) error {
|
|
| 16 |
- switch src.(type) {
|
|
| 17 |
- case string: |
|
| 18 |
- // if an empty UUID comes from a table, we return a null UUID |
|
| 19 |
- if src.(string) == "" {
|
|
| 20 |
- return nil |
|
| 21 |
- } |
|
| 22 |
- |
|
| 23 |
- // see uuid.Parse for required string format |
|
| 24 |
- parsed := Parse(src.(string)) |
|
| 25 |
- |
|
| 26 |
- if parsed == nil {
|
|
| 27 |
- return errors.New("Scan: invalid UUID format")
|
|
| 28 |
- } |
|
| 29 |
- |
|
| 30 |
- *uuid = parsed |
|
| 31 |
- case []byte: |
|
| 32 |
- b := src.([]byte) |
|
| 33 |
- |
|
| 34 |
- // if an empty UUID comes from a table, we return a null UUID |
|
| 35 |
- if len(b) == 0 {
|
|
| 36 |
- return nil |
|
| 37 |
- } |
|
| 38 |
- |
|
| 39 |
- // assumes a simple slice of bytes if 16 bytes |
|
| 40 |
- // otherwise attempts to parse |
|
| 41 |
- if len(b) == 16 {
|
|
| 42 |
- *uuid = UUID(b) |
|
| 43 |
- } else {
|
|
| 44 |
- u := Parse(string(b)) |
|
| 45 |
- |
|
| 46 |
- if u == nil {
|
|
| 47 |
- return errors.New("Scan: invalid UUID format")
|
|
| 48 |
- } |
|
| 49 |
- |
|
| 50 |
- *uuid = u |
|
| 51 |
- } |
|
| 52 |
- |
|
| 53 |
- default: |
|
| 54 |
- return fmt.Errorf("Scan: unable to scan type %T into UUID", src)
|
|
| 55 |
- } |
|
| 56 |
- |
|
| 57 |
- return nil |
|
| 58 |
-} |
| 59 | 1 |
deleted file mode 100755 |
| ... | ... |
@@ -1,132 +0,0 @@ |
| 1 |
-// Copyright 2014 Google Inc. 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 uuid |
|
| 6 |
- |
|
| 7 |
-import ( |
|
| 8 |
- "encoding/binary" |
|
| 9 |
- "sync" |
|
| 10 |
- "time" |
|
| 11 |
-) |
|
| 12 |
- |
|
| 13 |
-// A Time represents a time as the number of 100's of nanoseconds since 15 Oct |
|
| 14 |
-// 1582. |
|
| 15 |
-type Time int64 |
|
| 16 |
- |
|
| 17 |
-const ( |
|
| 18 |
- lillian = 2299160 // Julian day of 15 Oct 1582 |
|
| 19 |
- unix = 2440587 // Julian day of 1 Jan 1970 |
|
| 20 |
- epoch = unix - lillian // Days between epochs |
|
| 21 |
- g1582 = epoch * 86400 // seconds between epochs |
|
| 22 |
- g1582ns100 = g1582 * 10000000 // 100s of a nanoseconds between epochs |
|
| 23 |
-) |
|
| 24 |
- |
|
| 25 |
-var ( |
|
| 26 |
- timeMu sync.Mutex |
|
| 27 |
- lasttime uint64 // last time we returned |
|
| 28 |
- clock_seq uint16 // clock sequence for this run |
|
| 29 |
- |
|
| 30 |
- timeNow = time.Now // for testing |
|
| 31 |
-) |
|
| 32 |
- |
|
| 33 |
-// UnixTime converts t the number of seconds and nanoseconds using the Unix |
|
| 34 |
-// epoch of 1 Jan 1970. |
|
| 35 |
-func (t Time) UnixTime() (sec, nsec int64) {
|
|
| 36 |
- sec = int64(t - g1582ns100) |
|
| 37 |
- nsec = (sec % 10000000) * 100 |
|
| 38 |
- sec /= 10000000 |
|
| 39 |
- return sec, nsec |
|
| 40 |
-} |
|
| 41 |
- |
|
| 42 |
-// GetTime returns the current Time (100s of nanoseconds since 15 Oct 1582) and |
|
| 43 |
-// clock sequence as well as adjusting the clock sequence as needed. An error |
|
| 44 |
-// is returned if the current time cannot be determined. |
|
| 45 |
-func GetTime() (Time, uint16, error) {
|
|
| 46 |
- defer timeMu.Unlock() |
|
| 47 |
- timeMu.Lock() |
|
| 48 |
- return getTime() |
|
| 49 |
-} |
|
| 50 |
- |
|
| 51 |
-func getTime() (Time, uint16, error) {
|
|
| 52 |
- t := timeNow() |
|
| 53 |
- |
|
| 54 |
- // If we don't have a clock sequence already, set one. |
|
| 55 |
- if clock_seq == 0 {
|
|
| 56 |
- setClockSequence(-1) |
|
| 57 |
- } |
|
| 58 |
- now := uint64(t.UnixNano()/100) + g1582ns100 |
|
| 59 |
- |
|
| 60 |
- // If time has gone backwards with this clock sequence then we |
|
| 61 |
- // increment the clock sequence |
|
| 62 |
- if now <= lasttime {
|
|
| 63 |
- clock_seq = ((clock_seq + 1) & 0x3fff) | 0x8000 |
|
| 64 |
- } |
|
| 65 |
- lasttime = now |
|
| 66 |
- return Time(now), clock_seq, nil |
|
| 67 |
-} |
|
| 68 |
- |
|
| 69 |
-// ClockSequence returns the current clock sequence, generating one if not |
|
| 70 |
-// already set. The clock sequence is only used for Version 1 UUIDs. |
|
| 71 |
-// |
|
| 72 |
-// The uuid package does not use global static storage for the clock sequence or |
|
| 73 |
-// the last time a UUID was generated. Unless SetClockSequence a new random |
|
| 74 |
-// clock sequence is generated the first time a clock sequence is requested by |
|
| 75 |
-// ClockSequence, GetTime, or NewUUID. (section 4.2.1.1) sequence is generated |
|
| 76 |
-// for |
|
| 77 |
-func ClockSequence() int {
|
|
| 78 |
- defer timeMu.Unlock() |
|
| 79 |
- timeMu.Lock() |
|
| 80 |
- return clockSequence() |
|
| 81 |
-} |
|
| 82 |
- |
|
| 83 |
-func clockSequence() int {
|
|
| 84 |
- if clock_seq == 0 {
|
|
| 85 |
- setClockSequence(-1) |
|
| 86 |
- } |
|
| 87 |
- return int(clock_seq & 0x3fff) |
|
| 88 |
-} |
|
| 89 |
- |
|
| 90 |
-// SetClockSeq sets the clock sequence to the lower 14 bits of seq. Setting to |
|
| 91 |
-// -1 causes a new sequence to be generated. |
|
| 92 |
-func SetClockSequence(seq int) {
|
|
| 93 |
- defer timeMu.Unlock() |
|
| 94 |
- timeMu.Lock() |
|
| 95 |
- setClockSequence(seq) |
|
| 96 |
-} |
|
| 97 |
- |
|
| 98 |
-func setClockSequence(seq int) {
|
|
| 99 |
- if seq == -1 {
|
|
| 100 |
- var b [2]byte |
|
| 101 |
- randomBits(b[:]) // clock sequence |
|
| 102 |
- seq = int(b[0])<<8 | int(b[1]) |
|
| 103 |
- } |
|
| 104 |
- old_seq := clock_seq |
|
| 105 |
- clock_seq = uint16(seq&0x3fff) | 0x8000 // Set our variant |
|
| 106 |
- if old_seq != clock_seq {
|
|
| 107 |
- lasttime = 0 |
|
| 108 |
- } |
|
| 109 |
-} |
|
| 110 |
- |
|
| 111 |
-// Time returns the time in 100s of nanoseconds since 15 Oct 1582 encoded in |
|
| 112 |
-// uuid. It returns false if uuid is not valid. The time is only well defined |
|
| 113 |
-// for version 1 and 2 UUIDs. |
|
| 114 |
-func (uuid UUID) Time() (Time, bool) {
|
|
| 115 |
- if len(uuid) != 16 {
|
|
| 116 |
- return 0, false |
|
| 117 |
- } |
|
| 118 |
- time := int64(binary.BigEndian.Uint32(uuid[0:4])) |
|
| 119 |
- time |= int64(binary.BigEndian.Uint16(uuid[4:6])) << 32 |
|
| 120 |
- time |= int64(binary.BigEndian.Uint16(uuid[6:8])&0xfff) << 48 |
|
| 121 |
- return Time(time), true |
|
| 122 |
-} |
|
| 123 |
- |
|
| 124 |
-// ClockSequence returns the clock sequence encoded in uuid. It returns false |
|
| 125 |
-// if uuid is not valid. The clock sequence is only well defined for version 1 |
|
| 126 |
-// and 2 UUIDs. |
|
| 127 |
-func (uuid UUID) ClockSequence() (int, bool) {
|
|
| 128 |
- if len(uuid) != 16 {
|
|
| 129 |
- return 0, false |
|
| 130 |
- } |
|
| 131 |
- return int(binary.BigEndian.Uint16(uuid[8:10])) & 0x3fff, true |
|
| 132 |
-} |
| 133 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,43 +0,0 @@ |
| 1 |
-// Copyright 2011 Google Inc. 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 uuid |
|
| 6 |
- |
|
| 7 |
-import ( |
|
| 8 |
- "io" |
|
| 9 |
-) |
|
| 10 |
- |
|
| 11 |
-// randomBits completely fills slice b with random data. |
|
| 12 |
-func randomBits(b []byte) {
|
|
| 13 |
- if _, err := io.ReadFull(rander, b); err != nil {
|
|
| 14 |
- panic(err.Error()) // rand should never fail |
|
| 15 |
- } |
|
| 16 |
-} |
|
| 17 |
- |
|
| 18 |
-// xvalues returns the value of a byte as a hexadecimal digit or 255. |
|
| 19 |
-var xvalues = [256]byte{
|
|
| 20 |
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
|
| 21 |
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
|
| 22 |
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
|
| 23 |
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255, 255, 255, 255, 255, 255, |
|
| 24 |
- 255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
|
| 25 |
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
|
| 26 |
- 255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
|
| 27 |
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
|
| 28 |
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
|
| 29 |
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
|
| 30 |
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
|
| 31 |
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
|
| 32 |
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
|
| 33 |
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
|
| 34 |
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
|
| 35 |
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
|
| 36 |
-} |
|
| 37 |
- |
|
| 38 |
-// xtob converts the the first two hex bytes of x into a byte. |
|
| 39 |
-func xtob(x string) (byte, bool) {
|
|
| 40 |
- b1 := xvalues[x[0]] |
|
| 41 |
- b2 := xvalues[x[1]] |
|
| 42 |
- return (b1 << 4) | b2, b1 != 255 && b2 != 255 |
|
| 43 |
-} |
| 44 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,176 +0,0 @@ |
| 1 |
-// Copyright 2011 Google Inc. 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 uuid |
|
| 6 |
- |
|
| 7 |
-import ( |
|
| 8 |
- "bytes" |
|
| 9 |
- "crypto/rand" |
|
| 10 |
- "encoding/hex" |
|
| 11 |
- "fmt" |
|
| 12 |
- "io" |
|
| 13 |
- "strings" |
|
| 14 |
-) |
|
| 15 |
- |
|
| 16 |
-// A UUID is a 128 bit (16 byte) Universal Unique IDentifier as defined in RFC |
|
| 17 |
-// 4122. |
|
| 18 |
-type UUID []byte |
|
| 19 |
- |
|
| 20 |
-// A Version represents a UUIDs version. |
|
| 21 |
-type Version byte |
|
| 22 |
- |
|
| 23 |
-// A Variant represents a UUIDs variant. |
|
| 24 |
-type Variant byte |
|
| 25 |
- |
|
| 26 |
-// Constants returned by Variant. |
|
| 27 |
-const ( |
|
| 28 |
- Invalid = Variant(iota) // Invalid UUID |
|
| 29 |
- RFC4122 // The variant specified in RFC4122 |
|
| 30 |
- Reserved // Reserved, NCS backward compatibility. |
|
| 31 |
- Microsoft // Reserved, Microsoft Corporation backward compatibility. |
|
| 32 |
- Future // Reserved for future definition. |
|
| 33 |
-) |
|
| 34 |
- |
|
| 35 |
-var rander = rand.Reader // random function |
|
| 36 |
- |
|
| 37 |
-// New returns a new random (version 4) UUID as a string. It is a convenience |
|
| 38 |
-// function for NewRandom().String(). |
|
| 39 |
-func New() string {
|
|
| 40 |
- return NewRandom().String() |
|
| 41 |
-} |
|
| 42 |
- |
|
| 43 |
-// Parse decodes s into a UUID or returns nil. Both the UUID form of |
|
| 44 |
-// xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx and |
|
| 45 |
-// urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx are decoded. |
|
| 46 |
-func Parse(s string) UUID {
|
|
| 47 |
- if len(s) == 36+9 {
|
|
| 48 |
- if strings.ToLower(s[:9]) != "urn:uuid:" {
|
|
| 49 |
- return nil |
|
| 50 |
- } |
|
| 51 |
- s = s[9:] |
|
| 52 |
- } else if len(s) != 36 {
|
|
| 53 |
- return nil |
|
| 54 |
- } |
|
| 55 |
- if s[8] != '-' || s[13] != '-' || s[18] != '-' || s[23] != '-' {
|
|
| 56 |
- return nil |
|
| 57 |
- } |
|
| 58 |
- var uuid [16]byte |
|
| 59 |
- for i, x := range [16]int{
|
|
| 60 |
- 0, 2, 4, 6, |
|
| 61 |
- 9, 11, |
|
| 62 |
- 14, 16, |
|
| 63 |
- 19, 21, |
|
| 64 |
- 24, 26, 28, 30, 32, 34} {
|
|
| 65 |
- if v, ok := xtob(s[x:]); !ok {
|
|
| 66 |
- return nil |
|
| 67 |
- } else {
|
|
| 68 |
- uuid[i] = v |
|
| 69 |
- } |
|
| 70 |
- } |
|
| 71 |
- return uuid[:] |
|
| 72 |
-} |
|
| 73 |
- |
|
| 74 |
-// Equal returns true if uuid1 and uuid2 are equal. |
|
| 75 |
-func Equal(uuid1, uuid2 UUID) bool {
|
|
| 76 |
- return bytes.Equal(uuid1, uuid2) |
|
| 77 |
-} |
|
| 78 |
- |
|
| 79 |
-// String returns the string form of uuid, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
|
| 80 |
-// , or "" if uuid is invalid. |
|
| 81 |
-func (uuid UUID) String() string {
|
|
| 82 |
- if len(uuid) != 16 {
|
|
| 83 |
- return "" |
|
| 84 |
- } |
|
| 85 |
- var buf [36]byte |
|
| 86 |
- encodeHex(buf[:], uuid) |
|
| 87 |
- return string(buf[:]) |
|
| 88 |
-} |
|
| 89 |
- |
|
| 90 |
-// URN returns the RFC 2141 URN form of uuid, |
|
| 91 |
-// urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, or "" if uuid is invalid. |
|
| 92 |
-func (uuid UUID) URN() string {
|
|
| 93 |
- if len(uuid) != 16 {
|
|
| 94 |
- return "" |
|
| 95 |
- } |
|
| 96 |
- var buf [36 + 9]byte |
|
| 97 |
- copy(buf[:], "urn:uuid:") |
|
| 98 |
- encodeHex(buf[9:], uuid) |
|
| 99 |
- return string(buf[:]) |
|
| 100 |
-} |
|
| 101 |
- |
|
| 102 |
-func encodeHex(dst []byte, uuid UUID) {
|
|
| 103 |
- hex.Encode(dst[:], uuid[:4]) |
|
| 104 |
- dst[8] = '-' |
|
| 105 |
- hex.Encode(dst[9:13], uuid[4:6]) |
|
| 106 |
- dst[13] = '-' |
|
| 107 |
- hex.Encode(dst[14:18], uuid[6:8]) |
|
| 108 |
- dst[18] = '-' |
|
| 109 |
- hex.Encode(dst[19:23], uuid[8:10]) |
|
| 110 |
- dst[23] = '-' |
|
| 111 |
- hex.Encode(dst[24:], uuid[10:]) |
|
| 112 |
-} |
|
| 113 |
- |
|
| 114 |
-// Variant returns the variant encoded in uuid. It returns Invalid if |
|
| 115 |
-// uuid is invalid. |
|
| 116 |
-func (uuid UUID) Variant() Variant {
|
|
| 117 |
- if len(uuid) != 16 {
|
|
| 118 |
- return Invalid |
|
| 119 |
- } |
|
| 120 |
- switch {
|
|
| 121 |
- case (uuid[8] & 0xc0) == 0x80: |
|
| 122 |
- return RFC4122 |
|
| 123 |
- case (uuid[8] & 0xe0) == 0xc0: |
|
| 124 |
- return Microsoft |
|
| 125 |
- case (uuid[8] & 0xe0) == 0xe0: |
|
| 126 |
- return Future |
|
| 127 |
- default: |
|
| 128 |
- return Reserved |
|
| 129 |
- } |
|
| 130 |
-} |
|
| 131 |
- |
|
| 132 |
-// Version returns the version of uuid. It returns false if uuid is not |
|
| 133 |
-// valid. |
|
| 134 |
-func (uuid UUID) Version() (Version, bool) {
|
|
| 135 |
- if len(uuid) != 16 {
|
|
| 136 |
- return 0, false |
|
| 137 |
- } |
|
| 138 |
- return Version(uuid[6] >> 4), true |
|
| 139 |
-} |
|
| 140 |
- |
|
| 141 |
-func (v Version) String() string {
|
|
| 142 |
- if v > 15 {
|
|
| 143 |
- return fmt.Sprintf("BAD_VERSION_%d", v)
|
|
| 144 |
- } |
|
| 145 |
- return fmt.Sprintf("VERSION_%d", v)
|
|
| 146 |
-} |
|
| 147 |
- |
|
| 148 |
-func (v Variant) String() string {
|
|
| 149 |
- switch v {
|
|
| 150 |
- case RFC4122: |
|
| 151 |
- return "RFC4122" |
|
| 152 |
- case Reserved: |
|
| 153 |
- return "Reserved" |
|
| 154 |
- case Microsoft: |
|
| 155 |
- return "Microsoft" |
|
| 156 |
- case Future: |
|
| 157 |
- return "Future" |
|
| 158 |
- case Invalid: |
|
| 159 |
- return "Invalid" |
|
| 160 |
- } |
|
| 161 |
- return fmt.Sprintf("BadVariant%d", int(v))
|
|
| 162 |
-} |
|
| 163 |
- |
|
| 164 |
-// SetRand sets the random number generator to r, which implents io.Reader. |
|
| 165 |
-// If r.Read returns an error when the package requests random data then |
|
| 166 |
-// a panic will be issued. |
|
| 167 |
-// |
|
| 168 |
-// Calling SetRand with nil sets the random number generator to the default |
|
| 169 |
-// generator. |
|
| 170 |
-func SetRand(r io.Reader) {
|
|
| 171 |
- if r == nil {
|
|
| 172 |
- rander = rand.Reader |
|
| 173 |
- return |
|
| 174 |
- } |
|
| 175 |
- rander = r |
|
| 176 |
-} |
| 177 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,41 +0,0 @@ |
| 1 |
-// Copyright 2011 Google Inc. 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 uuid |
|
| 6 |
- |
|
| 7 |
-import ( |
|
| 8 |
- "encoding/binary" |
|
| 9 |
-) |
|
| 10 |
- |
|
| 11 |
-// NewUUID returns a Version 1 UUID based on the current NodeID and clock |
|
| 12 |
-// sequence, and the current time. If the NodeID has not been set by SetNodeID |
|
| 13 |
-// or SetNodeInterface then it will be set automatically. If the NodeID cannot |
|
| 14 |
-// be set NewUUID returns nil. If clock sequence has not been set by |
|
| 15 |
-// SetClockSequence then it will be set automatically. If GetTime fails to |
|
| 16 |
-// return the current NewUUID returns nil. |
|
| 17 |
-func NewUUID() UUID {
|
|
| 18 |
- if nodeID == nil {
|
|
| 19 |
- SetNodeInterface("")
|
|
| 20 |
- } |
|
| 21 |
- |
|
| 22 |
- now, seq, err := GetTime() |
|
| 23 |
- if err != nil {
|
|
| 24 |
- return nil |
|
| 25 |
- } |
|
| 26 |
- |
|
| 27 |
- uuid := make([]byte, 16) |
|
| 28 |
- |
|
| 29 |
- time_low := uint32(now & 0xffffffff) |
|
| 30 |
- time_mid := uint16((now >> 32) & 0xffff) |
|
| 31 |
- time_hi := uint16((now >> 48) & 0x0fff) |
|
| 32 |
- time_hi |= 0x1000 // Version 1 |
|
| 33 |
- |
|
| 34 |
- binary.BigEndian.PutUint32(uuid[0:], time_low) |
|
| 35 |
- binary.BigEndian.PutUint16(uuid[4:], time_mid) |
|
| 36 |
- binary.BigEndian.PutUint16(uuid[6:], time_hi) |
|
| 37 |
- binary.BigEndian.PutUint16(uuid[8:], seq) |
|
| 38 |
- copy(uuid[10:], nodeID) |
|
| 39 |
- |
|
| 40 |
- return uuid |
|
| 41 |
-} |
| 42 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,25 +0,0 @@ |
| 1 |
-// Copyright 2011 Google Inc. 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 uuid |
|
| 6 |
- |
|
| 7 |
-// Random returns a Random (Version 4) UUID or panics. |
|
| 8 |
-// |
|
| 9 |
-// The strength of the UUIDs is based on the strength of the crypto/rand |
|
| 10 |
-// package. |
|
| 11 |
-// |
|
| 12 |
-// A note about uniqueness derived from from the UUID Wikipedia entry: |
|
| 13 |
-// |
|
| 14 |
-// Randomly generated UUIDs have 122 random bits. One's annual risk of being |
|
| 15 |
-// hit by a meteorite is estimated to be one chance in 17 billion, that |
|
| 16 |
-// means the probability is about 0.00000000006 (6 × 10−11), |
|
| 17 |
-// equivalent to the odds of creating a few tens of trillions of UUIDs in a |
|
| 18 |
-// year and having one duplicate. |
|
| 19 |
-func NewRandom() UUID {
|
|
| 20 |
- uuid := make([]byte, 16) |
|
| 21 |
- randomBits([]byte(uuid)) |
|
| 22 |
- uuid[6] = (uuid[6] & 0x0f) | 0x40 // Version 4 |
|
| 23 |
- uuid[8] = (uuid[8] & 0x3f) | 0x80 // Variant is 10 |
|
| 24 |
- return uuid |
|
| 25 |
-} |
| ... | ... |
@@ -10,42 +10,42 @@ package capability |
| 10 | 10 |
type Capabilities interface {
|
| 11 | 11 |
// Get check whether a capability present in the given |
| 12 | 12 |
// capabilities set. The 'which' value should be one of EFFECTIVE, |
| 13 |
- // PERMITTED, INHERITABLE or BOUNDING. |
|
| 13 |
+ // PERMITTED, INHERITABLE, BOUNDING or AMBIENT. |
|
| 14 | 14 |
Get(which CapType, what Cap) bool |
| 15 | 15 |
|
| 16 | 16 |
// Empty check whether all capability bits of the given capabilities |
| 17 | 17 |
// set are zero. The 'which' value should be one of EFFECTIVE, |
| 18 |
- // PERMITTED, INHERITABLE or BOUNDING. |
|
| 18 |
+ // PERMITTED, INHERITABLE, BOUNDING or AMBIENT. |
|
| 19 | 19 |
Empty(which CapType) bool |
| 20 | 20 |
|
| 21 | 21 |
// Full check whether all capability bits of the given capabilities |
| 22 | 22 |
// set are one. The 'which' value should be one of EFFECTIVE, |
| 23 |
- // PERMITTED, INHERITABLE or BOUNDING. |
|
| 23 |
+ // PERMITTED, INHERITABLE, BOUNDING or AMBIENT. |
|
| 24 | 24 |
Full(which CapType) bool |
| 25 | 25 |
|
| 26 | 26 |
// Set sets capabilities of the given capabilities sets. The |
| 27 | 27 |
// 'which' value should be one or combination (OR'ed) of EFFECTIVE, |
| 28 |
- // PERMITTED, INHERITABLE or BOUNDING. |
|
| 28 |
+ // PERMITTED, INHERITABLE, BOUNDING or AMBIENT. |
|
| 29 | 29 |
Set(which CapType, caps ...Cap) |
| 30 | 30 |
|
| 31 | 31 |
// Unset unsets capabilities of the given capabilities sets. The |
| 32 | 32 |
// 'which' value should be one or combination (OR'ed) of EFFECTIVE, |
| 33 |
- // PERMITTED, INHERITABLE or BOUNDING. |
|
| 33 |
+ // PERMITTED, INHERITABLE, BOUNDING or AMBIENT. |
|
| 34 | 34 |
Unset(which CapType, caps ...Cap) |
| 35 | 35 |
|
| 36 | 36 |
// Fill sets all bits of the given capabilities kind to one. The |
| 37 |
- // 'kind' value should be one or combination (OR'ed) of CAPS or |
|
| 38 |
- // BOUNDS. |
|
| 37 |
+ // 'kind' value should be one or combination (OR'ed) of CAPS, |
|
| 38 |
+ // BOUNDS or AMBS. |
|
| 39 | 39 |
Fill(kind CapType) |
| 40 | 40 |
|
| 41 | 41 |
// Clear sets all bits of the given capabilities kind to zero. The |
| 42 |
- // 'kind' value should be one or combination (OR'ed) of CAPS or |
|
| 43 |
- // BOUNDS. |
|
| 42 |
+ // 'kind' value should be one or combination (OR'ed) of CAPS, |
|
| 43 |
+ // BOUNDS or AMBS. |
|
| 44 | 44 |
Clear(kind CapType) |
| 45 | 45 |
|
| 46 | 46 |
// String return current capabilities state of the given capabilities |
| 47 | 47 |
// set as string. The 'which' value should be one of EFFECTIVE, |
| 48 |
- // PERMITTED, INHERITABLE or BOUNDING. |
|
| 48 |
+ // PERMITTED, INHERITABLE BOUNDING or AMBIENT |
|
| 49 | 49 |
StringCap(which CapType) string |
| 50 | 50 |
|
| 51 | 51 |
// String return current capabilities state as string. |
| ... | ... |
@@ -60,13 +60,74 @@ type Capabilities interface {
|
| 60 | 60 |
Apply(kind CapType) error |
| 61 | 61 |
} |
| 62 | 62 |
|
| 63 |
-// NewPid create new initialized Capabilities object for given pid when it |
|
| 64 |
-// is nonzero, or for the current pid if pid is 0 |
|
| 63 |
+// NewPid initializes a new Capabilities object for given pid when |
|
| 64 |
+// it is nonzero, or for the current process if pid is 0. |
|
| 65 |
+// |
|
| 66 |
+// Deprecated: Replace with NewPid2. For example, replace: |
|
| 67 |
+// |
|
| 68 |
+// c, err := NewPid(0) |
|
| 69 |
+// if err != nil {
|
|
| 70 |
+// return err |
|
| 71 |
+// } |
|
| 72 |
+// |
|
| 73 |
+// with: |
|
| 74 |
+// |
|
| 75 |
+// c, err := NewPid2(0) |
|
| 76 |
+// if err != nil {
|
|
| 77 |
+// return err |
|
| 78 |
+// } |
|
| 79 |
+// err = c.Load() |
|
| 80 |
+// if err != nil {
|
|
| 81 |
+// return err |
|
| 82 |
+// } |
|
| 65 | 83 |
func NewPid(pid int) (Capabilities, error) {
|
| 84 |
+ c, err := newPid(pid) |
|
| 85 |
+ if err != nil {
|
|
| 86 |
+ return c, err |
|
| 87 |
+ } |
|
| 88 |
+ err = c.Load() |
|
| 89 |
+ return c, err |
|
| 90 |
+} |
|
| 91 |
+ |
|
| 92 |
+// NewPid2 initializes a new Capabilities object for given pid when |
|
| 93 |
+// it is nonzero, or for the current process if pid is 0. This |
|
| 94 |
+// does not load the process's current capabilities; to do that you |
|
| 95 |
+// must call Load explicitly. |
|
| 96 |
+func NewPid2(pid int) (Capabilities, error) {
|
|
| 66 | 97 |
return newPid(pid) |
| 67 | 98 |
} |
| 68 | 99 |
|
| 69 |
-// NewFile create new initialized Capabilities object for given named file. |
|
| 70 |
-func NewFile(name string) (Capabilities, error) {
|
|
| 71 |
- return newFile(name) |
|
| 100 |
+// NewFile initializes a new Capabilities object for given file path. |
|
| 101 |
+// |
|
| 102 |
+// Deprecated: Replace with NewFile2. For example, replace: |
|
| 103 |
+// |
|
| 104 |
+// c, err := NewFile(path) |
|
| 105 |
+// if err != nil {
|
|
| 106 |
+// return err |
|
| 107 |
+// } |
|
| 108 |
+// |
|
| 109 |
+// with: |
|
| 110 |
+// |
|
| 111 |
+// c, err := NewFile2(path) |
|
| 112 |
+// if err != nil {
|
|
| 113 |
+// return err |
|
| 114 |
+// } |
|
| 115 |
+// err = c.Load() |
|
| 116 |
+// if err != nil {
|
|
| 117 |
+// return err |
|
| 118 |
+// } |
|
| 119 |
+func NewFile(path string) (Capabilities, error) {
|
|
| 120 |
+ c, err := newFile(path) |
|
| 121 |
+ if err != nil {
|
|
| 122 |
+ return c, err |
|
| 123 |
+ } |
|
| 124 |
+ err = c.Load() |
|
| 125 |
+ return c, err |
|
| 126 |
+} |
|
| 127 |
+ |
|
| 128 |
+// NewFile2 creates a new initialized Capabilities object for given |
|
| 129 |
+// file path. This does not load the process's current capabilities; |
|
| 130 |
+// to do that you must call Load explicitly. |
|
| 131 |
+func NewFile2(path string) (Capabilities, error) {
|
|
| 132 |
+ return newFile(path) |
|
| 72 | 133 |
} |
| ... | ... |
@@ -103,21 +103,17 @@ func newPid(pid int) (c Capabilities, err error) {
|
| 103 | 103 |
case linuxCapVer1: |
| 104 | 104 |
p := new(capsV1) |
| 105 | 105 |
p.hdr.version = capVers |
| 106 |
- p.hdr.pid = pid |
|
| 106 |
+ p.hdr.pid = int32(pid) |
|
| 107 | 107 |
c = p |
| 108 | 108 |
case linuxCapVer2, linuxCapVer3: |
| 109 | 109 |
p := new(capsV3) |
| 110 | 110 |
p.hdr.version = capVers |
| 111 |
- p.hdr.pid = pid |
|
| 111 |
+ p.hdr.pid = int32(pid) |
|
| 112 | 112 |
c = p |
| 113 | 113 |
default: |
| 114 | 114 |
err = errUnknownVers |
| 115 | 115 |
return |
| 116 | 116 |
} |
| 117 |
- err = c.Load() |
|
| 118 |
- if err != nil {
|
|
| 119 |
- c = nil |
|
| 120 |
- } |
|
| 121 | 117 |
return |
| 122 | 118 |
} |
| 123 | 119 |
|
| ... | ... |
@@ -235,9 +231,10 @@ func (c *capsV1) Apply(kind CapType) error {
|
| 235 | 235 |
} |
| 236 | 236 |
|
| 237 | 237 |
type capsV3 struct {
|
| 238 |
- hdr capHeader |
|
| 239 |
- data [2]capData |
|
| 240 |
- bounds [2]uint32 |
|
| 238 |
+ hdr capHeader |
|
| 239 |
+ data [2]capData |
|
| 240 |
+ bounds [2]uint32 |
|
| 241 |
+ ambient [2]uint32 |
|
| 241 | 242 |
} |
| 242 | 243 |
|
| 243 | 244 |
func (c *capsV3) Get(which CapType, what Cap) bool {
|
| ... | ... |
@@ -256,6 +253,8 @@ func (c *capsV3) Get(which CapType, what Cap) bool {
|
| 256 | 256 |
return (1<<uint(what))&c.data[i].inheritable != 0 |
| 257 | 257 |
case BOUNDING: |
| 258 | 258 |
return (1<<uint(what))&c.bounds[i] != 0 |
| 259 |
+ case AMBIENT: |
|
| 260 |
+ return (1<<uint(what))&c.ambient[i] != 0 |
|
| 259 | 261 |
} |
| 260 | 262 |
|
| 261 | 263 |
return false |
| ... | ... |
@@ -275,6 +274,9 @@ func (c *capsV3) getData(which CapType, dest []uint32) {
|
| 275 | 275 |
case BOUNDING: |
| 276 | 276 |
dest[0] = c.bounds[0] |
| 277 | 277 |
dest[1] = c.bounds[1] |
| 278 |
+ case AMBIENT: |
|
| 279 |
+ dest[0] = c.ambient[0] |
|
| 280 |
+ dest[1] = c.ambient[1] |
|
| 278 | 281 |
} |
| 279 | 282 |
} |
| 280 | 283 |
|
| ... | ... |
@@ -313,6 +315,9 @@ func (c *capsV3) Set(which CapType, caps ...Cap) {
|
| 313 | 313 |
if which&BOUNDING != 0 {
|
| 314 | 314 |
c.bounds[i] |= 1 << uint(what) |
| 315 | 315 |
} |
| 316 |
+ if which&AMBIENT != 0 {
|
|
| 317 |
+ c.ambient[i] |= 1 << uint(what) |
|
| 318 |
+ } |
|
| 316 | 319 |
} |
| 317 | 320 |
} |
| 318 | 321 |
|
| ... | ... |
@@ -336,6 +341,9 @@ func (c *capsV3) Unset(which CapType, caps ...Cap) {
|
| 336 | 336 |
if which&BOUNDING != 0 {
|
| 337 | 337 |
c.bounds[i] &= ^(1 << uint(what)) |
| 338 | 338 |
} |
| 339 |
+ if which&AMBIENT != 0 {
|
|
| 340 |
+ c.ambient[i] &= ^(1 << uint(what)) |
|
| 341 |
+ } |
|
| 339 | 342 |
} |
| 340 | 343 |
} |
| 341 | 344 |
|
| ... | ... |
@@ -353,6 +361,10 @@ func (c *capsV3) Fill(kind CapType) {
|
| 353 | 353 |
c.bounds[0] = 0xffffffff |
| 354 | 354 |
c.bounds[1] = 0xffffffff |
| 355 | 355 |
} |
| 356 |
+ if kind&AMBS == AMBS {
|
|
| 357 |
+ c.ambient[0] = 0xffffffff |
|
| 358 |
+ c.ambient[1] = 0xffffffff |
|
| 359 |
+ } |
|
| 356 | 360 |
} |
| 357 | 361 |
|
| 358 | 362 |
func (c *capsV3) Clear(kind CapType) {
|
| ... | ... |
@@ -369,6 +381,10 @@ func (c *capsV3) Clear(kind CapType) {
|
| 369 | 369 |
c.bounds[0] = 0 |
| 370 | 370 |
c.bounds[1] = 0 |
| 371 | 371 |
} |
| 372 |
+ if kind&AMBS == AMBS {
|
|
| 373 |
+ c.ambient[0] = 0 |
|
| 374 |
+ c.ambient[1] = 0 |
|
| 375 |
+ } |
|
| 372 | 376 |
} |
| 373 | 377 |
|
| 374 | 378 |
func (c *capsV3) StringCap(which CapType) (ret string) {
|
| ... | ... |
@@ -408,7 +424,11 @@ func (c *capsV3) Load() (err error) {
|
| 408 | 408 |
} |
| 409 | 409 |
if strings.HasPrefix(line, "CapB") {
|
| 410 | 410 |
fmt.Sscanf(line[4:], "nd: %08x%08x", &c.bounds[1], &c.bounds[0]) |
| 411 |
- break |
|
| 411 |
+ continue |
|
| 412 |
+ } |
|
| 413 |
+ if strings.HasPrefix(line, "CapA") {
|
|
| 414 |
+ fmt.Sscanf(line[4:], "mb: %08x%08x", &c.ambient[1], &c.ambient[0]) |
|
| 415 |
+ continue |
|
| 412 | 416 |
} |
| 413 | 417 |
} |
| 414 | 418 |
f.Close() |
| ... | ... |
@@ -442,7 +462,25 @@ func (c *capsV3) Apply(kind CapType) (err error) {
|
| 442 | 442 |
} |
| 443 | 443 |
|
| 444 | 444 |
if kind&CAPS == CAPS {
|
| 445 |
- return capset(&c.hdr, &c.data[0]) |
|
| 445 |
+ err = capset(&c.hdr, &c.data[0]) |
|
| 446 |
+ if err != nil {
|
|
| 447 |
+ return |
|
| 448 |
+ } |
|
| 449 |
+ } |
|
| 450 |
+ |
|
| 451 |
+ if kind&AMBS == AMBS {
|
|
| 452 |
+ for i := Cap(0); i <= CAP_LAST_CAP; i++ {
|
|
| 453 |
+ action := pr_CAP_AMBIENT_LOWER |
|
| 454 |
+ if c.Get(AMBIENT, i) {
|
|
| 455 |
+ action = pr_CAP_AMBIENT_RAISE |
|
| 456 |
+ } |
|
| 457 |
+ err := prctl(pr_CAP_AMBIENT, action, uintptr(i), 0, 0) |
|
| 458 |
+ // Ignore EINVAL as not supported on kernels before 4.3 |
|
| 459 |
+ if errno, ok := err.(syscall.Errno); ok && errno == syscall.EINVAL {
|
|
| 460 |
+ err = nil |
|
| 461 |
+ continue |
|
| 462 |
+ } |
|
| 463 |
+ } |
|
| 446 | 464 |
} |
| 447 | 465 |
|
| 448 | 466 |
return |
| ... | ... |
@@ -450,10 +488,6 @@ func (c *capsV3) Apply(kind CapType) (err error) {
|
| 450 | 450 |
|
| 451 | 451 |
func newFile(path string) (c Capabilities, err error) {
|
| 452 | 452 |
c = &capsFile{path: path}
|
| 453 |
- err = c.Load() |
|
| 454 |
- if err != nil {
|
|
| 455 |
- c = nil |
|
| 456 |
- } |
|
| 457 | 453 |
return |
| 458 | 454 |
} |
| 459 | 455 |
|
| ... | ... |
@@ -20,6 +20,8 @@ func (c CapType) String() string {
|
| 20 | 20 |
return "bounding" |
| 21 | 21 |
case CAPS: |
| 22 | 22 |
return "caps" |
| 23 |
+ case AMBIENT: |
|
| 24 |
+ return "ambient" |
|
| 23 | 25 |
} |
| 24 | 26 |
return "unknown" |
| 25 | 27 |
} |
| ... | ... |
@@ -29,9 +31,11 @@ const ( |
| 29 | 29 |
PERMITTED |
| 30 | 30 |
INHERITABLE |
| 31 | 31 |
BOUNDING |
| 32 |
+ AMBIENT |
|
| 32 | 33 |
|
| 33 | 34 |
CAPS = EFFECTIVE | PERMITTED | INHERITABLE |
| 34 | 35 |
BOUNDS = BOUNDING |
| 36 |
+ AMBS = AMBIENT |
|
| 35 | 37 |
) |
| 36 | 38 |
|
| 37 | 39 |
//go:generate go run enumgen/gen.go |
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
|
| 14 | 14 |
type capHeader struct {
|
| 15 | 15 |
version uint32 |
| 16 |
- pid int |
|
| 16 |
+ pid int32 |
|
| 17 | 17 |
} |
| 18 | 18 |
|
| 19 | 19 |
type capData struct {
|
| ... | ... |
@@ -38,6 +38,15 @@ func capset(hdr *capHeader, data *capData) (err error) {
|
| 38 | 38 |
return |
| 39 | 39 |
} |
| 40 | 40 |
|
| 41 |
+// not yet in syscall |
|
| 42 |
+const ( |
|
| 43 |
+ pr_CAP_AMBIENT = 47 |
|
| 44 |
+ pr_CAP_AMBIENT_IS_SET = uintptr(1) |
|
| 45 |
+ pr_CAP_AMBIENT_RAISE = uintptr(2) |
|
| 46 |
+ pr_CAP_AMBIENT_LOWER = uintptr(3) |
|
| 47 |
+ pr_CAP_AMBIENT_CLEAR_ALL = uintptr(4) |
|
| 48 |
+) |
|
| 49 |
+ |
|
| 41 | 50 |
func prctl(option int, arg2, arg3, arg4, arg5 uintptr) (err error) {
|
| 42 | 51 |
_, _, e1 := syscall.Syscall6(syscall.SYS_PRCTL, uintptr(option), arg2, arg3, arg4, arg5, 0) |
| 43 | 52 |
if e1 != 0 {
|