1*939fec44SIgor Ostapenko // Copyright 2025 The Kyua Authors.
2*939fec44SIgor Ostapenko // All rights reserved.
3*939fec44SIgor Ostapenko //
4*939fec44SIgor Ostapenko // Redistribution and use in source and binary forms, with or without
5*939fec44SIgor Ostapenko // modification, are permitted provided that the following conditions are
6*939fec44SIgor Ostapenko // met:
7*939fec44SIgor Ostapenko //
8*939fec44SIgor Ostapenko // * Redistributions of source code must retain the above copyright
9*939fec44SIgor Ostapenko // notice, this list of conditions and the following disclaimer.
10*939fec44SIgor Ostapenko // * Redistributions in binary form must reproduce the above copyright
11*939fec44SIgor Ostapenko // notice, this list of conditions and the following disclaimer in the
12*939fec44SIgor Ostapenko // documentation and/or other materials provided with the distribution.
13*939fec44SIgor Ostapenko // * Neither the name of Google Inc. nor the names of its contributors
14*939fec44SIgor Ostapenko // may be used to endorse or promote products derived from this software
15*939fec44SIgor Ostapenko // without specific prior written permission.
16*939fec44SIgor Ostapenko //
17*939fec44SIgor Ostapenko // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18*939fec44SIgor Ostapenko // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19*939fec44SIgor Ostapenko // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20*939fec44SIgor Ostapenko // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21*939fec44SIgor Ostapenko // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22*939fec44SIgor Ostapenko // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23*939fec44SIgor Ostapenko // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24*939fec44SIgor Ostapenko // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25*939fec44SIgor Ostapenko // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26*939fec44SIgor Ostapenko // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27*939fec44SIgor Ostapenko // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*939fec44SIgor Ostapenko
29*939fec44SIgor Ostapenko #include "os/freebsd/reqs_checker_kmods.hpp"
30*939fec44SIgor Ostapenko
31*939fec44SIgor Ostapenko #include "model/metadata.hpp"
32*939fec44SIgor Ostapenko
33*939fec44SIgor Ostapenko extern "C" {
34*939fec44SIgor Ostapenko #include "libutil.h"
35*939fec44SIgor Ostapenko }
36*939fec44SIgor Ostapenko
37*939fec44SIgor Ostapenko std::string
exec(const model::metadata & md,const utils::config::tree &,const std::string &,const utils::fs::path &) const38*939fec44SIgor Ostapenko freebsd::reqs_checker_kmods::exec(const model::metadata& md,
39*939fec44SIgor Ostapenko const utils::config::tree&,
40*939fec44SIgor Ostapenko const std::string&,
41*939fec44SIgor Ostapenko const utils::fs::path&) const
42*939fec44SIgor Ostapenko {
43*939fec44SIgor Ostapenko std::string reason = "";
44*939fec44SIgor Ostapenko for (auto& kmod : md.required_kmods())
45*939fec44SIgor Ostapenko if (!::kld_isloaded((kmod).c_str()))
46*939fec44SIgor Ostapenko reason += " " + kmod;
47*939fec44SIgor Ostapenko if (!reason.empty())
48*939fec44SIgor Ostapenko reason = "Required kmods are not loaded:" + reason + ".";
49*939fec44SIgor Ostapenko return reason;
50*939fec44SIgor Ostapenko }
51