Skip to content

Commit

Permalink
Fix build on FreeBSD
Browse files Browse the repository at this point in the history
Ref opencontainers#330

Signed-off-by: Mateusz Kwiatkowski <[email protected]>
  • Loading branch information
mateuszkwiatkowski committed Feb 4, 2021
1 parent f8bb975 commit a5afd68
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 19 deletions.
18 changes: 13 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
# limitations under the License.

# Use bash, so that we can do process substitution.
SHELL = /bin/bash
SHELL := $(shell which bash)

# Go tools.
GO ?= go
GO_MD2MAN ?= go-md2man
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
export GO111MODULE=on

# Set up the ... lovely ... GOPATH hacks.
Expand Down Expand Up @@ -68,13 +70,19 @@ BASE_FLAGS := ${BUILD_FLAGS} -tags "${BUILDTAGS}"
BASE_LDFLAGS := -s -w -X ${PROJECT}.gitCommit=${COMMIT} -X ${PROJECT}.version=${VERSION}

# Specific build flags for build type.
DYN_BUILD_FLAGS := ${BASE_FLAGS} -buildmode=pie -ldflags "${BASE_LDFLAGS}"
TEST_BUILD_FLAGS := ${BASE_FLAGS} -buildmode=pie -ldflags "${BASE_LDFLAGS} -X ${PROJECT}/pkg/testutils.binaryType=test"
ifeq ($(GOOS), linux)
DYN_BUILD_FLAGS := ${BASE_FLAGS} -buildmode=pie -ldflags "${BASE_LDFLAGS}"
TEST_BUILD_FLAGS := ${BASE_FLAGS} -buildmode=pie -ldflags "${BASE_LDFLAGS} -X ${PROJECT}/pkg/testutils.binaryType=test"
else
DYN_BUILD_FLAGS := ${BASE_FLAGS} -ldflags "${BASE_LDFLAGS}"
TEST_BUILD_FLAGS := ${BASE_FLAGS} -ldflags "${BASE_LDFLAGS} -X ${PROJECT}/pkg/testutils.binaryType=test"
endif

STATIC_BUILD_FLAGS := ${BASE_FLAGS} -ldflags "${BASE_LDFLAGS} -extldflags '-static'"

# Installation directories.
DESTDIR ?=
PREFIX ?=/usr
PREFIX ?=/usr/local
BINDIR ?=$(PREFIX)/bin
MANDIR ?=$(PREFIX)/share/man

Expand All @@ -85,7 +93,7 @@ GO_SRC = $(shell find . -type f -name '*.go')
# NOTE: If you change these make sure you also update local-validate-build.

umoci: $(GO_SRC)
$(GO) build ${DYN_BUILD_FLAGS} -o $(BUILD_DIR)/$@ ${CMD}
GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO) build ${DYN_BUILD_FLAGS} -o $(BUILD_DIR)/$@ ${CMD}

umoci.static: $(GO_SRC)
env CGO_ENABLED=0 $(GO) build ${STATIC_BUILD_FLAGS} -o $(BUILD_DIR)/$@ ${CMD}
Expand Down
5 changes: 0 additions & 5 deletions pkg/fseval/fseval_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@ func (fs osFsEval) RemoveAll(path string) error {
return os.RemoveAll(path)
}

// Mknod is equivalent to unix.Mknod.
func (fs osFsEval) Mknod(path string, mode os.FileMode, dev uint64) error {
return unix.Mknod(path, uint32(mode), int(dev))
}

// MkdirAll is equivalent to os.MkdirAll.
func (fs osFsEval) MkdirAll(path string, perm os.FileMode) error {
return os.MkdirAll(path, perm)
Expand Down
28 changes: 28 additions & 0 deletions pkg/fseval/mknod_freebsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* umoci: Umoci Modifies Open Containers' Images
* Copyright (C) 2016-2020 SUSE LLC
*
* 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 fseval

import (
"os"

"golang.org/x/sys/unix"
)

func (fs osFsEval) Mknod(path string, mode os.FileMode, dev uint64) error {
return unix.Mknod(path, uint32(mode), uint64(dev))
}
28 changes: 28 additions & 0 deletions pkg/fseval/mknod_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* umoci: Umoci Modifies Open Containers' Images
* Copyright (C) 2016-2020 SUSE LLC
*
* 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 fseval

import (
"os"

"golang.org/x/sys/unix"
)

func (fs osFsEval) Mknod(path string, mode os.FileMode, dev uint64) error {
return unix.Mknod(path, uint32(mode), int(dev))
}
34 changes: 34 additions & 0 deletions pkg/unpriv/mknod_freebsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* umoci: Umoci Modifies Open Containers' Images
* Copyright (C) 2016-2020 SUSE LLC
*
* 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 unpriv

import (
"os"

"github.com/pkg/errors"
"golang.org/x/sys/unix"
)

// Mknod is a wrapper around unix.Mknod which has been wrapped with unpriv.Wrap
// to make it possible to remove a path even if you do not currently have the
// required access bits to modify or resolve the path.
func Mknod(path string, mode os.FileMode, dev uint64) error {
return errors.Wrap(Wrap(path, func(path string) error {
return unix.Mknod(path, uint32(mode), uint64(dev))
}), "unpriv.mknod")
}
34 changes: 34 additions & 0 deletions pkg/unpriv/mknod_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* umoci: Umoci Modifies Open Containers' Images
* Copyright (C) 2016-2020 SUSE LLC
*
* 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 unpriv

import (
"os"

"github.com/pkg/errors"
"golang.org/x/sys/unix"
)

// Mknod is a wrapper around unix.Mknod which has been wrapped with unpriv.Wrap
// to make it possible to remove a path even if you do not currently have the
// required access bits to modify or resolve the path.
func Mknod(path string, mode os.FileMode, dev uint64) error {
return errors.Wrap(Wrap(path, func(path string) error {
return unix.Mknod(path, uint32(mode), int(dev))
}), "unpriv.mknod")
}
9 changes: 0 additions & 9 deletions pkg/unpriv/unpriv.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,15 +446,6 @@ func MkdirAll(path string, perm os.FileMode) error {
}), "unpriv.mkdirall")
}

// Mknod is a wrapper around unix.Mknod which has been wrapped with unpriv.Wrap
// to make it possible to remove a path even if you do not currently have the
// required access bits to modify or resolve the path.
func Mknod(path string, mode os.FileMode, dev uint64) error {
return errors.Wrap(Wrap(path, func(path string) error {
return unix.Mknod(path, uint32(mode), int(dev))
}), "unpriv.mknod")
}

// Llistxattr is a wrapper around system.Llistxattr which has been wrapped with
// unpriv.Wrap to make it possible to remove a path even if you do not
// currently have the required access bits to resolve the path.
Expand Down

0 comments on commit a5afd68

Please sign in to comment.