From 8be05eb237a026d797deba448eef3cf54b8fce7e Mon Sep 17 00:00:00 2001 From: Justin Cormack Date: Sun, 16 Dec 2018 14:27:42 +0000 Subject: [PATCH] Fix freebsd build This brings freebsd in line with Darwin, ie it builds, but some parts may not yet be fully functional. There is now a WIP `runc` port for FreeBSD at https://github.com/clovertrail/runc/tree/1501-SupportOnFreeBSD so should be able to test further. Signed-off-by: Justin Cormack --- .../{shim_unix.go => shim_freebsd.go} | 7 +++- cmd/containerd-stress/rlimit_freebsd.go | 40 +++++++++++++++++++ cmd/containerd-stress/rlimit_unix.go | 2 +- runtime/v2/shim/shim_freebsd.go | 29 ++++++++++++++ 4 files changed, 75 insertions(+), 3 deletions(-) rename cmd/containerd-shim/{shim_unix.go => shim_freebsd.go} (82%) create mode 100644 cmd/containerd-stress/rlimit_freebsd.go create mode 100644 runtime/v2/shim/shim_freebsd.go diff --git a/cmd/containerd-shim/shim_unix.go b/cmd/containerd-shim/shim_freebsd.go similarity index 82% rename from cmd/containerd-shim/shim_unix.go rename to cmd/containerd-shim/shim_freebsd.go index 88cd5387c..92988aa26 100644 --- a/cmd/containerd-shim/shim_unix.go +++ b/cmd/containerd-shim/shim_freebsd.go @@ -1,4 +1,4 @@ -// +build !linux,!windows,!darwin +// +build freebsd /* Copyright The containerd Authors. @@ -39,5 +39,8 @@ func setupSignals() (chan os.Signal, error) { } func newServer() (*ttrpc.Server, error) { - return ttrpc.NewServer(ttrpc.WithServerHandshaker(ttrpc.UnixSocketRequireSameUser())) + // for freebsd, we omit the socket credentials because these syscalls are + // slightly different. since we don't have freebsd support yet, this can be + // implemented later and the build can continue without issue. + return ttrpc.NewServer() } diff --git a/cmd/containerd-stress/rlimit_freebsd.go b/cmd/containerd-stress/rlimit_freebsd.go new file mode 100644 index 000000000..a1b39defc --- /dev/null +++ b/cmd/containerd-stress/rlimit_freebsd.go @@ -0,0 +1,40 @@ +// +build freebsd + +/* + 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 main + +import ( + "syscall" +) + +func setRlimit() error { + rlimit := int64(100000) + if rlimit > 0 { + var limit syscall.Rlimit + if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + return err + } + if limit.Cur < rlimit { + limit.Cur = rlimit + if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + return err + } + } + } + return nil +} diff --git a/cmd/containerd-stress/rlimit_unix.go b/cmd/containerd-stress/rlimit_unix.go index bca9df65a..807a9a92f 100644 --- a/cmd/containerd-stress/rlimit_unix.go +++ b/cmd/containerd-stress/rlimit_unix.go @@ -1,4 +1,4 @@ -// +build !windows +// +build !windows,!freebsd /* Copyright The containerd Authors. diff --git a/runtime/v2/shim/shim_freebsd.go b/runtime/v2/shim/shim_freebsd.go new file mode 100644 index 000000000..4bc636280 --- /dev/null +++ b/runtime/v2/shim/shim_freebsd.go @@ -0,0 +1,29 @@ +// +build freebsd + +/* + 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 shim + +import "github.com/containerd/ttrpc" + +func newServer() (*ttrpc.Server, error) { + return ttrpc.NewServer() +} + +func subreaper() error { + return nil +}