summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEd Tanous <ed@tanous.net>2024-01-31 23:18:03 +0300
committerEd Tanous <ed@tanous.net>2024-04-27 02:45:10 +0300
commit3bfa3b29c0515a9e77c7c69fe072b7ff2e0fc302 (patch)
tree261abe54a0fe45e84659bc5f644077ed68d62a08 /include
parent9f217c26f58c0a99c18e7cac7b095dcf6068562d (diff)
downloadbmcweb-3bfa3b29c0515a9e77c7c69fe072b7ff2e0fc302.tar.xz
Move to process v2
Boost process v2 brings some significant benefits to our launching of processes[1]. In bmcweb terms: 1. The code is radically simpler, which decreaeses compile times, and reduces the scope for code scanning tools. 2. The code now uses standard asio pipes instead of inventing its own. 3. Separate compilation. Tested: We don't have a lot of unit tests for the virtual media stuff that I can run, but we do have unit tests for credentials pipe, which in this change have been ported over, so the feature works. Unit tests are passing. [1] https://www.boost.org/doc/libs/1_80_0/doc/html/boost_process/v2.html#boost_process.v2.introduction Change-Id: Ia20226819d75ff6e492f8852185f0b73e8f5cf83 Signed-off-by: Ed Tanous <ed@tanous.net>
Diffstat (limited to 'include')
-rw-r--r--include/credential_pipe.hpp23
-rw-r--r--include/vm_websocket.hpp24
2 files changed, 30 insertions, 17 deletions
diff --git a/include/credential_pipe.hpp b/include/credential_pipe.hpp
index 169d47c6cb..2cc3dc8b28 100644
--- a/include/credential_pipe.hpp
+++ b/include/credential_pipe.hpp
@@ -1,9 +1,13 @@
#pragma once
+#include "logging.hpp"
+
#include <boost/asio/buffer.hpp>
+#include <boost/asio/connect_pipe.hpp>
#include <boost/asio/io_context.hpp>
+#include <boost/asio/readable_pipe.hpp>
+#include <boost/asio/writable_pipe.hpp>
#include <boost/asio/write.hpp>
-#include <boost/process/async_pipe.hpp>
#include <array>
#include <string>
@@ -12,7 +16,15 @@
class CredentialsPipe
{
public:
- explicit CredentialsPipe(boost::asio::io_context& io) : impl(io) {}
+ explicit CredentialsPipe(boost::asio::io_context& io) : impl(io), read(io)
+ {
+ boost::system::error_code ec;
+ boost::asio::connect_pipe(read, impl, ec);
+ if (ec)
+ {
+ BMCWEB_LOG_CRITICAL("Failed to connect pipe {}", ec.what());
+ }
+ }
CredentialsPipe(const CredentialsPipe&) = delete;
CredentialsPipe(CredentialsPipe&&) = delete;
@@ -25,9 +37,9 @@ class CredentialsPipe
explicit_bzero(pass.data(), pass.capacity());
}
- int fd() const
+ int releaseFd()
{
- return impl.native_source();
+ return read.release();
}
template <typename WriteHandler>
@@ -44,7 +56,8 @@ class CredentialsPipe
std::forward<WriteHandler>(handler));
}
- boost::process::async_pipe impl;
+ boost::asio::writable_pipe impl;
+ boost::asio::readable_pipe read;
private:
std::string user;
diff --git a/include/vm_websocket.hpp b/include/vm_websocket.hpp
index 19054a6d97..3a72b3adb5 100644
--- a/include/vm_websocket.hpp
+++ b/include/vm_websocket.hpp
@@ -3,10 +3,11 @@
#include "app.hpp"
#include "websocket.hpp"
+#include <boost/asio/readable_pipe.hpp>
+#include <boost/asio/writable_pipe.hpp>
#include <boost/beast/core/flat_static_buffer.hpp>
-#include <boost/process/async_pipe.hpp>
-#include <boost/process/child.hpp>
-#include <boost/process/io.hpp>
+#include <boost/process/v2/process.hpp>
+#include <boost/process/v2/stdio.hpp>
#include <csignal>
@@ -26,8 +27,11 @@ static constexpr auto nbdBufferSize = (128 * 1024 + 16) * 4;
class Handler : public std::enable_shared_from_this<Handler>
{
public:
- Handler(const std::string& mediaIn, boost::asio::io_context& ios) :
- pipeOut(ios), pipeIn(ios), media(mediaIn),
+ Handler(const std::string& media, boost::asio::io_context& ios) :
+ pipeOut(ios), pipeIn(ios),
+ proxy(ios, "/usr/bin/nbd-proxy", {media},
+ boost::process::v2::process_stdio{
+ .in = pipeIn, .out = pipeOut, .err = nullptr}),
outputBuffer(new boost::beast::flat_static_buffer<nbdBufferSize>),
inputBuffer(new boost::beast::flat_static_buffer<nbdBufferSize>)
{}
@@ -56,9 +60,6 @@ class Handler : public std::enable_shared_from_this<Handler>
void connect()
{
std::error_code ec;
- proxy = boost::process::child("/usr/bin/nbd-proxy", media,
- boost::process::std_out > pipeOut,
- boost::process::std_in < pipeIn, ec);
if (ec)
{
BMCWEB_LOG_ERROR("Couldn't connect to nbd-proxy: {}", ec.message());
@@ -148,10 +149,9 @@ class Handler : public std::enable_shared_from_this<Handler>
});
}
- boost::process::async_pipe pipeOut;
- boost::process::async_pipe pipeIn;
- boost::process::child proxy;
- std::string media;
+ boost::asio::readable_pipe pipeOut;
+ boost::asio::writable_pipe pipeIn;
+ boost::process::v2::process proxy;
bool doingWrite{false};
std::unique_ptr<boost::beast::flat_static_buffer<nbdBufferSize>>