Merge pull request #3545 from estesp/update-fifo
Update fifo vendoring for typed errors
This commit is contained in:
commit
c62b7444ef
@ -2,7 +2,7 @@ github.com/containerd/go-runc 9007c2405372fe28918845901a3276c0915689a1
|
||||
github.com/containerd/console 0650fd9eeb50bab4fc99dceb9f2e14cf58f36e7f
|
||||
github.com/containerd/cgroups c4b9ac5c7601384c965b9646fc515884e091ebb9
|
||||
github.com/containerd/typeurl a93fcdb778cd272c6e9b3028b2f42d813e785d40
|
||||
github.com/containerd/fifo 3d5202aec260678c48179c56f40e6f38a095738c
|
||||
github.com/containerd/fifo bda0ff6ed73c67bfb5e62bc9c697f146b7fd7f13
|
||||
github.com/containerd/btrfs af5082808c833de0e79c1e72eea9fea239364877
|
||||
github.com/containerd/continuity bd77b46c8352f74eb12c85bdc01f4b90f69d66b4
|
||||
github.com/coreos/go-systemd 48702e0da86bd25e76cfef347e2adeb434a0d0a6
|
||||
|
30
vendor/github.com/containerd/fifo/errors.go
generated
vendored
Normal file
30
vendor/github.com/containerd/fifo/errors.go
generated
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
Copyright The containerd Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package fifo
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrClosed = errors.New("fifo closed")
|
||||
ErrCtrlClosed = errors.New("control of closed fifo")
|
||||
ErrRdFrmWRONLY = errors.New("reading from write-only fifo")
|
||||
ErrReadClosed = errors.New("reading from a closed fifo")
|
||||
ErrWrToRDONLY = errors.New("writing to read-only fifo")
|
||||
ErrWriteClosed = errors.New("writing to a closed fifo")
|
||||
)
|
8
vendor/github.com/containerd/fifo/fifo.go
generated
vendored
8
vendor/github.com/containerd/fifo/fifo.go
generated
vendored
@ -147,7 +147,7 @@ func OpenFifo(ctx context.Context, fn string, flag int, perm os.FileMode) (io.Re
|
||||
// Read from a fifo to a byte array.
|
||||
func (f *fifo) Read(b []byte) (int, error) {
|
||||
if f.flag&syscall.O_WRONLY > 0 {
|
||||
return 0, errors.New("reading from write-only fifo")
|
||||
return 0, ErrRdFrmWRONLY
|
||||
}
|
||||
select {
|
||||
case <-f.opened:
|
||||
@ -158,14 +158,14 @@ func (f *fifo) Read(b []byte) (int, error) {
|
||||
case <-f.opened:
|
||||
return f.file.Read(b)
|
||||
case <-f.closed:
|
||||
return 0, errors.New("reading from a closed fifo")
|
||||
return 0, ErrReadClosed
|
||||
}
|
||||
}
|
||||
|
||||
// Write from byte array to a fifo.
|
||||
func (f *fifo) Write(b []byte) (int, error) {
|
||||
if f.flag&(syscall.O_WRONLY|syscall.O_RDWR) == 0 {
|
||||
return 0, errors.New("writing to read-only fifo")
|
||||
return 0, ErrWrToRDONLY
|
||||
}
|
||||
select {
|
||||
case <-f.opened:
|
||||
@ -176,7 +176,7 @@ func (f *fifo) Write(b []byte) (int, error) {
|
||||
case <-f.opened:
|
||||
return f.file.Write(b)
|
||||
case <-f.closed:
|
||||
return 0, errors.New("writing to a closed fifo")
|
||||
return 0, ErrWriteClosed
|
||||
}
|
||||
}
|
||||
|
||||
|
114
vendor/github.com/containerd/fifo/raw.go
generated
vendored
Normal file
114
vendor/github.com/containerd/fifo/raw.go
generated
vendored
Normal file
@ -0,0 +1,114 @@
|
||||
// +build go1.12
|
||||
|
||||
/*
|
||||
Copyright The containerd Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package fifo
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// SyscallConn provides raw access to the fifo's underlying filedescrptor.
|
||||
// See syscall.Conn for guarentees provided by this interface.
|
||||
func (f *fifo) SyscallConn() (syscall.RawConn, error) {
|
||||
// deterministic check for closed
|
||||
select {
|
||||
case <-f.closed:
|
||||
return nil, ErrClosed
|
||||
default:
|
||||
}
|
||||
|
||||
select {
|
||||
case <-f.closed:
|
||||
return nil, ErrClosed
|
||||
case <-f.opened:
|
||||
return f.file.SyscallConn()
|
||||
default:
|
||||
}
|
||||
|
||||
// Not opened and not closed, this means open is non-blocking AND it's not open yet
|
||||
// Use rawConn to deal with non-blocking open.
|
||||
rc := &rawConn{f: f, ready: make(chan struct{})}
|
||||
go func() {
|
||||
select {
|
||||
case <-f.closed:
|
||||
return
|
||||
case <-f.opened:
|
||||
rc.raw, rc.err = f.file.SyscallConn()
|
||||
close(rc.ready)
|
||||
}
|
||||
}()
|
||||
|
||||
return rc, nil
|
||||
}
|
||||
|
||||
type rawConn struct {
|
||||
f *fifo
|
||||
ready chan struct{}
|
||||
raw syscall.RawConn
|
||||
err error
|
||||
}
|
||||
|
||||
func (r *rawConn) Control(f func(fd uintptr)) error {
|
||||
select {
|
||||
case <-r.f.closed:
|
||||
return ErrCtrlClosed
|
||||
case <-r.ready:
|
||||
}
|
||||
|
||||
if r.err != nil {
|
||||
return r.err
|
||||
}
|
||||
|
||||
return r.raw.Control(f)
|
||||
}
|
||||
|
||||
func (r *rawConn) Read(f func(fd uintptr) (done bool)) error {
|
||||
if r.f.flag&syscall.O_WRONLY > 0 {
|
||||
return ErrRdFrmWRONLY
|
||||
}
|
||||
|
||||
select {
|
||||
case <-r.f.closed:
|
||||
return ErrReadClosed
|
||||
case <-r.ready:
|
||||
}
|
||||
|
||||
if r.err != nil {
|
||||
return r.err
|
||||
}
|
||||
|
||||
return r.raw.Read(f)
|
||||
}
|
||||
|
||||
func (r *rawConn) Write(f func(fd uintptr) (done bool)) error {
|
||||
if r.f.flag&(syscall.O_WRONLY|syscall.O_RDWR) == 0 {
|
||||
return ErrWrToRDONLY
|
||||
}
|
||||
|
||||
select {
|
||||
case <-r.f.closed:
|
||||
return ErrWriteClosed
|
||||
case <-r.ready:
|
||||
}
|
||||
|
||||
if r.err != nil {
|
||||
return r.err
|
||||
}
|
||||
|
||||
return r.raw.Write(f)
|
||||
}
|
12
vendor/github.com/containerd/fifo/readme.md
generated
vendored
12
vendor/github.com/containerd/fifo/readme.md
generated
vendored
@ -1,6 +1,7 @@
|
||||
### fifo
|
||||
|
||||
[](https://travis-ci.org/containerd/fifo)
|
||||
[](https://codecov.io/gh/containerd/fifo)
|
||||
|
||||
Go package for handling fifos in a sane way.
|
||||
|
||||
@ -30,3 +31,14 @@ func (f *fifo) Write(b []byte) (int, error)
|
||||
// before open(2) has returned and fifo was never opened.
|
||||
func (f *fifo) Close() error
|
||||
```
|
||||
|
||||
## Project details
|
||||
|
||||
The fifo is a containerd sub-project, licensed under the [Apache 2.0 license](./LICENSE).
|
||||
As a containerd sub-project, you will find the:
|
||||
|
||||
* [Project governance](https://github.com/containerd/project/blob/master/GOVERNANCE.md),
|
||||
* [Maintainers](https://github.com/containerd/project/blob/master/MAINTAINERS),
|
||||
* and [Contributing guidelines](https://github.com/containerd/project/blob/master/CONTRIBUTING.md)
|
||||
|
||||
information in our [`containerd/project`](https://github.com/containerd/project) repository.
|
||||
|
Loading…
Reference in New Issue
Block a user