Libcontainer depends on the new package now to avoid cycled
dependencies.
Signed-off-by: David Calavera <david.calavera@gmail.com>
| ... | ... |
@@ -20,6 +20,7 @@ clone git github.com/mistifyio/go-zfs v2.1.1 |
| 20 | 20 |
clone git github.com/tchap/go-patricia v2.1.0 |
| 21 | 21 |
clone git github.com/vdemeester/shakers 3c10293ce22b900c27acad7b28656196fcc2f73b |
| 22 | 22 |
clone git golang.org/x/net 47990a1ba55743e6ef1affd3a14e5bac8553615d https://github.com/golang/net.git |
| 23 |
+clone git github.com/docker/go-units v0.2.0 |
|
| 23 | 24 |
|
| 24 | 25 |
#get libnetwork packages |
| 25 | 26 |
clone git github.com/docker/libnetwork bbd6e6d8ca1e7c9b42f6f53277b0bde72847ff90 |
| ... | ... |
@@ -49,7 +50,7 @@ clone git github.com/miekg/pkcs11 80f102b5cac759de406949c47f0928b99bd64cdf |
| 49 | 49 |
clone git github.com/jfrazelle/go v1.5.1-1 |
| 50 | 50 |
clone git github.com/agl/ed25519 d2b94fd789ea21d12fac1a4443dd3a3f79cda72c |
| 51 | 51 |
|
| 52 |
-clone git github.com/opencontainers/runc v0.0.6 # libcontainer |
|
| 52 |
+clone git github.com/opencontainers/runc ba1568de399395774ad84c2ace65937814c542ed # libcontainer |
|
| 53 | 53 |
clone git github.com/opencontainers/specs 46d949ea81080c5f60dfb72ee91468b1e9fb2998 # specs |
| 54 | 54 |
clone git github.com/seccomp/libseccomp-golang 1b506fc7c24eec5a3693cdcbed40d9c226cfc6a1 |
| 55 | 55 |
# libcontainer deps (see src/github.com/opencontainers/runc/Godeps/Godeps.json) |
| 56 | 56 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,191 @@ |
| 0 |
+ |
|
| 1 |
+ Apache License |
|
| 2 |
+ Version 2.0, January 2004 |
|
| 3 |
+ https://www.apache.org/licenses/ |
|
| 4 |
+ |
|
| 5 |
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION |
|
| 6 |
+ |
|
| 7 |
+ 1. Definitions. |
|
| 8 |
+ |
|
| 9 |
+ "License" shall mean the terms and conditions for use, reproduction, |
|
| 10 |
+ and distribution as defined by Sections 1 through 9 of this document. |
|
| 11 |
+ |
|
| 12 |
+ "Licensor" shall mean the copyright owner or entity authorized by |
|
| 13 |
+ the copyright owner that is granting the License. |
|
| 14 |
+ |
|
| 15 |
+ "Legal Entity" shall mean the union of the acting entity and all |
|
| 16 |
+ other entities that control, are controlled by, or are under common |
|
| 17 |
+ control with that entity. For the purposes of this definition, |
|
| 18 |
+ "control" means (i) the power, direct or indirect, to cause the |
|
| 19 |
+ direction or management of such entity, whether by contract or |
|
| 20 |
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the |
|
| 21 |
+ outstanding shares, or (iii) beneficial ownership of such entity. |
|
| 22 |
+ |
|
| 23 |
+ "You" (or "Your") shall mean an individual or Legal Entity |
|
| 24 |
+ exercising permissions granted by this License. |
|
| 25 |
+ |
|
| 26 |
+ "Source" form shall mean the preferred form for making modifications, |
|
| 27 |
+ including but not limited to software source code, documentation |
|
| 28 |
+ source, and configuration files. |
|
| 29 |
+ |
|
| 30 |
+ "Object" form shall mean any form resulting from mechanical |
|
| 31 |
+ transformation or translation of a Source form, including but |
|
| 32 |
+ not limited to compiled object code, generated documentation, |
|
| 33 |
+ and conversions to other media types. |
|
| 34 |
+ |
|
| 35 |
+ "Work" shall mean the work of authorship, whether in Source or |
|
| 36 |
+ Object form, made available under the License, as indicated by a |
|
| 37 |
+ copyright notice that is included in or attached to the work |
|
| 38 |
+ (an example is provided in the Appendix below). |
|
| 39 |
+ |
|
| 40 |
+ "Derivative Works" shall mean any work, whether in Source or Object |
|
| 41 |
+ form, that is based on (or derived from) the Work and for which the |
|
| 42 |
+ editorial revisions, annotations, elaborations, or other modifications |
|
| 43 |
+ represent, as a whole, an original work of authorship. For the purposes |
|
| 44 |
+ of this License, Derivative Works shall not include works that remain |
|
| 45 |
+ separable from, or merely link (or bind by name) to the interfaces of, |
|
| 46 |
+ the Work and Derivative Works thereof. |
|
| 47 |
+ |
|
| 48 |
+ "Contribution" shall mean any work of authorship, including |
|
| 49 |
+ the original version of the Work and any modifications or additions |
|
| 50 |
+ to that Work or Derivative Works thereof, that is intentionally |
|
| 51 |
+ submitted to Licensor for inclusion in the Work by the copyright owner |
|
| 52 |
+ or by an individual or Legal Entity authorized to submit on behalf of |
|
| 53 |
+ the copyright owner. For the purposes of this definition, "submitted" |
|
| 54 |
+ means any form of electronic, verbal, or written communication sent |
|
| 55 |
+ to the Licensor or its representatives, including but not limited to |
|
| 56 |
+ communication on electronic mailing lists, source code control systems, |
|
| 57 |
+ and issue tracking systems that are managed by, or on behalf of, the |
|
| 58 |
+ Licensor for the purpose of discussing and improving the Work, but |
|
| 59 |
+ excluding communication that is conspicuously marked or otherwise |
|
| 60 |
+ designated in writing by the copyright owner as "Not a Contribution." |
|
| 61 |
+ |
|
| 62 |
+ "Contributor" shall mean Licensor and any individual or Legal Entity |
|
| 63 |
+ on behalf of whom a Contribution has been received by Licensor and |
|
| 64 |
+ subsequently incorporated within the Work. |
|
| 65 |
+ |
|
| 66 |
+ 2. Grant of Copyright License. Subject to the terms and conditions of |
|
| 67 |
+ this License, each Contributor hereby grants to You a perpetual, |
|
| 68 |
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable |
|
| 69 |
+ copyright license to reproduce, prepare Derivative Works of, |
|
| 70 |
+ publicly display, publicly perform, sublicense, and distribute the |
|
| 71 |
+ Work and such Derivative Works in Source or Object form. |
|
| 72 |
+ |
|
| 73 |
+ 3. Grant of Patent License. Subject to the terms and conditions of |
|
| 74 |
+ this License, each Contributor hereby grants to You a perpetual, |
|
| 75 |
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable |
|
| 76 |
+ (except as stated in this section) patent license to make, have made, |
|
| 77 |
+ use, offer to sell, sell, import, and otherwise transfer the Work, |
|
| 78 |
+ where such license applies only to those patent claims licensable |
|
| 79 |
+ by such Contributor that are necessarily infringed by their |
|
| 80 |
+ Contribution(s) alone or by combination of their Contribution(s) |
|
| 81 |
+ with the Work to which such Contribution(s) was submitted. If You |
|
| 82 |
+ institute patent litigation against any entity (including a |
|
| 83 |
+ cross-claim or counterclaim in a lawsuit) alleging that the Work |
|
| 84 |
+ or a Contribution incorporated within the Work constitutes direct |
|
| 85 |
+ or contributory patent infringement, then any patent licenses |
|
| 86 |
+ granted to You under this License for that Work shall terminate |
|
| 87 |
+ as of the date such litigation is filed. |
|
| 88 |
+ |
|
| 89 |
+ 4. Redistribution. You may reproduce and distribute copies of the |
|
| 90 |
+ Work or Derivative Works thereof in any medium, with or without |
|
| 91 |
+ modifications, and in Source or Object form, provided that You |
|
| 92 |
+ meet the following conditions: |
|
| 93 |
+ |
|
| 94 |
+ (a) You must give any other recipients of the Work or |
|
| 95 |
+ Derivative Works a copy of this License; and |
|
| 96 |
+ |
|
| 97 |
+ (b) You must cause any modified files to carry prominent notices |
|
| 98 |
+ stating that You changed the files; and |
|
| 99 |
+ |
|
| 100 |
+ (c) You must retain, in the Source form of any Derivative Works |
|
| 101 |
+ that You distribute, all copyright, patent, trademark, and |
|
| 102 |
+ attribution notices from the Source form of the Work, |
|
| 103 |
+ excluding those notices that do not pertain to any part of |
|
| 104 |
+ the Derivative Works; and |
|
| 105 |
+ |
|
| 106 |
+ (d) If the Work includes a "NOTICE" text file as part of its |
|
| 107 |
+ distribution, then any Derivative Works that You distribute must |
|
| 108 |
+ include a readable copy of the attribution notices contained |
|
| 109 |
+ within such NOTICE file, excluding those notices that do not |
|
| 110 |
+ pertain to any part of the Derivative Works, in at least one |
|
| 111 |
+ of the following places: within a NOTICE text file distributed |
|
| 112 |
+ as part of the Derivative Works; within the Source form or |
|
| 113 |
+ documentation, if provided along with the Derivative Works; or, |
|
| 114 |
+ within a display generated by the Derivative Works, if and |
|
| 115 |
+ wherever such third-party notices normally appear. The contents |
|
| 116 |
+ of the NOTICE file are for informational purposes only and |
|
| 117 |
+ do not modify the License. You may add Your own attribution |
|
| 118 |
+ notices within Derivative Works that You distribute, alongside |
|
| 119 |
+ or as an addendum to the NOTICE text from the Work, provided |
|
| 120 |
+ that such additional attribution notices cannot be construed |
|
| 121 |
+ as modifying the License. |
|
| 122 |
+ |
|
| 123 |
+ You may add Your own copyright statement to Your modifications and |
|
| 124 |
+ may provide additional or different license terms and conditions |
|
| 125 |
+ for use, reproduction, or distribution of Your modifications, or |
|
| 126 |
+ for any such Derivative Works as a whole, provided Your use, |
|
| 127 |
+ reproduction, and distribution of the Work otherwise complies with |
|
| 128 |
+ the conditions stated in this License. |
|
| 129 |
+ |
|
| 130 |
+ 5. Submission of Contributions. Unless You explicitly state otherwise, |
|
| 131 |
+ any Contribution intentionally submitted for inclusion in the Work |
|
| 132 |
+ by You to the Licensor shall be under the terms and conditions of |
|
| 133 |
+ this License, without any additional terms or conditions. |
|
| 134 |
+ Notwithstanding the above, nothing herein shall supersede or modify |
|
| 135 |
+ the terms of any separate license agreement you may have executed |
|
| 136 |
+ with Licensor regarding such Contributions. |
|
| 137 |
+ |
|
| 138 |
+ 6. Trademarks. This License does not grant permission to use the trade |
|
| 139 |
+ names, trademarks, service marks, or product names of the Licensor, |
|
| 140 |
+ except as required for reasonable and customary use in describing the |
|
| 141 |
+ origin of the Work and reproducing the content of the NOTICE file. |
|
| 142 |
+ |
|
| 143 |
+ 7. Disclaimer of Warranty. Unless required by applicable law or |
|
| 144 |
+ agreed to in writing, Licensor provides the Work (and each |
|
| 145 |
+ Contributor provides its Contributions) on an "AS IS" BASIS, |
|
| 146 |
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
|
| 147 |
+ implied, including, without limitation, any warranties or conditions |
|
| 148 |
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A |
|
| 149 |
+ PARTICULAR PURPOSE. You are solely responsible for determining the |
|
| 150 |
+ appropriateness of using or redistributing the Work and assume any |
|
| 151 |
+ risks associated with Your exercise of permissions under this License. |
|
| 152 |
+ |
|
| 153 |
+ 8. Limitation of Liability. In no event and under no legal theory, |
|
| 154 |
+ whether in tort (including negligence), contract, or otherwise, |
|
| 155 |
+ unless required by applicable law (such as deliberate and grossly |
|
| 156 |
+ negligent acts) or agreed to in writing, shall any Contributor be |
|
| 157 |
+ liable to You for damages, including any direct, indirect, special, |
|
| 158 |
+ incidental, or consequential damages of any character arising as a |
|
| 159 |
+ result of this License or out of the use or inability to use the |
|
| 160 |
+ Work (including but not limited to damages for loss of goodwill, |
|
| 161 |
+ work stoppage, computer failure or malfunction, or any and all |
|
| 162 |
+ other commercial damages or losses), even if such Contributor |
|
| 163 |
+ has been advised of the possibility of such damages. |
|
| 164 |
+ |
|
| 165 |
+ 9. Accepting Warranty or Additional Liability. While redistributing |
|
| 166 |
+ the Work or Derivative Works thereof, You may choose to offer, |
|
| 167 |
+ and charge a fee for, acceptance of support, warranty, indemnity, |
|
| 168 |
+ or other liability obligations and/or rights consistent with this |
|
| 169 |
+ License. However, in accepting such obligations, You may act only |
|
| 170 |
+ on Your own behalf and on Your sole responsibility, not on behalf |
|
| 171 |
+ of any other Contributor, and only if You agree to indemnify, |
|
| 172 |
+ defend, and hold each Contributor harmless for any liability |
|
| 173 |
+ incurred by, or claims asserted against, such Contributor by reason |
|
| 174 |
+ of your accepting any such warranty or additional liability. |
|
| 175 |
+ |
|
| 176 |
+ END OF TERMS AND CONDITIONS |
|
| 177 |
+ |
|
| 178 |
+ Copyright 2015 Docker, Inc. |
|
| 179 |
+ |
|
| 180 |
+ Licensed under the Apache License, Version 2.0 (the "License"); |
|
| 181 |
+ you may not use this file except in compliance with the License. |
|
| 182 |
+ You may obtain a copy of the License at |
|
| 183 |
+ |
|
| 184 |
+ https://www.apache.org/licenses/LICENSE-2.0 |
|
| 185 |
+ |
|
| 186 |
+ Unless required by applicable law or agreed to in writing, software |
|
| 187 |
+ distributed under the License is distributed on an "AS IS" BASIS, |
|
| 188 |
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
| 189 |
+ See the License for the specific language governing permissions and |
|
| 190 |
+ limitations under the License. |
| 0 | 191 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,11 @@ |
| 0 |
+# Introduction |
|
| 1 |
+ |
|
| 2 |
+go-units is a library to transform human friendly measurements into machine friendly values. |
|
| 3 |
+ |
|
| 4 |
+## Usage |
|
| 5 |
+ |
|
| 6 |
+See the [docs in godoc](https://godoc.org/github.com/docker/go-units) for examples and documentation. |
|
| 7 |
+ |
|
| 8 |
+## License |
|
| 9 |
+ |
|
| 10 |
+go-units is licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for the full license text. |
| 0 | 11 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,33 @@ |
| 0 |
+// Package units provides helper function to parse and print size and time units |
|
| 1 |
+// in human-readable format. |
|
| 2 |
+package units |
|
| 3 |
+ |
|
| 4 |
+import ( |
|
| 5 |
+ "fmt" |
|
| 6 |
+ "time" |
|
| 7 |
+) |
|
| 8 |
+ |
|
| 9 |
+// HumanDuration returns a human-readable approximation of a duration |
|
| 10 |
+// (eg. "About a minute", "4 hours ago", etc.). |
|
| 11 |
+func HumanDuration(d time.Duration) string {
|
|
| 12 |
+ if seconds := int(d.Seconds()); seconds < 1 {
|
|
| 13 |
+ return "Less than a second" |
|
| 14 |
+ } else if seconds < 60 {
|
|
| 15 |
+ return fmt.Sprintf("%d seconds", seconds)
|
|
| 16 |
+ } else if minutes := int(d.Minutes()); minutes == 1 {
|
|
| 17 |
+ return "About a minute" |
|
| 18 |
+ } else if minutes < 60 {
|
|
| 19 |
+ return fmt.Sprintf("%d minutes", minutes)
|
|
| 20 |
+ } else if hours := int(d.Hours()); hours == 1 {
|
|
| 21 |
+ return "About an hour" |
|
| 22 |
+ } else if hours < 48 {
|
|
| 23 |
+ return fmt.Sprintf("%d hours", hours)
|
|
| 24 |
+ } else if hours < 24*7*2 {
|
|
| 25 |
+ return fmt.Sprintf("%d days", hours/24)
|
|
| 26 |
+ } else if hours < 24*30*3 {
|
|
| 27 |
+ return fmt.Sprintf("%d weeks", hours/24/7)
|
|
| 28 |
+ } else if hours < 24*365*2 {
|
|
| 29 |
+ return fmt.Sprintf("%d months", hours/24/30)
|
|
| 30 |
+ } |
|
| 31 |
+ return fmt.Sprintf("%d years", int(d.Hours())/24/365)
|
|
| 32 |
+} |
| 0 | 33 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,95 @@ |
| 0 |
+package units |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "fmt" |
|
| 4 |
+ "regexp" |
|
| 5 |
+ "strconv" |
|
| 6 |
+ "strings" |
|
| 7 |
+) |
|
| 8 |
+ |
|
| 9 |
+// See: http://en.wikipedia.org/wiki/Binary_prefix |
|
| 10 |
+const ( |
|
| 11 |
+ // Decimal |
|
| 12 |
+ |
|
| 13 |
+ KB = 1000 |
|
| 14 |
+ MB = 1000 * KB |
|
| 15 |
+ GB = 1000 * MB |
|
| 16 |
+ TB = 1000 * GB |
|
| 17 |
+ PB = 1000 * TB |
|
| 18 |
+ |
|
| 19 |
+ // Binary |
|
| 20 |
+ |
|
| 21 |
+ KiB = 1024 |
|
| 22 |
+ MiB = 1024 * KiB |
|
| 23 |
+ GiB = 1024 * MiB |
|
| 24 |
+ TiB = 1024 * GiB |
|
| 25 |
+ PiB = 1024 * TiB |
|
| 26 |
+) |
|
| 27 |
+ |
|
| 28 |
+type unitMap map[string]int64 |
|
| 29 |
+ |
|
| 30 |
+var ( |
|
| 31 |
+ decimalMap = unitMap{"k": KB, "m": MB, "g": GB, "t": TB, "p": PB}
|
|
| 32 |
+ binaryMap = unitMap{"k": KiB, "m": MiB, "g": GiB, "t": TiB, "p": PiB}
|
|
| 33 |
+ sizeRegex = regexp.MustCompile(`^(\d+)([kKmMgGtTpP])?[bB]?$`) |
|
| 34 |
+) |
|
| 35 |
+ |
|
| 36 |
+var decimapAbbrs = []string{"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}
|
|
| 37 |
+var binaryAbbrs = []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"}
|
|
| 38 |
+ |
|
| 39 |
+// CustomSize returns a human-readable approximation of a size |
|
| 40 |
+// using custom format. |
|
| 41 |
+func CustomSize(format string, size float64, base float64, _map []string) string {
|
|
| 42 |
+ i := 0 |
|
| 43 |
+ for size >= base {
|
|
| 44 |
+ size = size / base |
|
| 45 |
+ i++ |
|
| 46 |
+ } |
|
| 47 |
+ return fmt.Sprintf(format, size, _map[i]) |
|
| 48 |
+} |
|
| 49 |
+ |
|
| 50 |
+// HumanSize returns a human-readable approximation of a size |
|
| 51 |
+// capped at 4 valid numbers (eg. "2.746 MB", "796 KB"). |
|
| 52 |
+func HumanSize(size float64) string {
|
|
| 53 |
+ return CustomSize("%.4g %s", size, 1000.0, decimapAbbrs)
|
|
| 54 |
+} |
|
| 55 |
+ |
|
| 56 |
+// BytesSize returns a human-readable size in bytes, kibibytes, |
|
| 57 |
+// mebibytes, gibibytes, or tebibytes (eg. "44kiB", "17MiB"). |
|
| 58 |
+func BytesSize(size float64) string {
|
|
| 59 |
+ return CustomSize("%.4g %s", size, 1024.0, binaryAbbrs)
|
|
| 60 |
+} |
|
| 61 |
+ |
|
| 62 |
+// FromHumanSize returns an integer from a human-readable specification of a |
|
| 63 |
+// size using SI standard (eg. "44kB", "17MB"). |
|
| 64 |
+func FromHumanSize(size string) (int64, error) {
|
|
| 65 |
+ return parseSize(size, decimalMap) |
|
| 66 |
+} |
|
| 67 |
+ |
|
| 68 |
+// RAMInBytes parses a human-readable string representing an amount of RAM |
|
| 69 |
+// in bytes, kibibytes, mebibytes, gibibytes, or tebibytes and |
|
| 70 |
+// returns the number of bytes, or -1 if the string is unparseable. |
|
| 71 |
+// Units are case-insensitive, and the 'b' suffix is optional. |
|
| 72 |
+func RAMInBytes(size string) (int64, error) {
|
|
| 73 |
+ return parseSize(size, binaryMap) |
|
| 74 |
+} |
|
| 75 |
+ |
|
| 76 |
+// Parses the human-readable size string into the amount it represents. |
|
| 77 |
+func parseSize(sizeStr string, uMap unitMap) (int64, error) {
|
|
| 78 |
+ matches := sizeRegex.FindStringSubmatch(sizeStr) |
|
| 79 |
+ if len(matches) != 3 {
|
|
| 80 |
+ return -1, fmt.Errorf("invalid size: '%s'", sizeStr)
|
|
| 81 |
+ } |
|
| 82 |
+ |
|
| 83 |
+ size, err := strconv.ParseInt(matches[1], 10, 0) |
|
| 84 |
+ if err != nil {
|
|
| 85 |
+ return -1, err |
|
| 86 |
+ } |
|
| 87 |
+ |
|
| 88 |
+ unitPrefix := strings.ToLower(matches[2]) |
|
| 89 |
+ if mul, ok := uMap[unitPrefix]; ok {
|
|
| 90 |
+ size *= mul |
|
| 91 |
+ } |
|
| 92 |
+ |
|
| 93 |
+ return size, nil |
|
| 94 |
+} |
| ... | ... |
@@ -78,6 +78,13 @@ func (p Process) Signal(sig os.Signal) error {
|
| 78 | 78 |
return p.ops.signal(sig) |
| 79 | 79 |
} |
| 80 | 80 |
|
| 81 |
+// IO holds the process's STDIO |
|
| 82 |
+type IO struct {
|
|
| 83 |
+ Stdin io.WriteCloser |
|
| 84 |
+ Stdout io.ReadCloser |
|
| 85 |
+ Stderr io.ReadCloser |
|
| 86 |
+} |
|
| 87 |
+ |
|
| 81 | 88 |
// NewConsole creates new console for process and returns it |
| 82 | 89 |
func (p *Process) NewConsole(rootuid int) (Console, error) {
|
| 83 | 90 |
console, err := NewConsole(rootuid, rootuid) |
| ... | ... |
@@ -320,3 +320,44 @@ func getPipeFds(pid int) ([]string, error) {
|
| 320 | 320 |
} |
| 321 | 321 |
return fds, nil |
| 322 | 322 |
} |
| 323 |
+ |
|
| 324 |
+// InitializeIO creates pipes for use with the process's STDIO |
|
| 325 |
+// and returns the opposite side for each |
|
| 326 |
+func (p *Process) InitializeIO(rootuid int) (i *IO, err error) {
|
|
| 327 |
+ var fds []uintptr |
|
| 328 |
+ i = &IO{}
|
|
| 329 |
+ // cleanup in case of an error |
|
| 330 |
+ defer func() {
|
|
| 331 |
+ if err != nil {
|
|
| 332 |
+ for _, fd := range fds {
|
|
| 333 |
+ syscall.Close(int(fd)) |
|
| 334 |
+ } |
|
| 335 |
+ } |
|
| 336 |
+ }() |
|
| 337 |
+ // STDIN |
|
| 338 |
+ r, w, err := os.Pipe() |
|
| 339 |
+ if err != nil {
|
|
| 340 |
+ return nil, err |
|
| 341 |
+ } |
|
| 342 |
+ fds = append(fds, r.Fd(), w.Fd()) |
|
| 343 |
+ p.Stdin, i.Stdin = r, w |
|
| 344 |
+ // STDOUT |
|
| 345 |
+ if r, w, err = os.Pipe(); err != nil {
|
|
| 346 |
+ return nil, err |
|
| 347 |
+ } |
|
| 348 |
+ fds = append(fds, r.Fd(), w.Fd()) |
|
| 349 |
+ p.Stdout, i.Stdout = w, r |
|
| 350 |
+ // STDERR |
|
| 351 |
+ if r, w, err = os.Pipe(); err != nil {
|
|
| 352 |
+ return nil, err |
|
| 353 |
+ } |
|
| 354 |
+ fds = append(fds, r.Fd(), w.Fd()) |
|
| 355 |
+ p.Stderr, i.Stderr = w, r |
|
| 356 |
+ // change ownership of the pipes incase we are in a user namespace |
|
| 357 |
+ for _, fd := range fds {
|
|
| 358 |
+ if err := syscall.Fchown(int(fd), rootuid, rootuid); err != nil {
|
|
| 359 |
+ return nil, err |
|
| 360 |
+ } |
|
| 361 |
+ } |
|
| 362 |
+ return i, nil |
|
| 363 |
+} |