go.mod: github.com/containerd/fifo v1.1.0

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
Akihiro Suda 2023-03-07 21:51:15 +09:00
parent 6d95132313
commit 5630d6a840
No known key found for this signature in database
GPG Key ID: 49524C6F9F638F1A
10 changed files with 69 additions and 44 deletions

2
go.mod
View File

@ -13,7 +13,7 @@ require (
github.com/containerd/cgroups/v3 v3.0.1 github.com/containerd/cgroups/v3 v3.0.1
github.com/containerd/console v1.0.3 github.com/containerd/console v1.0.3
github.com/containerd/continuity v0.3.0 github.com/containerd/continuity v0.3.0
github.com/containerd/fifo v1.0.0 github.com/containerd/fifo v1.1.0
github.com/containerd/go-cni v1.1.9 github.com/containerd/go-cni v1.1.9
github.com/containerd/go-runc v1.0.0 github.com/containerd/go-runc v1.0.0
github.com/containerd/imgcrypt v1.1.7 github.com/containerd/imgcrypt v1.1.7

3
go.sum
View File

@ -239,8 +239,9 @@ github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448/go.mod h1:ODA38xgv
github.com/containerd/fifo v0.0.0-20200410184934-f15a3290365b/go.mod h1:jPQ2IAeZRCYxpS/Cm1495vGFww6ecHmMk1YJH2Q5ln0= github.com/containerd/fifo v0.0.0-20200410184934-f15a3290365b/go.mod h1:jPQ2IAeZRCYxpS/Cm1495vGFww6ecHmMk1YJH2Q5ln0=
github.com/containerd/fifo v0.0.0-20201026212402-0724c46b320c/go.mod h1:jPQ2IAeZRCYxpS/Cm1495vGFww6ecHmMk1YJH2Q5ln0= github.com/containerd/fifo v0.0.0-20201026212402-0724c46b320c/go.mod h1:jPQ2IAeZRCYxpS/Cm1495vGFww6ecHmMk1YJH2Q5ln0=
github.com/containerd/fifo v0.0.0-20210316144830-115abcc95a1d/go.mod h1:ocF/ME1SX5b1AOlWi9r677YJmCPSwwWnQ9O123vzpE4= github.com/containerd/fifo v0.0.0-20210316144830-115abcc95a1d/go.mod h1:ocF/ME1SX5b1AOlWi9r677YJmCPSwwWnQ9O123vzpE4=
github.com/containerd/fifo v1.0.0 h1:6PirWBr9/L7GDamKr+XM0IeUFXu5mf3M/BPpH9gaLBU=
github.com/containerd/fifo v1.0.0/go.mod h1:ocF/ME1SX5b1AOlWi9r677YJmCPSwwWnQ9O123vzpE4= github.com/containerd/fifo v1.0.0/go.mod h1:ocF/ME1SX5b1AOlWi9r677YJmCPSwwWnQ9O123vzpE4=
github.com/containerd/fifo v1.1.0 h1:4I2mbh5stb1u6ycIABlBw9zgtlK8viPI9QkQNRQEEmY=
github.com/containerd/fifo v1.1.0/go.mod h1:bmC4NWMbXlt2EZ0Hc7Fx7QzTFxgPID13eH0Qu+MAb2o=
github.com/containerd/go-cni v1.0.1/go.mod h1:+vUpYxKvAF72G9i1WoDOiPGRtQpqsNW/ZHtSlv++smU= github.com/containerd/go-cni v1.0.1/go.mod h1:+vUpYxKvAF72G9i1WoDOiPGRtQpqsNW/ZHtSlv++smU=
github.com/containerd/go-cni v1.0.2/go.mod h1:nrNABBHzu0ZwCug9Ije8hL2xBCYh/pjfMb1aZGrrohk= github.com/containerd/go-cni v1.0.2/go.mod h1:nrNABBHzu0ZwCug9Ije8hL2xBCYh/pjfMb1aZGrrohk=
github.com/containerd/go-cni v1.1.0/go.mod h1:Rflh2EJ/++BA2/vY5ao3K6WJRR/bZKsX123aPk+kUtA= github.com/containerd/go-cni v1.1.0/go.mod h1:Rflh2EJ/++BA2/vY5ao3K6WJRR/bZKsX123aPk+kUtA=

View File

@ -28,7 +28,7 @@ require (
github.com/containerd/cgroups v1.1.0 // indirect github.com/containerd/cgroups v1.1.0 // indirect
github.com/containerd/console v1.0.3 // indirect github.com/containerd/console v1.0.3 // indirect
github.com/containerd/continuity v0.3.0 // indirect github.com/containerd/continuity v0.3.0 // indirect
github.com/containerd/fifo v1.0.0 // indirect github.com/containerd/fifo v1.1.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cyphar/filepath-securejoin v0.2.3 // indirect github.com/cyphar/filepath-securejoin v0.2.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect

View File

@ -506,8 +506,9 @@ github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkX
github.com/containerd/continuity v0.0.0-20210208174643-50096c924a4e/go.mod h1:EXlVlkqNba9rJe3j7w3Xa924itAMLgZH4UD/Q4PExuQ= github.com/containerd/continuity v0.0.0-20210208174643-50096c924a4e/go.mod h1:EXlVlkqNba9rJe3j7w3Xa924itAMLgZH4UD/Q4PExuQ=
github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg= github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg=
github.com/containerd/continuity v0.3.0/go.mod h1:wJEAIwKOm/pBZuBd0JmeTvnLquTB1Ag8espWhkykbPM= github.com/containerd/continuity v0.3.0/go.mod h1:wJEAIwKOm/pBZuBd0JmeTvnLquTB1Ag8espWhkykbPM=
github.com/containerd/fifo v1.0.0 h1:6PirWBr9/L7GDamKr+XM0IeUFXu5mf3M/BPpH9gaLBU=
github.com/containerd/fifo v1.0.0/go.mod h1:ocF/ME1SX5b1AOlWi9r677YJmCPSwwWnQ9O123vzpE4= github.com/containerd/fifo v1.0.0/go.mod h1:ocF/ME1SX5b1AOlWi9r677YJmCPSwwWnQ9O123vzpE4=
github.com/containerd/fifo v1.1.0 h1:4I2mbh5stb1u6ycIABlBw9zgtlK8viPI9QkQNRQEEmY=
github.com/containerd/fifo v1.1.0/go.mod h1:bmC4NWMbXlt2EZ0Hc7Fx7QzTFxgPID13eH0Qu+MAb2o=
github.com/containerd/go-cni v1.1.6/go.mod h1:BWtoWl5ghVymxu6MBjg79W9NZrCRyHIdUtk4cauMe34= github.com/containerd/go-cni v1.1.6/go.mod h1:BWtoWl5ghVymxu6MBjg79W9NZrCRyHIdUtk4cauMe34=
github.com/containerd/go-cni v1.1.9/go.mod h1:XYrZJ1d5W6E2VOvjffL3IZq0Dz6bsVlERHbekNK90PM= github.com/containerd/go-cni v1.1.9/go.mod h1:XYrZJ1d5W6E2VOvjffL3IZq0Dz6bsVlERHbekNK90PM=
github.com/containerd/go-runc v0.0.0-20200220073739-7016d3ce2328/go.mod h1:PpyHrqVs8FTi9vpyHwPwiNEGaACDxT/N/pLcvMSRA9g= github.com/containerd/go-runc v0.0.0-20200220073739-7016d3ce2328/go.mod h1:PpyHrqVs8FTi9vpyHwPwiNEGaACDxT/N/pLcvMSRA9g=

View File

@ -1,19 +1,35 @@
linters: linters:
enable: enable:
- structcheck - exportloopref # Checks for pointers to enclosing loop variables
- varcheck
- staticcheck
- unconvert
- gofmt - gofmt
- goimports - goimports
- golint - gosec
- ineffassign - ineffassign
- vet
- unused
- misspell - misspell
- nolintlint
- revive
- staticcheck
- tenv # Detects using os.Setenv instead of t.Setenv since Go 1.17
- unconvert
- unused
- vet
- dupword # Checks for duplicate words in the source code
disable: disable:
- errcheck - errcheck
linters-settings:
gosec:
# The following issues surfaced when `gosec` linter
# was enabled. They are temporarily excluded to unblock
# the existing workflow, but still to be addressed by
# future works.
excludes:
- G204
- G305
- G306
- G402
- G404
run: run:
timeout: 3m timeout: 3m
skip-dirs: skip-dirs:

View File

@ -1,4 +1,4 @@
// +build !windows //go:build !windows
/* /*
Copyright The containerd Authors. Copyright The containerd Authors.
@ -20,13 +20,13 @@ package fifo
import ( import (
"context" "context"
"fmt"
"io" "io"
"os" "os"
"runtime" "runtime"
"sync" "sync"
"syscall" "syscall"
"github.com/pkg/errors"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
@ -48,12 +48,12 @@ var leakCheckWg *sync.WaitGroup
func OpenFifoDup2(ctx context.Context, fn string, flag int, perm os.FileMode, fd int) (io.ReadWriteCloser, error) { func OpenFifoDup2(ctx context.Context, fn string, flag int, perm os.FileMode, fd int) (io.ReadWriteCloser, error) {
f, err := openFifo(ctx, fn, flag, perm) f, err := openFifo(ctx, fn, flag, perm)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "fifo error") return nil, fmt.Errorf("fifo error: %w", err)
} }
if err := unix.Dup2(int(f.file.Fd()), fd); err != nil { if err := unix.Dup2(int(f.file.Fd()), fd); err != nil {
_ = f.Close() _ = f.Close()
return nil, errors.Wrap(err, "dup2 error") return nil, fmt.Errorf("dup2 error: %w", err)
} }
return f, nil return f, nil
@ -62,22 +62,28 @@ func OpenFifoDup2(ctx context.Context, fn string, flag int, perm os.FileMode, fd
// OpenFifo opens a fifo. Returns io.ReadWriteCloser. // OpenFifo opens a fifo. Returns io.ReadWriteCloser.
// Context can be used to cancel this function until open(2) has not returned. // Context can be used to cancel this function until open(2) has not returned.
// Accepted flags: // Accepted flags:
// - syscall.O_CREAT - create new fifo if one doesn't exist // - syscall.O_CREAT - create new fifo if one doesn't exist
// - syscall.O_RDONLY - open fifo only from reader side // - syscall.O_RDONLY - open fifo only from reader side
// - syscall.O_WRONLY - open fifo only from writer side // - syscall.O_WRONLY - open fifo only from writer side
// - syscall.O_RDWR - open fifo from both sides, never block on syscall level // - syscall.O_RDWR - open fifo from both sides, never block on syscall level
// - syscall.O_NONBLOCK - return io.ReadWriteCloser even if other side of the // - syscall.O_NONBLOCK - return io.ReadWriteCloser even if other side of the
// fifo isn't open. read/write will be connected after the actual fifo is // fifo isn't open. read/write will be connected after the actual fifo is
// open or after fifo is closed. // open or after fifo is closed.
func OpenFifo(ctx context.Context, fn string, flag int, perm os.FileMode) (io.ReadWriteCloser, error) { func OpenFifo(ctx context.Context, fn string, flag int, perm os.FileMode) (io.ReadWriteCloser, error) {
return openFifo(ctx, fn, flag, perm) fifo, err := openFifo(ctx, fn, flag, perm)
if fifo == nil {
// Do not return a non-nil ReadWriteCloser((*fifo)(nil)) value
// as that can confuse callers.
return nil, err
}
return fifo, err
} }
func openFifo(ctx context.Context, fn string, flag int, perm os.FileMode) (*fifo, error) { func openFifo(ctx context.Context, fn string, flag int, perm os.FileMode) (*fifo, error) {
if _, err := os.Stat(fn); err != nil { if _, err := os.Stat(fn); err != nil {
if os.IsNotExist(err) && flag&syscall.O_CREAT != 0 { if os.IsNotExist(err) && flag&syscall.O_CREAT != 0 {
if err := syscall.Mkfifo(fn, uint32(perm&os.ModePerm)); err != nil && !os.IsExist(err) { if err := syscall.Mkfifo(fn, uint32(perm&os.ModePerm)); err != nil && !os.IsExist(err) {
return nil, errors.Wrapf(err, "error creating fifo %v", fn) return nil, fmt.Errorf("error creating fifo %v: %w", fn, err)
} }
} else { } else {
return nil, err return nil, err
@ -138,7 +144,7 @@ func openFifo(ctx context.Context, fn string, flag int, perm os.FileMode) (*fifo
case <-ctx.Done(): case <-ctx.Done():
err = ctx.Err() err = ctx.Err()
default: default:
err = errors.Errorf("fifo %v was closed before opening", h.Name()) err = fmt.Errorf("fifo %v was closed before opening", h.Name())
} }
if file != nil { if file != nil {
file.Close() file.Close()
@ -206,6 +212,10 @@ func (f *fifo) Write(b []byte) (int, error) {
// before open(2) has returned and fifo was never opened. // before open(2) has returned and fifo was never opened.
func (f *fifo) Close() (retErr error) { func (f *fifo) Close() (retErr error) {
for { for {
if f == nil {
return
}
select { select {
case <-f.closed: case <-f.closed:
f.handle.Close() f.handle.Close()

View File

@ -1,4 +1,4 @@
// +build linux //go:build linux
/* /*
Copyright The containerd Authors. Copyright The containerd Authors.
@ -23,11 +23,9 @@ import (
"os" "os"
"sync" "sync"
"syscall" "syscall"
"github.com/pkg/errors"
) )
//nolint:golint //nolint:revive
const O_PATH = 010000000 const O_PATH = 010000000
type handle struct { type handle struct {
@ -42,7 +40,7 @@ type handle struct {
func getHandle(fn string) (*handle, error) { func getHandle(fn string) (*handle, error) {
f, err := os.OpenFile(fn, O_PATH, 0) f, err := os.OpenFile(fn, O_PATH, 0)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to open %v with O_PATH", fn) return nil, fmt.Errorf("failed to open %v with O_PATH: %w", fn, err)
} }
var ( var (
@ -51,7 +49,7 @@ func getHandle(fn string) (*handle, error) {
) )
if err := syscall.Fstat(int(fd), &stat); err != nil { if err := syscall.Fstat(int(fd), &stat); err != nil {
f.Close() f.Close()
return nil, errors.Wrapf(err, "failed to stat handle %v", fd) return nil, fmt.Errorf("failed to stat handle %v: %w", fd, err)
} }
h := &handle{ h := &handle{
@ -66,7 +64,7 @@ func getHandle(fn string) (*handle, error) {
// check /proc just in case // check /proc just in case
if _, err := os.Stat(h.procPath()); err != nil { if _, err := os.Stat(h.procPath()); err != nil {
f.Close() f.Close()
return nil, errors.Wrapf(err, "couldn't stat %v", h.procPath()) return nil, fmt.Errorf("couldn't stat %v: %w", h.procPath(), err)
} }
return h, nil return h, nil
@ -83,11 +81,11 @@ func (h *handle) Name() string {
func (h *handle) Path() (string, error) { func (h *handle) Path() (string, error) {
var stat syscall.Stat_t var stat syscall.Stat_t
if err := syscall.Stat(h.procPath(), &stat); err != nil { if err := syscall.Stat(h.procPath(), &stat); err != nil {
return "", errors.Wrapf(err, "path %v could not be statted", h.procPath()) return "", fmt.Errorf("path %v could not be statted: %w", h.procPath(), err)
} }
//nolint:unconvert //nolint:unconvert
if uint64(stat.Dev) != h.dev || stat.Ino != h.ino { if uint64(stat.Dev) != h.dev || stat.Ino != h.ino {
return "", errors.Errorf("failed to verify handle %v/%v %v/%v", stat.Dev, h.dev, stat.Ino, h.ino) return "", fmt.Errorf("failed to verify handle %v/%v %v/%v", stat.Dev, h.dev, stat.Ino, h.ino)
} }
return h.procPath(), nil return h.procPath(), nil
} }

View File

@ -1,4 +1,4 @@
// +build !linux,!windows //go:build !linux && !windows
/* /*
Copyright The containerd Authors. Copyright The containerd Authors.
@ -19,9 +19,8 @@
package fifo package fifo
import ( import (
"fmt"
"syscall" "syscall"
"github.com/pkg/errors"
) )
type handle struct { type handle struct {
@ -33,13 +32,13 @@ type handle struct {
func getHandle(fn string) (*handle, error) { func getHandle(fn string) (*handle, error) {
var stat syscall.Stat_t var stat syscall.Stat_t
if err := syscall.Stat(fn, &stat); err != nil { if err := syscall.Stat(fn, &stat); err != nil {
return nil, errors.Wrapf(err, "failed to stat %v", fn) return nil, fmt.Errorf("failed to stat %v: %w", fn, err)
} }
h := &handle{ h := &handle{
fn: fn, fn: fn,
dev: uint64(stat.Dev), //nolint: unconvert dev: uint64(stat.Dev), //nolint:unconvert,nolintlint
ino: uint64(stat.Ino), //nolint: unconvert ino: uint64(stat.Ino), //nolint:unconvert,nolintlint
} }
return h, nil return h, nil
@ -48,10 +47,10 @@ func getHandle(fn string) (*handle, error) {
func (h *handle) Path() (string, error) { func (h *handle) Path() (string, error) {
var stat syscall.Stat_t var stat syscall.Stat_t
if err := syscall.Stat(h.fn, &stat); err != nil { if err := syscall.Stat(h.fn, &stat); err != nil {
return "", errors.Wrapf(err, "path %v could not be statted", h.fn) return "", fmt.Errorf("path %v could not be statted: %w", h.fn, err)
} }
if uint64(stat.Dev) != h.dev || uint64(stat.Ino) != h.ino { //nolint: unconvert if uint64(stat.Dev) != h.dev || uint64(stat.Ino) != h.ino { //nolint:unconvert,nolintlint
return "", errors.Errorf("failed to verify handle %v/%v %v/%v for %v", stat.Dev, h.dev, stat.Ino, h.ino, h.fn) return "", fmt.Errorf("failed to verify handle %v/%v %v/%v for %v", stat.Dev, h.dev, stat.Ino, h.ino, h.fn)
} }
return h.fn, nil return h.fn, nil
} }

View File

@ -1,4 +1,4 @@
// +build !windows //go:build !windows
/* /*
Copyright The containerd Authors. Copyright The containerd Authors.

4
vendor/modules.txt vendored
View File

@ -113,8 +113,8 @@ github.com/containerd/continuity/proto
github.com/containerd/continuity/sysx github.com/containerd/continuity/sysx
github.com/containerd/continuity/testutil github.com/containerd/continuity/testutil
github.com/containerd/continuity/testutil/loopback github.com/containerd/continuity/testutil/loopback
# github.com/containerd/fifo v1.0.0 # github.com/containerd/fifo v1.1.0
## explicit; go 1.13 ## explicit; go 1.18
github.com/containerd/fifo github.com/containerd/fifo
# github.com/containerd/go-cni v1.1.9 # github.com/containerd/go-cni v1.1.9
## explicit; go 1.19 ## explicit; go 1.19