From d12b9fecc485e947c0fa9a70f0f46d1e6d8cdc5a Mon Sep 17 00:00:00 2001 From: clfreville2 Date: Mon, 16 Oct 2023 14:04:31 +0200 Subject: [PATCH 1/6] Prepare ZeroMQ --- CMakeLists.txt | 13 +++++++++++-- src/main.cpp | 49 +++++++++++++++++++++++++++++++++++++------------ 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a99602d..899a1d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,14 @@ project(planificador) add_compile_options(-Wall -Wextra -pedantic) include(FetchContent) + +FetchContent_Declare( + cppzmq + GIT_REPOSITORY https://github.com/zeromq/cppzmq.git + GIT_TAG v4.10.0 +) +FetchContent_MakeAvailable(cppzmq) + FetchContent_Declare( tomlplusplus GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git @@ -12,8 +20,9 @@ FetchContent_Declare( ) FetchContent_MakeAvailable(tomlplusplus) -file(GLOB nameFile "src/*.cpp") -add_executable(planificador src/host.cpp src/runner.cpp src/config.cpp src/main.cpp ) +add_executable(planificador src/host.cpp src/runner.cpp src/config.cpp src/main.cpp) target_compile_features(planificador PUBLIC cxx_std_17) include_directories(${tomlplusplus_SOURCE_DIR}/include) +include_directories(${cppzmq_SOURCE_DIR}) +target_link_libraries(planificador PRIVATE zmq) diff --git a/src/main.cpp b/src/main.cpp index 7672bb8..9737048 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,8 +11,7 @@ #include #include "host.hpp" - -namespace fs = std::filesystem; +#include "zmq_addon.hpp" sk::runner_backend detect_backend() { const char *const argv[] = {"docker", "stats", "--no-stream", nullptr}; @@ -32,23 +31,49 @@ sk::runner_backend detect_backend() { } int main() { - std::vector listsHosts = sk::config::loadHostsFromToml("../conf.toml"); + std::vector listsHosts = + sk::config::loadHostsFromToml("../conf.toml"); std::priority_queue hosts(listsHosts.begin(), listsHosts.end()); + std::queue programQueue; + if (hosts.empty()) { std::cerr << "Pas de host" << std::endl; + exit(1); } - std::queue queue; - queue.push(sk::program{"echo $(( 1 + 2 ))", "ghcr.io/moshell-lang/moshell:master"}); - sk::runner runner(detect_backend()); - while (!queue.empty()) { - const sk::program ¤t = queue.front(); - sk::run_result res = runner.run_blocking(current); - std::cout << "out: " << res.out << "\n"; - std::cout << "err: " << res.err << "\n"; - queue.pop(); + + zmq::context_t context(1); + zmq::socket_t receiver(context, zmq::socket_type::pull); + receiver.connect("tcp://localhost:5557"); + zmq::socket_t sender(context, zmq::socket_type::push); + sender.connect("tcp://localhost:5558"); + + while (true) { + zmq::message_t request; + receiver.recv(request); + if (request.size() < 32) { + std::cerr << "Invalid request" << std::endl; + break; + } + std::string_view jobId(static_cast(request.data()), 32); + std::string requestString(static_cast(request.data()) + 32, + request.size() - 32); + + std::cout << "Executing " << request.size() << " bytes code.\n"; + sk::program program{requestString, + "ghcr.io/moshell-lang/moshell:master"}; + sk::run_result result = runner.run_blocking(program); + + std::cout << "Result: " << result.out << std::endl; + + // Send the job id and result.out to sink + zmq::message_t reply(32 + result.out.size()); + memcpy(reply.data(), jobId.data(), 32); + memcpy(static_cast(reply.data()) + 32, result.out.data(), + result.out.size()); + sender.send(reply, zmq::send_flags::none); } return 0; } From 2d75822ed9a9f742fb7b202bd83bcda4f0c87f34 Mon Sep 17 00:00:00 2001 From: clfreville2 Date: Mon, 16 Oct 2023 14:55:07 +0200 Subject: [PATCH 2/6] Use system distribution of cppzmq --- CMakeLists.txt | 7 ------- 1 file changed, 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 899a1d3..76873a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,13 +6,6 @@ add_compile_options(-Wall -Wextra -pedantic) include(FetchContent) -FetchContent_Declare( - cppzmq - GIT_REPOSITORY https://github.com/zeromq/cppzmq.git - GIT_TAG v4.10.0 -) -FetchContent_MakeAvailable(cppzmq) - FetchContent_Declare( tomlplusplus GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git From 3bc8f547f644cf1b0dd268ec0624f1810092b9c4 Mon Sep 17 00:00:00 2001 From: clfreville2 Date: Mon, 16 Oct 2023 20:41:11 +0200 Subject: [PATCH 3/6] Allow fetching locally ZeroMQ if not already installed --- .drone.yml | 4 ++-- .gitignore | 4 ++++ CMakeLists.txt | 36 +++++++++++++++++++++++++----- libzmq-pkg-config/FindZeroMQ.cmake | 28 +++++++++++++++++++++++ 4 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 libzmq-pkg-config/FindZeroMQ.cmake diff --git a/.drone.yml b/.drone.yml index 3e29fca..ce1a964 100644 --- a/.drone.yml +++ b/.drone.yml @@ -6,5 +6,5 @@ steps: - name: build image: hub.codefirst.iut.uca.fr/clement.freville2/planificador-build-image:latest commands: - - mkdir build && cd build && cmake .. - - make + - cmake -B build -S . + - cmake --build build --parallel $(nproc) diff --git a/.gitignore b/.gitignore index 3b1c59a..6a848fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ bin build obj + +.idea +.vscode +cmake-build-debug diff --git a/CMakeLists.txt b/CMakeLists.txt index 76873a8..3e4c718 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,19 +1,45 @@ cmake_minimum_required(VERSION 3.10) +set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) project(planificador) -add_compile_options(-Wall -Wextra -pedantic) - include(FetchContent) FetchContent_Declare( - tomlplusplus - GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git - GIT_TAG v3.3.0 + tomlplusplus + GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git + GIT_TAG v3.3.0 ) FetchContent_MakeAvailable(tomlplusplus) +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/libzmq-pkg-config) +find_package(ZeroMQ QUIET) + +if (NOT ZeroMQ_FOUND) + message(STATUS "ZeroMQ not found, using bundled version") + FetchContent_Declare( + zeromq + GIT_REPOSITORY https://github.com/zeromq/libzmq.git + GIT_TAG v4.3.5 + ) + FetchContent_Declare( + cppzmq + GIT_REPOSITORY https://github.com/zeromq/cppzmq.git + GIT_TAG v4.10.0 + ) + set(WITH_PERF_TOOL OFF) + set(ENABLE_CPACK OFF) + set(ZMQ_BUILD_TESTS OFF) + set(WITH_TLS OFF) + set(WITH_DOC OFF) + set(CPPZMQ_BUILD_TESTS OFF) + FetchContent_MakeAvailable(zeromq cppzmq) + include_directories(${zeromq_SOURCE_DIR}/include) + include_directories(${cppzmq_SOURCE_DIR}) +endif () + add_executable(planificador src/host.cpp src/runner.cpp src/config.cpp src/main.cpp) +target_compile_options(planificador PUBLIC -Wall -Wextra -pedantic) target_compile_features(planificador PUBLIC cxx_std_17) include_directories(${tomlplusplus_SOURCE_DIR}/include) diff --git a/libzmq-pkg-config/FindZeroMQ.cmake b/libzmq-pkg-config/FindZeroMQ.cmake new file mode 100644 index 0000000..892762c --- /dev/null +++ b/libzmq-pkg-config/FindZeroMQ.cmake @@ -0,0 +1,28 @@ +# Adapted from https://github.com/zeromq/cppzmq/blob/master/CMakeLists.txt +set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH ON) +find_package(PkgConfig) +pkg_check_modules(PC_LIBZMQ QUIET libzmq) + +set(ZeroMQ_VERSION ${PC_LIBZMQ_VERSION}) + +find_path(ZeroMQ_INCLUDE_DIR zmq.h + PATHS ${ZeroMQ_DIR}/include + ${PC_LIBZMQ_INCLUDE_DIRS}) + +find_library(ZeroMQ_LIBRARY + NAMES zmq + PATHS ${ZeroMQ_DIR}/lib + ${PC_LIBZMQ_LIBDIR} + ${PC_LIBZMQ_LIBRARY_DIRS}) + +if(ZeroMQ_LIBRARY) + set(ZeroMQ_FOUND ON) +endif() + +set ( ZeroMQ_LIBRARIES ${ZeroMQ_LIBRARY} ) +set ( ZeroMQ_INCLUDE_DIRS ${ZeroMQ_INCLUDE_DIR} ) + +include ( FindPackageHandleStandardArgs ) +# handle the QUIETLY and REQUIRED arguments and set ZMQ_FOUND to TRUE +# if all listed variables are TRUE +find_package_handle_standard_args ( ZeroMQ DEFAULT_MSG ZeroMQ_LIBRARIES ZeroMQ_INCLUDE_DIRS ) From c8408620c078c7c8a94a9fb4dda6b42b3279ddad Mon Sep 17 00:00:00 2001 From: clfreville2 Date: Wed, 18 Oct 2023 14:47:30 +0200 Subject: [PATCH 4/6] Link against the system library or the local build --- CMakeLists.txt | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e4c718..0482a7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.14) set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) project(planificador) @@ -15,10 +15,11 @@ FetchContent_MakeAvailable(tomlplusplus) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/libzmq-pkg-config) find_package(ZeroMQ QUIET) +add_executable(planificador src/host.cpp src/runner.cpp src/config.cpp src/main.cpp) if (NOT ZeroMQ_FOUND) message(STATUS "ZeroMQ not found, using bundled version") FetchContent_Declare( - zeromq + zmq GIT_REPOSITORY https://github.com/zeromq/libzmq.git GIT_TAG v4.3.5 ) @@ -32,16 +33,19 @@ if (NOT ZeroMQ_FOUND) set(ZMQ_BUILD_TESTS OFF) set(WITH_TLS OFF) set(WITH_DOC OFF) + set(BUILD_STATIC OFF) + set(BUILD_SHARED ON) + set(ZMQ_BUILD_TESTS OFF) set(CPPZMQ_BUILD_TESTS OFF) - FetchContent_MakeAvailable(zeromq cppzmq) - include_directories(${zeromq_SOURCE_DIR}/include) + FetchContent_MakeAvailable(zmq cppzmq) + include_directories(${zmq_SOURCE_DIR}/include) include_directories(${cppzmq_SOURCE_DIR}) + target_link_libraries(planificador PRIVATE libzmq) +else () + target_link_libraries(planificador PRIVATE zmq) endif () -add_executable(planificador src/host.cpp src/runner.cpp src/config.cpp src/main.cpp) target_compile_options(planificador PUBLIC -Wall -Wextra -pedantic) target_compile_features(planificador PUBLIC cxx_std_17) include_directories(${tomlplusplus_SOURCE_DIR}/include) -include_directories(${cppzmq_SOURCE_DIR}) -target_link_libraries(planificador PRIVATE zmq) From 5435dc638df9aa5916305cb38803f6825c73f8a1 Mon Sep 17 00:00:00 2001 From: clfreville2 Date: Fri, 20 Oct 2023 11:13:55 +0200 Subject: [PATCH 5/6] Read the image from the request --- CMakeLists.txt | 2 +- src/main.cpp | 32 ++++++++++++++++++++++++-------- src/network.cpp | 10 ++++++++++ src/network.hpp | 7 +++++++ 4 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 src/network.cpp create mode 100644 src/network.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0482a7d..9ae1f0e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ FetchContent_MakeAvailable(tomlplusplus) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/libzmq-pkg-config) find_package(ZeroMQ QUIET) -add_executable(planificador src/host.cpp src/runner.cpp src/config.cpp src/main.cpp) +add_executable(planificador src/host.cpp src/runner.cpp src/network.cpp src/config.cpp src/main.cpp) if (NOT ZeroMQ_FOUND) message(STATUS "ZeroMQ not found, using bundled version") FetchContent_Declare( diff --git a/src/main.cpp b/src/main.cpp index 9737048..d761217 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,5 @@ #include "config.hpp" +#include "network.hpp" #include "program.hpp" #include "runner.hpp" #include @@ -13,6 +14,9 @@ #include "host.hpp" #include "zmq_addon.hpp" +static constexpr uint32_t JOB_ID_LEN = 32; +static constexpr uint32_t MIN_MESSAGE_LEN = JOB_ID_LEN + sizeof(uint32_t) * 2; + sk::runner_backend detect_backend() { const char *const argv[] = {"docker", "stats", "--no-stream", nullptr}; pid_t pid; @@ -53,15 +57,27 @@ int main() { while (true) { zmq::message_t request; receiver.recv(request); - if (request.size() < 32) { + if (request.size() < MIN_MESSAGE_LEN) { + std::cerr << "Invalid request" << std::endl; + break; + } + std::string_view jobId(static_cast(request.data()), JOB_ID_LEN); + uint32_t imageLen = + sk::read_uint32(static_cast(request.data()) + JOB_ID_LEN); + uint32_t codeLen = + sk::read_uint32(static_cast(request.data()) + JOB_ID_LEN + sizeof(uint32_t)); + if (request.size() < MIN_MESSAGE_LEN + imageLen + codeLen) { std::cerr << "Invalid request" << std::endl; break; } - std::string_view jobId(static_cast(request.data()), 32); - std::string requestString(static_cast(request.data()) + 32, - request.size() - 32); + std::string imageString(static_cast(request.data()) + + MIN_MESSAGE_LEN, + imageLen); + std::string requestString(static_cast(request.data()) + + MIN_MESSAGE_LEN + imageLen, + codeLen); - std::cout << "Executing " << request.size() << " bytes code.\n"; + std::cout << "Executing " << codeLen << " bytes code.\n"; sk::program program{requestString, "ghcr.io/moshell-lang/moshell:master"}; sk::run_result result = runner.run_blocking(program); @@ -69,9 +85,9 @@ int main() { std::cout << "Result: " << result.out << std::endl; // Send the job id and result.out to sink - zmq::message_t reply(32 + result.out.size()); - memcpy(reply.data(), jobId.data(), 32); - memcpy(static_cast(reply.data()) + 32, result.out.data(), + zmq::message_t reply(JOB_ID_LEN + result.out.size()); + memcpy(reply.data(), jobId.data(), JOB_ID_LEN); + memcpy(static_cast(reply.data()) + JOB_ID_LEN, result.out.data(), result.out.size()); sender.send(reply, zmq::send_flags::none); } diff --git a/src/network.cpp b/src/network.cpp new file mode 100644 index 0000000..8aaa451 --- /dev/null +++ b/src/network.cpp @@ -0,0 +1,10 @@ +#include "network.hpp" + +namespace sk { +uint32_t read_uint32(const char *buffer) { + return static_cast(buffer[3]) | + static_cast(buffer[2]) << 8 | + static_cast(buffer[1]) << 16 | + static_cast(buffer[0]) << 24; +} +} diff --git a/src/network.hpp b/src/network.hpp new file mode 100644 index 0000000..db7ab6c --- /dev/null +++ b/src/network.hpp @@ -0,0 +1,7 @@ +#pragma once + +#include + +namespace sk { +uint32_t read_uint32(const char *buffer); +} From 5154280fd12fe44e5c1a9e639b82161274e4d87a Mon Sep 17 00:00:00 2001 From: bastien ollier Date: Fri, 20 Oct 2023 11:22:28 +0200 Subject: [PATCH 6/6] use the good image --- .clang-format | 1 + src/config.cpp | 6 ++---- src/host.cpp | 17 +++++------------ src/host.hpp | 11 ++++------- src/main.cpp | 28 ++++++++++------------------ src/network.cpp | 7 +------ src/runner.cpp | 33 ++++++--------------------------- 7 files changed, 29 insertions(+), 74 deletions(-) diff --git a/.clang-format b/.clang-format index 37743a5..5b16361 100644 --- a/.clang-format +++ b/.clang-format @@ -2,3 +2,4 @@ BasedOnStyle: LLVM IndentWidth: 4 FixNamespaceComments: false +ColumnLimit: 100000 \ No newline at end of file diff --git a/src/config.cpp b/src/config.cpp index 4b1909e..7a1c7a3 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -17,11 +17,9 @@ std::vector sk::config::loadHostsFromToml(const fs::path &confFile) { } toml::table &serverInfo = *serverInfoPtr; - if (serverInfo.get_as("ip") && - serverInfo.get_as("nbContainerMax")) { + if (serverInfo.get_as("ip") && serverInfo.get_as("nbContainerMax")) { std::string serverIp = serverInfo.get_as("ip")->get(); - int serverMaxContainers = - serverInfo.get_as("nbContainerMax")->get(); + int serverMaxContainers = serverInfo.get_as("nbContainerMax")->get(); hosts.push_back(sk::host(serverIp, serverMaxContainers)); } diff --git a/src/host.cpp b/src/host.cpp index 479281f..6b32fb8 100644 --- a/src/host.cpp +++ b/src/host.cpp @@ -1,23 +1,16 @@ #include "host.hpp" namespace sk { -host::host(const std::string &ip, unsigned int connectionsMax) - : ip{ip}, connections{0}, connectionsMax{connectionsMax}, runners{} {} +host::host(const std::string &ip, unsigned int connectionsMax) : ip{ip}, connections{0}, connectionsMax{connectionsMax}, runners{} {} -void host::addConnection(sk::runner& runner) { +void host::addConnection(sk::runner &runner) { runners.push(runner); connections += 1; } -const std::string& host::getIp() const { - return ip; -} +const std::string &host::getIp() const { return ip; } -unsigned int host::getNbConnections() const { - return connections; -} +unsigned int host::getNbConnections() const { return connections; } -unsigned int host::getNbConnectionsMax() const { - return connectionsMax; -} +unsigned int host::getNbConnectionsMax() const { return connectionsMax; } } diff --git a/src/host.hpp b/src/host.hpp index f5fe88f..a423692 100644 --- a/src/host.hpp +++ b/src/host.hpp @@ -1,8 +1,8 @@ #pragma once -#include +#include "runner.hpp" #include -#include "runner.hpp" +#include namespace sk { class host { @@ -15,16 +15,13 @@ class host { public: host(const std::string &ip, unsigned int connectionsMax); - void addConnection(sk::runner& runner); + void addConnection(sk::runner &runner); const std::string &getIp() const; unsigned int getNbConnections() const; unsigned int getNbConnectionsMax() const; - bool operator<(const host &other) const { - return (connectionsMax - connections) < - other.getNbConnectionsMax() - other.getNbConnections(); - } + bool operator<(const host &other) const { return (connectionsMax - connections) < other.getNbConnectionsMax() - other.getNbConnections(); } }; } diff --git a/src/main.cpp b/src/main.cpp index d761217..7268c51 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,8 +20,7 @@ static constexpr uint32_t MIN_MESSAGE_LEN = JOB_ID_LEN + sizeof(uint32_t) * 2; sk::runner_backend detect_backend() { const char *const argv[] = {"docker", "stats", "--no-stream", nullptr}; pid_t pid; - if (posix_spawnp(&pid, argv[0], nullptr, nullptr, - const_cast(argv), nullptr) != 0) { + if (posix_spawnp(&pid, argv[0], nullptr, nullptr, const_cast(argv), nullptr) != 0) { return sk::runner_backend::BubbleWrap; } int status = 0; @@ -35,8 +34,7 @@ sk::runner_backend detect_backend() { } int main() { - std::vector listsHosts = - sk::config::loadHostsFromToml("../conf.toml"); + std::vector listsHosts = sk::config::loadHostsFromToml("../conf.toml"); std::priority_queue hosts(listsHosts.begin(), listsHosts.end()); std::queue programQueue; @@ -61,25 +59,20 @@ int main() { std::cerr << "Invalid request" << std::endl; break; } + std::string_view jobId(static_cast(request.data()), JOB_ID_LEN); - uint32_t imageLen = - sk::read_uint32(static_cast(request.data()) + JOB_ID_LEN); - uint32_t codeLen = - sk::read_uint32(static_cast(request.data()) + JOB_ID_LEN + sizeof(uint32_t)); + uint32_t imageLen = sk::read_uint32(static_cast(request.data()) + JOB_ID_LEN); + uint32_t codeLen = sk::read_uint32(static_cast(request.data()) + JOB_ID_LEN + sizeof(uint32_t)); + if (request.size() < MIN_MESSAGE_LEN + imageLen + codeLen) { std::cerr << "Invalid request" << std::endl; break; } - std::string imageString(static_cast(request.data()) + - MIN_MESSAGE_LEN, - imageLen); - std::string requestString(static_cast(request.data()) + - MIN_MESSAGE_LEN + imageLen, - codeLen); + std::string imageString(static_cast(request.data()) + MIN_MESSAGE_LEN, imageLen); + std::string requestString(static_cast(request.data()) + MIN_MESSAGE_LEN + imageLen, codeLen); std::cout << "Executing " << codeLen << " bytes code.\n"; - sk::program program{requestString, - "ghcr.io/moshell-lang/moshell:master"}; + sk::program program{requestString, imageString}; sk::run_result result = runner.run_blocking(program); std::cout << "Result: " << result.out << std::endl; @@ -87,8 +80,7 @@ int main() { // Send the job id and result.out to sink zmq::message_t reply(JOB_ID_LEN + result.out.size()); memcpy(reply.data(), jobId.data(), JOB_ID_LEN); - memcpy(static_cast(reply.data()) + JOB_ID_LEN, result.out.data(), - result.out.size()); + memcpy(static_cast(reply.data()) + JOB_ID_LEN, result.out.data(), result.out.size()); sender.send(reply, zmq::send_flags::none); } return 0; diff --git a/src/network.cpp b/src/network.cpp index 8aaa451..d5d3a0c 100644 --- a/src/network.cpp +++ b/src/network.cpp @@ -1,10 +1,5 @@ #include "network.hpp" namespace sk { -uint32_t read_uint32(const char *buffer) { - return static_cast(buffer[3]) | - static_cast(buffer[2]) << 8 | - static_cast(buffer[1]) << 16 | - static_cast(buffer[0]) << 24; -} +uint32_t read_uint32(const char *buffer) { return static_cast(buffer[3]) | static_cast(buffer[2]) << 8 | static_cast(buffer[1]) << 16 | static_cast(buffer[0]) << 24; } } diff --git a/src/runner.cpp b/src/runner.cpp index a3ad56d..f473c0c 100644 --- a/src/runner.cpp +++ b/src/runner.cpp @@ -30,33 +30,15 @@ run_result runner::run_blocking(const program &program) { posix_spawn_file_actions_addclose(&actions, in_pipe[0]); posix_spawn_file_actions_addclose(&actions, out_pipe[1]); posix_spawn_file_actions_addclose(&actions, err_pipe[1]); - const char *const docker_args[] = {"docker", - "run", - "--rm", - "-i", - "--pull=never", - "--cap-drop=ALL", - "--network=none", - "--memory=64m", - "--memory-swap=64m", - "--pids-limit=128", - program.image.c_str(), - nullptr}; - const char *const bwrap_args[] = { - "bwrap", "--ro-bind", "/usr", "/usr", "--dir", - "/tmp", "--dir", "/var", "--proc", "/proc", - "--dev", "/dev", "--symlink", "usr/lib", "/lib", - "--symlink", "usr/lib64", "/lib64", "--symlink", "usr/bin", - "/bin", "--symlink", "usr/sbin", "/sbin", "--unshare-all", - "/bin/sh", nullptr}; + const char *const docker_args[] = {"docker", "run", "--rm", "-i", "--pull=never", "--cap-drop=ALL", "--network=none", "--memory=64m", "--memory-swap=64m", "--pids-limit=128", program.image.c_str(), nullptr}; + const char *const bwrap_args[] = {"bwrap", "--ro-bind", "/usr", "/usr", "--dir", "/tmp", "--dir", "/var", "--proc", "/proc", "--dev", "/dev", "--symlink", "usr/lib", "/lib", "--symlink", "usr/lib64", "/lib64", "--symlink", "usr/bin", "/bin", "--symlink", "usr/sbin", "/sbin", "--unshare-all", "/bin/sh", nullptr}; const char *const *args = docker_args; if (backend == runner_backend::BubbleWrap) { args = bwrap_args; } pid_t pid; int exit_code; - if (posix_spawnp(&pid, args[0], &actions, nullptr, - const_cast(args), nullptr) != 0) { + if (posix_spawnp(&pid, args[0], &actions, nullptr, const_cast(args), nullptr) != 0) { throw std::system_error{errno, std::generic_category()}; } @@ -70,19 +52,16 @@ run_result runner::run_blocking(const program &program) { std::array buffer{}; std::string out; std::string err; - std::array plist = {pollfd{out_pipe[0], POLLIN, 0}, - pollfd{err_pipe[0], POLLIN, 0}}; + std::array plist = {pollfd{out_pipe[0], POLLIN, 0}, pollfd{err_pipe[0], POLLIN, 0}}; while (poll(plist.data(), plist.size(), /*timeout*/ -1) > 0) { if (plist[0].revents & POLLIN) { - ssize_t bytes_read = - read(out_pipe[0], buffer.data(), buffer.size()); + ssize_t bytes_read = read(out_pipe[0], buffer.data(), buffer.size()); if (bytes_read == -1) { throw std::system_error{errno, std::generic_category()}; } out.append(buffer.data(), bytes_read); } else if (plist[1].revents & POLLIN) { - ssize_t bytes_read = - read(err_pipe[0], buffer.data(), buffer.size()); + ssize_t bytes_read = read(err_pipe[0], buffer.data(), buffer.size()); if (bytes_read == -1) { throw std::system_error{errno, std::generic_category()}; }