mirror of https://github.com/docker/cli.git
bump containerd/fifo a9fb20d87448d386e6d50b1f2e1fa70dcf0de43c
- containerd/fifo#17 Expose underlying file's `SyscallConn` method Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
eeaa4e543a
commit
ac234326a6
|
@ -6,7 +6,7 @@ github.com/beorn7/perks 3a771d992973f24aa725d07868b4
|
|||
github.com/containerd/console c12b1e7919c14469339a5d38f2f8ed9b64a9de23
|
||||
github.com/containerd/containerd ceba56893a76f22cf0126c46d835c80fb3833408
|
||||
github.com/containerd/continuity 004b46473808b3e7a4a3049c20e4376c91eb966d
|
||||
github.com/containerd/fifo 3d5202aec260678c48179c56f40e6f38a095738c
|
||||
github.com/containerd/fifo a9fb20d87448d386e6d50b1f2e1fa70dcf0de43c
|
||||
github.com/containerd/typeurl a93fcdb778cd272c6e9b3028b2f42d813e785d40
|
||||
github.com/coreos/etcd fca8add78a9d926166eb739b8e4a124434025ba3 # v3.3.9
|
||||
github.com/cpuguy83/go-md2man 20f5889cbdc3c73dbd2862796665e7c465ade7d1 # v1.0.8
|
||||
|
|
|
@ -0,0 +1,116 @@
|
|||
// +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"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// 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, errors.New("fifo closed")
|
||||
default:
|
||||
}
|
||||
|
||||
select {
|
||||
case <-f.closed:
|
||||
return nil, errors.New("fifo closed")
|
||||
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 errors.New("control of closed fifo")
|
||||
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 errors.New("reading from write-only fifo")
|
||||
}
|
||||
|
||||
select {
|
||||
case <-r.f.closed:
|
||||
return errors.New("reading of a closed fifo")
|
||||
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 errors.New("writing to read-only fifo")
|
||||
}
|
||||
|
||||
select {
|
||||
case <-r.f.closed:
|
||||
return errors.New("writing to a closed fifo")
|
||||
case <-r.ready:
|
||||
}
|
||||
|
||||
if r.err != nil {
|
||||
return r.err
|
||||
}
|
||||
|
||||
return r.raw.Write(f)
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
### fifo
|
||||
|
||||
[![Build Status](https://travis-ci.org/containerd/fifo.svg?branch=master)](https://travis-ci.org/containerd/fifo)
|
||||
[![codecov](https://codecov.io/gh/containerd/fifo/branch/master/graph/badge.svg)](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