util.cpp (9b2a20d3cfa1131521456b9ebfde7a7bb8b234bb) util.cpp (8664252af8cac7f5c3e9ce693e546e0a6d1af39a)
1#include "config.h"
2
3#include "util.hpp"
4
5#include "config_parser.hpp"
6#include "types.hpp"
7
1#include "config.h"
2
3#include "util.hpp"
4
5#include "config_parser.hpp"
6#include "types.hpp"
7
8#include <fmt/compile.h>
9#include <fmt/format.h>
10#include <sys/wait.h>
11
12#include <phosphor-logging/elog-errors.hpp>
13#include <phosphor-logging/lg2.hpp>
14#include <stdplus/numeric/str.hpp>
8#include <sys/wait.h>
9
10#include <phosphor-logging/elog-errors.hpp>
11#include <phosphor-logging/lg2.hpp>
12#include <stdplus/numeric/str.hpp>
13#include <stdplus/str/buf.hpp>
14#include <stdplus/str/cat.hpp>
15#include <xyz/openbmc_project/Common/error.hpp>
16
17#include <cctype>
18#include <string>
19#include <string_view>
20
21namespace phosphor
22{
23namespace network
24{
25
26using std::literals::string_view_literals::operator""sv;
27using namespace phosphor::logging;
28using namespace sdbusplus::xyz::openbmc_project::Common::Error;
29
30namespace internal
31{
32
15#include <xyz/openbmc_project/Common/error.hpp>
16
17#include <cctype>
18#include <string>
19#include <string_view>
20
21namespace phosphor
22{
23namespace network
24{
25
26using std::literals::string_view_literals::operator""sv;
27using namespace phosphor::logging;
28using namespace sdbusplus::xyz::openbmc_project::Common::Error;
29
30namespace internal
31{
32
33void executeCommandinChildProcess(stdplus::const_zstring path, char** args)
33void executeCommandinChildProcess(stdplus::zstring_view path, char** args)
34{
35 using namespace std::string_literals;
36 pid_t pid = fork();
37
38 if (pid == 0)
39 {
40 execv(path.c_str(), args);
41 exit(255);

--- 13 unchanged lines hidden (view full) ---

55 {
56 status = -1;
57 break;
58 }
59 }
60
61 if (status < 0)
62 {
34{
35 using namespace std::string_literals;
36 pid_t pid = fork();
37
38 if (pid == 0)
39 {
40 execv(path.c_str(), args);
41 exit(255);

--- 13 unchanged lines hidden (view full) ---

55 {
56 status = -1;
57 break;
58 }
59 }
60
61 if (status < 0)
62 {
63 fmt::memory_buffer buf;
64 fmt::format_to(fmt::appender(buf), "`{}`", path);
63 stdplus::StrBuf buf;
64 stdplus::strAppend(buf, "`"sv, path, "`"sv);
65 for (size_t i = 0; args[i] != nullptr; ++i)
66 {
65 for (size_t i = 0; args[i] != nullptr; ++i)
66 {
67 fmt::format_to(fmt::appender(buf), " `{}`", args[i]);
67 stdplus::strAppend(buf, " `"sv, args[i], "`"sv);
68 }
69 buf.push_back('\0');
70 lg2::error("Unable to execute the command {CMD}: {STATUS}", "CMD",
71 buf.data(), "STATUS", status);
72 elog<InternalFailure>();
73 }
74 }
75}

--- 64 unchanged lines hidden (view full) ---

140 catch (...)
141 {
142 return std::nullopt;
143 }
144 if (idx == 0)
145 {
146 return "ethaddr";
147 }
68 }
69 buf.push_back('\0');
70 lg2::error("Unable to execute the command {CMD}: {STATUS}", "CMD",
71 buf.data(), "STATUS", status);
72 elog<InternalFailure>();
73 }
74 }
75}

--- 64 unchanged lines hidden (view full) ---

140 catch (...)
141 {
142 return std::nullopt;
143 }
144 if (idx == 0)
145 {
146 return "ethaddr";
147 }
148 return fmt::format(FMT_COMPILE("eth{}addr"), idx);
148 stdplus::ToStrHandle<stdplus::IntToStr<10, unsigned>> tsh;
149 return stdplus::strCat("eth"sv, tsh(idx), "addr"sv);
149}
150
151static std::optional<DHCPVal> systemdParseDHCP(std::string_view str)
152{
153 if (config::icaseeq(str, "ipv4"))
154 {
155 return DHCPVal{.v4 = true, .v6 = false};
156 }

--- 65 unchanged lines hidden ---
150}
151
152static std::optional<DHCPVal> systemdParseDHCP(std::string_view str)
153{
154 if (config::icaseeq(str, "ipv4"))
155 {
156 return DHCPVal{.v4 = true, .v6 = false};
157 }

--- 65 unchanged lines hidden ---