Skip to content

Commit

Permalink
Separate FreeBSD related code beneath freebsd/
Browse files Browse the repository at this point in the history
  • Loading branch information
ihoro committed Feb 25, 2024
1 parent b231b13 commit f633b9c
Show file tree
Hide file tree
Showing 15 changed files with 250 additions and 18 deletions.
1 change: 1 addition & 0 deletions contrib/kyua/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ include doc/Makefile.am.inc
include drivers/Makefile.am.inc
include engine/Makefile.am.inc
include examples/Makefile.am.inc
include freebsd/Makefile.am.inc
include integration/Makefile.am.inc
include misc/Makefile.am.inc
include model/Makefile.am.inc
Expand Down
1 change: 1 addition & 0 deletions contrib/kyua/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,6 @@ fi
AM_CONDITIONAL(TARGET_SRCDIR_EMPTY, [test -z "${target_srcdir}"])
AC_SUBST([target_srcdir])

AM_CONDITIONAL([FreeBSD], [test "$(uname -o)" = "FreeBSD"])

AC_OUTPUT
6 changes: 4 additions & 2 deletions contrib/kyua/engine/execenv/Makefile.am.inc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# TODO: Think of OOP based refactoring to invert the dependency. FreeBSD
# related code should be like a plugin or extension.
ENGINE_LIBS += ${FREEBSD_LIBS}

libengine_a_SOURCES += engine/execenv/execenv.hpp
libengine_a_SOURCES += engine/execenv/execenv.cpp
libengine_a_SOURCES += engine/execenv/jail.hpp
libengine_a_SOURCES += engine/execenv/jail.cpp
3 changes: 2 additions & 1 deletion contrib/kyua/engine/execenv/execenv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@

#include "engine/execenv/execenv.hpp"

#include "engine/execenv/jail.hpp"
#include "model/metadata.hpp"
#include "model/test_case.hpp"
#include "model/test_program.hpp"
#include "utils/fs/path.hpp"
#include "utils/process/operations.hpp"

#include "freebsd/engine/execenv/jail.hpp"

namespace execenv = engine::execenv;
namespace process = utils::process;

Expand Down
37 changes: 37 additions & 0 deletions contrib/kyua/freebsd/Makefile.am.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2024 The Kyua Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of Google Inc. nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

FREEBSD_CFLAGS =
FREEBSD_LIBS = libfreebsd.a

noinst_LIBRARIES += libfreebsd.a
libfreebsd_a_CPPFLAGS = -DGDB=\"$(GDB)\"
libfreebsd_a_SOURCES =

include freebsd/engine/Makefile.am.inc
include freebsd/utils/Makefile.am.inc
29 changes: 29 additions & 0 deletions contrib/kyua/freebsd/engine/Makefile.am.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2024 The Kyua Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of Google Inc. nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

include freebsd/engine/execenv/Makefile.am.inc
34 changes: 34 additions & 0 deletions contrib/kyua/freebsd/engine/execenv/Makefile.am.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2024 The Kyua Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of Google Inc. nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

libfreebsd_a_SOURCES += freebsd/engine/execenv/jail.hpp
if FreeBSD
libfreebsd_a_SOURCES += freebsd/engine/execenv/jail.cpp
else
libfreebsd_a_SOURCES += freebsd/engine/execenv/jail_stub.cpp
endif
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "engine/execenv/jail.hpp"
#include "freebsd/engine/execenv/jail.hpp"

extern "C" {
// FreeBSD Jail
Expand All @@ -38,9 +38,10 @@ extern "C" {
#include "model/test_case.hpp"
#include "model/test_program.hpp"
#include "utils/fs/path.hpp"
#include "utils/process/jail.hpp"
#include "utils/process/operations.hpp"

#include "freebsd/utils/process/jail.hpp"

namespace execenv = engine::execenv;
namespace process = utils::process;
namespace fs = utils::fs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

/// \file engine/execenv/jail.hpp
/// \file freebsd/engine/execenv/jail.hpp
/// FreeBSD jail execution environment.

#if !defined(ENGINE_EXECENV_JAIL_HPP)
#define ENGINE_EXECENV_JAIL_HPP
#if !defined(FREEBSD_ENGINE_EXECENV_JAIL_HPP)
#define FREEBSD_ENGINE_EXECENV_JAIL_HPP

#include "model/test_program.hpp"
#include "utils/defs.hpp"
Expand All @@ -52,4 +52,4 @@ void cleanup(const model::test_program&, const std::string&);
} // namespace execenv
} // namespace engine

#endif // !defined(ENGINE_EXECENV_JAIL_HPP)
#endif // !defined(FREEBSD_ENGINE_EXECENV_JAIL_HPP)
68 changes: 68 additions & 0 deletions contrib/kyua/freebsd/engine/execenv/jail_stub.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) 2024 Igor Ostapenko <pm@igoro.pro>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of Google Inc. nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "freebsd/engine/execenv/jail.hpp"

#include <iostream>

#include "utils/process/operations_fwd.hpp"

namespace execenv = engine::execenv;

using utils::process::args_vector;


static inline void requires_freebsd(void) UTILS_NORETURN;

static inline void
requires_freebsd(void)
{
std::cerr << "execenv=\"jail\" is a FreeBSD-only feature.\n";
std::exit(EXIT_FAILURE);
}

void
execenv::jail::init(const model::test_program&,
const std::string&)
{
requires_freebsd();
}

void
execenv::jail::exec(const model::test_program&,
const std::string&,
const args_vector&) throw()
{
requires_freebsd();
}

void
execenv::jail::cleanup(const model::test_program&,
const std::string&)
{
requires_freebsd();
}
29 changes: 29 additions & 0 deletions contrib/kyua/freebsd/utils/Makefile.am.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2024 The Kyua Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of Google Inc. nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

include freebsd/utils/process/Makefile.am.inc
33 changes: 33 additions & 0 deletions contrib/kyua/freebsd/utils/process/Makefile.am.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2024 The Kyua Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of Google Inc. nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

if FreeBSD
FREEBSD_LIBS += -ljail
libfreebsd_a_SOURCES += freebsd/utils/process/jail.hpp
libfreebsd_a_SOURCES += freebsd/utils/process/jail.cpp
endif
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "utils/process/jail.hpp"
#include "freebsd/utils/process/jail.hpp"

extern "C" {
#include <limits.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

/// \file utils/process/jail.hpp
/// \file freebsd/utils/process/jail.hpp
/// Collection of utilities for FreeBSD jail.

#if !defined(UTILS_PROCESS_JAIL_HPP)
#define UTILS_PROCESS_JAIL_HPP
#if !defined(FREEBSD_UTILS_PROCESS_JAIL_HPP)
#define FREEBSD_UTILS_PROCESS_JAIL_HPP

#include "utils/defs.hpp"
#include "utils/fs/path_fwd.hpp"
Expand All @@ -52,4 +52,4 @@ void remove(const std::string&);
} // namespace process
} // namespace utils

#endif // !defined(UTILS_PROCESS_JAIL_HPP)
#endif // !defined(FREEBSD_UTILS_PROCESS_JAIL_HPP)
4 changes: 0 additions & 4 deletions contrib/kyua/utils/process/Makefile.am.inc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

UTILS_LIBS += -ljail

libutils_a_SOURCES += utils/process/child.cpp
libutils_a_SOURCES += utils/process/child.hpp
libutils_a_SOURCES += utils/process/child.ipp
Expand All @@ -46,8 +44,6 @@ libutils_a_SOURCES += utils/process/fdstream.hpp
libutils_a_SOURCES += utils/process/fdstream_fwd.hpp
libutils_a_SOURCES += utils/process/isolation.cpp
libutils_a_SOURCES += utils/process/isolation.hpp
libutils_a_SOURCES += utils/process/jail.hpp
libutils_a_SOURCES += utils/process/jail.cpp
libutils_a_SOURCES += utils/process/operations.cpp
libutils_a_SOURCES += utils/process/operations.hpp
libutils_a_SOURCES += utils/process/operations_fwd.hpp
Expand Down

0 comments on commit f633b9c

Please sign in to comment.