Browse code

vendor: github.com/containerd/fifo 0724c46b320cf96bb172a0550c19a4b1fca4dacb

full diff: https://github.com/containerd/fifo/compare/f15a3290365b9d2627d189e619ab4008e0069caf...0724c46b320cf96bb172a0550c19a4b1fca4dacb

- Add OpenFifoDup2
- use golang.org/x/sys/unix for dup2 (fixes build on arm64)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2020/11/18 18:54:06
Showing 2 changed files
... ...
@@ -131,7 +131,7 @@ google.golang.org/genproto                          3f1135a288c9a07e340ae8ba4cc6
131 131
 
132 132
 # containerd
133 133
 github.com/containerd/containerd                    d4e78200d6da62480c85bf6f26b7221ea938f396
134
-github.com/containerd/fifo                          f15a3290365b9d2627d189e619ab4008e0069caf
134
+github.com/containerd/fifo                          0724c46b320cf96bb172a0550c19a4b1fca4dacb
135 135
 github.com/containerd/continuity                    efbc4488d8fe1bdc16bde3b2d2990d9b3a899165
136 136
 github.com/containerd/cgroups                       318312a373405e5e91134d8063d04d59768a1bff
137 137
 github.com/containerd/console                       5d7e1412f07b502a01029ea20e20e0d2be31fa7c # v1.0.1
... ...
@@ -25,6 +25,7 @@ import (
25 25
 	"syscall"
26 26
 
27 27
 	"github.com/pkg/errors"
28
+	"golang.org/x/sys/unix"
28 29
 )
29 30
 
30 31
 type fifo struct {
... ...
@@ -41,6 +42,21 @@ type fifo struct {
41 41
 
42 42
 var leakCheckWg *sync.WaitGroup
43 43
 
44
+// OpenFifoDup2 is same as OpenFifo, but additionally creates a copy of the FIFO file descriptor with dup2 syscall.
45
+func OpenFifoDup2(ctx context.Context, fn string, flag int, perm os.FileMode, fd int) (io.ReadWriteCloser, error) {
46
+	f, err := openFifo(ctx, fn, flag, perm)
47
+	if err != nil {
48
+		return nil, errors.Wrap(err, "fifo error")
49
+	}
50
+
51
+	if err := unix.Dup2(int(f.file.Fd()), fd); err != nil {
52
+		_ = f.Close()
53
+		return nil, errors.Wrap(err, "dup2 error")
54
+	}
55
+
56
+	return f, nil
57
+}
58
+
44 59
 // OpenFifo opens a fifo. Returns io.ReadWriteCloser.
45 60
 // Context can be used to cancel this function until open(2) has not returned.
46 61
 // Accepted flags:
... ...
@@ -52,6 +68,10 @@ var leakCheckWg *sync.WaitGroup
52 52
 //     fifo isn't open. read/write will be connected after the actual fifo is
53 53
 //     open or after fifo is closed.
54 54
 func OpenFifo(ctx context.Context, fn string, flag int, perm os.FileMode) (io.ReadWriteCloser, error) {
55
+	return openFifo(ctx, fn, flag, perm)
56
+}
57
+
58
+func openFifo(ctx context.Context, fn string, flag int, perm os.FileMode) (*fifo, error) {
55 59
 	if _, err := os.Stat(fn); err != nil {
56 60
 		if os.IsNotExist(err) && flag&syscall.O_CREAT != 0 {
57 61
 			if err := mkfifo(fn, uint32(perm&os.ModePerm)); err != nil && !os.IsExist(err) {