1*257e70f1SIgor Ostapenko // Copyright 2024 The Kyua Authors.
2*257e70f1SIgor Ostapenko // All rights reserved.
3*257e70f1SIgor Ostapenko //
4*257e70f1SIgor Ostapenko // Redistribution and use in source and binary forms, with or without
5*257e70f1SIgor Ostapenko // modification, are permitted provided that the following conditions are
6*257e70f1SIgor Ostapenko // met:
7*257e70f1SIgor Ostapenko //
8*257e70f1SIgor Ostapenko // * Redistributions of source code must retain the above copyright
9*257e70f1SIgor Ostapenko // notice, this list of conditions and the following disclaimer.
10*257e70f1SIgor Ostapenko // * Redistributions in binary form must reproduce the above copyright
11*257e70f1SIgor Ostapenko // notice, this list of conditions and the following disclaimer in the
12*257e70f1SIgor Ostapenko // documentation and/or other materials provided with the distribution.
13*257e70f1SIgor Ostapenko // * Neither the name of Google Inc. nor the names of its contributors
14*257e70f1SIgor Ostapenko // may be used to endorse or promote products derived from this software
15*257e70f1SIgor Ostapenko // without specific prior written permission.
16*257e70f1SIgor Ostapenko //
17*257e70f1SIgor Ostapenko // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18*257e70f1SIgor Ostapenko // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19*257e70f1SIgor Ostapenko // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20*257e70f1SIgor Ostapenko // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21*257e70f1SIgor Ostapenko // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22*257e70f1SIgor Ostapenko // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23*257e70f1SIgor Ostapenko // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24*257e70f1SIgor Ostapenko // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25*257e70f1SIgor Ostapenko // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26*257e70f1SIgor Ostapenko // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27*257e70f1SIgor Ostapenko // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*257e70f1SIgor Ostapenko
29*257e70f1SIgor Ostapenko #include "os/freebsd/execenv_jail.hpp"
30*257e70f1SIgor Ostapenko
31*257e70f1SIgor Ostapenko #include <iostream>
32*257e70f1SIgor Ostapenko
33*257e70f1SIgor Ostapenko #include "utils/process/operations_fwd.hpp"
34*257e70f1SIgor Ostapenko
35*257e70f1SIgor Ostapenko using utils::process::args_vector;
36*257e70f1SIgor Ostapenko
37*257e70f1SIgor Ostapenko
38*257e70f1SIgor Ostapenko static inline void requires_freebsd(void) UTILS_NORETURN;
39*257e70f1SIgor Ostapenko
40*257e70f1SIgor Ostapenko static inline void
requires_freebsd(void)41*257e70f1SIgor Ostapenko requires_freebsd(void)
42*257e70f1SIgor Ostapenko {
43*257e70f1SIgor Ostapenko std::cerr << "execenv=\"jail\" requires FreeBSD with jail feature.\n";
44*257e70f1SIgor Ostapenko std::exit(EXIT_FAILURE);
45*257e70f1SIgor Ostapenko }
46*257e70f1SIgor Ostapenko
47*257e70f1SIgor Ostapenko
48*257e70f1SIgor Ostapenko namespace freebsd {
49*257e70f1SIgor Ostapenko
50*257e70f1SIgor Ostapenko
51*257e70f1SIgor Ostapenko bool execenv_jail_supported = false;
52*257e70f1SIgor Ostapenko
53*257e70f1SIgor Ostapenko
54*257e70f1SIgor Ostapenko void
init() const55*257e70f1SIgor Ostapenko execenv_jail::init() const
56*257e70f1SIgor Ostapenko {
57*257e70f1SIgor Ostapenko requires_freebsd();
58*257e70f1SIgor Ostapenko }
59*257e70f1SIgor Ostapenko
60*257e70f1SIgor Ostapenko
61*257e70f1SIgor Ostapenko void
cleanup() const62*257e70f1SIgor Ostapenko execenv_jail::cleanup() const
63*257e70f1SIgor Ostapenko {
64*257e70f1SIgor Ostapenko requires_freebsd();
65*257e70f1SIgor Ostapenko }
66*257e70f1SIgor Ostapenko
67*257e70f1SIgor Ostapenko
68*257e70f1SIgor Ostapenko void
exec(const args_vector &) const69*257e70f1SIgor Ostapenko execenv_jail::exec(const args_vector&) const
70*257e70f1SIgor Ostapenko {
71*257e70f1SIgor Ostapenko requires_freebsd();
72*257e70f1SIgor Ostapenko }
73*257e70f1SIgor Ostapenko
74*257e70f1SIgor Ostapenko
75*257e70f1SIgor Ostapenko } // namespace freebsd
76