Skip to content

Commit 14d8313

Browse files
committed
exclude OpenFifoDup2() on Windows
Commit 9c214ed updated this function, and replaced syscall.Dup2() for golang.org/x/sys/unix.Dup2(), which is not available on Windows. This patch splits the API from the implementation, and moves the unix implementation to a "unix" file; a stub is added for Windows. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 115abcc commit 14d8313

3 files changed

Lines changed: 74 additions & 12 deletions

File tree

fifo.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"syscall"
2626

2727
"github.com/pkg/errors"
28-
"golang.org/x/sys/unix"
2928
)
3029

3130
type fifo struct {
@@ -44,17 +43,7 @@ var leakCheckWg *sync.WaitGroup
4443

4544
// OpenFifoDup2 is same as OpenFifo, but additionally creates a copy of the FIFO file descriptor with dup2 syscall.
4645
func OpenFifoDup2(ctx context.Context, fn string, flag int, perm os.FileMode, fd int) (io.ReadWriteCloser, error) {
47-
f, err := openFifo(ctx, fn, flag, perm)
48-
if err != nil {
49-
return nil, errors.Wrap(err, "fifo error")
50-
}
51-
52-
if err := unix.Dup2(int(f.file.Fd()), fd); err != nil {
53-
_ = f.Close()
54-
return nil, errors.Wrap(err, "dup2 error")
55-
}
56-
57-
return f, nil
46+
return openFifoDup2(ctx, fn, flag, perm, fd)
5847
}
5948

6049
// OpenFifo opens a fifo. Returns io.ReadWriteCloser.

fifo_unix.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// +build !windows
2+
3+
/*
4+
Copyright The containerd Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package fifo
20+
21+
import (
22+
"context"
23+
"io"
24+
"os"
25+
26+
"github.com/pkg/errors"
27+
"golang.org/x/sys/unix"
28+
)
29+
30+
// openFifoDup2 is same as OpenFifo, but additionally creates a copy of the FIFO file descriptor with dup2 syscall.
31+
func openFifoDup2(ctx context.Context, fn string, flag int, perm os.FileMode, fd int) (io.ReadWriteCloser, error) {
32+
f, err := openFifo(ctx, fn, flag, perm)
33+
if err != nil {
34+
return nil, errors.Wrap(err, "fifo error")
35+
}
36+
37+
if err := unix.Dup2(int(f.file.Fd()), fd); err != nil {
38+
_ = f.Close()
39+
return nil, errors.Wrap(err, "dup2 error")
40+
}
41+
42+
return f, nil
43+
}

fifo_windows.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package fifo
18+
19+
import (
20+
"context"
21+
"io"
22+
"os"
23+
24+
"github.com/pkg/errors"
25+
)
26+
27+
// openFifoDup2 is not supported on Windows
28+
func openFifoDup2(ctx context.Context, fn string, flag int, perm os.FileMode, fd int) (io.ReadWriteCloser, error) {
29+
return nil, errors.New("not supported")
30+
}

0 commit comments

Comments
 (0)