From 8bef26fef42914cb773ff39fdc8b9702ee5ec26f Mon Sep 17 00:00:00 2001 From: ABeltramo Date: Sun, 4 Feb 2024 10:44:31 +0000 Subject: [PATCH] fix: docker, log when exec fails and avoid double mounting initial devices --- docker/startup.sh | 2 +- docker/wolf.Dockerfile | 2 +- .../src/platforms/all/docker/docker/docker.cpp | 16 ++++++++++++++-- src/moonlight-server/runners/docker.hpp | 11 ++++++++--- src/moonlight-server/wolf.cpp | 1 - 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/docker/startup.sh b/docker/startup.sh index a4b65841..f90b8ef5 100644 --- a/docker/startup.sh +++ b/docker/startup.sh @@ -2,6 +2,6 @@ set -e # Update fake-udev if missing from the path -cp /wolf/fake-udev $WOLF_CFG_FOLDER/fake-udev +cp /wolf/fake-udev $WOLF_DOCKER_FAKE_UDEV_PATH exec /wolf/wolf \ No newline at end of file diff --git a/docker/wolf.Dockerfile b/docker/wolf.Dockerfile index b3c84616..184eed79 100644 --- a/docker/wolf.Dockerfile +++ b/docker/wolf.Dockerfile @@ -111,7 +111,7 @@ ENV XDG_RUNTIME_DIR=/tmp/sockets \ WOLF_DOCKER_SOCKET=/var/run/docker.sock \ RUST_BACKTRACE=full \ HOST_APPS_STATE_FOLDER=/etc/wolf \ - WOLF_DOCKER_FAKE_UDEV_PATH=/etc/wolf/fake-udev \ + WOLF_DOCKER_FAKE_UDEV_PATH=$HOST_APPS_STATE_FOLDER/fake-udev \ GST_DEBUG=2 \ PUID=0 \ PGID=0 \ diff --git a/src/core/src/platforms/all/docker/docker/docker.cpp b/src/core/src/platforms/all/docker/docker/docker.cpp index e6693201..66d1f8f6 100644 --- a/src/core/src/platforms/all/docker/docker/docker.cpp +++ b/src/core/src/platforms/all/docker/docker/docker.cpp @@ -342,8 +342,20 @@ bool DockerAPI::exec(std::string_view id, const std::vector &c json_payload = json::serialize(post_params); raw_msg = req(conn.value().get(), POST, api_url, json_payload); if (raw_msg && raw_msg->first == 200) { - // Exec request completed, return - return true; + auto console = raw_msg->second; + // Exec request completed, inspect the results + api_url = fmt::format("http://localhost/{}/exec/{}/json", DOCKER_API_VERSION, exec_id); + raw_msg = req(conn.value().get(), GET, api_url); + if (raw_msg && raw_msg->first == 200) { + json = parse(raw_msg->second); + auto exit_code = json.at("ExitCode").as_int64(); + if (exit_code != 0) { + logs::log(logs::warning, "Docker exec failed ({}), {}", exit_code, console); + return false; + } else { + return true; + } + } } } diff --git a/src/moonlight-server/runners/docker.hpp b/src/moonlight-server/runners/docker.hpp index eb219a76..42deaaef 100644 --- a/src/moonlight-server/runners/docker.hpp +++ b/src/moonlight-server/runners/docker.hpp @@ -163,9 +163,10 @@ void RunDocker::run(std::size_t session_id, // Fake udev auto udev_base_path = std::filesystem::path(app_state_folder) / "udev"; auto hw_db_path = udev_base_path / "data"; - auto fake_udev_cli_path = std::string(utils::get_env("WOLF_DOCKER_FAKE_UDEV_PATH")); - bool use_fake_udev = !fake_udev_cli_path.empty(); + auto fake_udev_cli_path = std::string(utils::get_env("WOLF_DOCKER_FAKE_UDEV_PATH", "")); + bool use_fake_udev = !fake_udev_cli_path.empty() || std::filesystem::exists(fake_udev_cli_path); if (use_fake_udev) { + logs::log(logs::debug, "[DOCKER] Using fake-udev, creating {}", hw_db_path.string()); std::filesystem::create_directories(hw_db_path); // Check if /run/udev/control exists @@ -178,6 +179,10 @@ void RunDocker::run(std::size_t session_id, } mounts.push_back(MountPoint{.source = udev_base_path.string(), .destination = "/run/udev/", .mode = "rw"}); mounts.push_back(MountPoint{.source = fake_udev_cli_path, .destination = "/usr/bin/fake-udev", .mode = "ro"}); + } else { + logs::log(logs::warning, + "[DOCKER] Unable to use fake-udev, check the env variable WOLF_DOCKER_FAKE_UDEV_PATH and the file at {}", + fake_udev_cli_path); } Container new_container = {.id = "", .name = fmt::format("{}_{}", this->container.name, session_id), @@ -233,7 +238,7 @@ void RunDocker::run(std::size_t session_id, if (udev_ev.count("DEVNAME") == 0) { cmd = fmt::format("fake-udev -m {}", udev_msg); } else { - cmd = fmt::format("mknod {} c {} {} && chmod 777 {} && fake-udev -m {}", + cmd = fmt::format("mkdir -p /dev/input && mknod {} c {} {} && chmod 777 {} && fake-udev -m {}", udev_ev["DEVNAME"], udev_ev["MAJOR"], udev_ev["MINOR"], diff --git a/src/moonlight-server/wolf.cpp b/src/moonlight-server/wolf.cpp index fb85d576..f353651d 100644 --- a/src/moonlight-server/wolf.cpp +++ b/src/moonlight-server/wolf.cpp @@ -242,7 +242,6 @@ auto setup_sessions_handlers(const immer::box &app_state, auto input_nodes = immer::array_transient(); std::copy(mouse_nodes.begin(), mouse_nodes.end(), std::back_inserter(input_nodes)); std::copy(kb_nodes.begin(), kb_nodes.end(), std::back_inserter(input_nodes)); - std::copy(input_nodes.begin(), input_nodes.end(), std::back_inserter(all_devices)); auto wl_state = virtual_display::create_wayland_display(input_nodes.persistent(), render_node); virtual_display::set_resolution(