Skip to content

Commit b459209

Browse files
committed
Compile for FreeBSD
Signed-off-by: Samuel Karp <[email protected]>
1 parent 51f9eaf commit b459209

4 files changed

Lines changed: 77 additions & 7 deletions

File tree

archive/tar_freebsd.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// +build freebsd
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 archive
20+
21+
import "golang.org/x/sys/unix"
22+
23+
// mknod wraps unix.Mknod. FreeBSD's unix.Mknod signature is different from
24+
// other Unix and Unix-like operating systems.
25+
func mknod(path string, mode uint32, dev uint64) error {
26+
return unix.Mknod(path, mode, dev)
27+
}
28+
29+
// lsetxattrCreate wraps unix.Lsetxattr with FreeBSD-specific flags and errors
30+
func lsetxattrCreate(link string, attr string, data []byte) error {
31+
err := unix.Lsetxattr(link, attr, data, 0)
32+
if err == unix.ENOTSUP|| err == unix.EEXIST {
33+
return nil
34+
}
35+
return err
36+
}

archive/tar_mostunix.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// +build !windows,!freebsd
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 archive
20+
21+
import "golang.org/x/sys/unix"
22+
23+
// mknod wraps Unix.Mknod and casts dev to int
24+
func mknod(path string, mode uint32, dev uint64) error {
25+
return unix.Mknod(path, mode, int(dev))
26+
}
27+
28+
// lsetxattrCreate wraps unix.Lsetxattr, passes the unix.XATTR_CREATE flag on
29+
// supported operating systems,and ignores appropriate errors
30+
func lsetxattrCreate(link string, attr string, data []byte) error {
31+
err := unix.Lsetxattr(link, attr, data, unix.XATTR_CREATE)
32+
if err == unix.ENOTSUP || err == unix.ENODATA || err == unix.EEXIST {
33+
return nil
34+
}
35+
return err
36+
}

archive/tar_unix.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func handleTarTypeBlockCharFifo(hdr *tar.Header, path string) error {
108108
mode |= unix.S_IFIFO
109109
}
110110

111-
return unix.Mknod(path, mode, int(unix.Mkdev(uint32(hdr.Devmajor), uint32(hdr.Devminor))))
111+
return mknod(path, mode, unix.Mkdev(uint32(hdr.Devmajor), uint32(hdr.Devminor)))
112112
}
113113

114114
func handleLChmod(hdr *tar.Header, path string, hdrInfo os.FileInfo) error {
@@ -196,10 +196,7 @@ func copyUpXAttrs(dst, src string) error {
196196
}
197197
return errors.Wrapf(err, "failed to get xattr %q on %s", xattr, src)
198198
}
199-
if err := unix.Lsetxattr(dst, xattr, data, unix.XATTR_CREATE); err != nil {
200-
if err == unix.ENOTSUP || err == unix.ENODATA || err == unix.EEXIST {
201-
continue
202-
}
199+
if err := lsetxattrCreate(dst, xattr, data); err != nil {
203200
return errors.Wrapf(err, "failed to set xattr %q on %s", xattr, dst)
204201
}
205202
}

cmd/containerd-shim/shim_freebsd.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import (
2222
"os"
2323
"os/signal"
2424

25-
"github.com/containerd/containerd/runtime/v1/shim"
25+
"github.com/containerd/containerd/sys/reaper"
26+
2627
runc "github.com/containerd/go-runc"
2728
"github.com/containerd/ttrpc"
2829
)
@@ -34,7 +35,7 @@ func setupSignals() (chan os.Signal, error) {
3435
signal.Notify(signals)
3536
// make sure runc is setup to use the monitor
3637
// for waiting on processes
37-
runc.Monitor = shim.Default
38+
runc.Monitor = reaper.Default
3839
return signals, nil
3940
}
4041

0 commit comments

Comments
 (0)