Add --systemd command line option
When enabled, will start a new service for client application instead of forking.
This commit is contained in:
@@ -24,7 +24,7 @@ jobs:
|
||||
|
||||
- name: Install dependencies
|
||||
run: >
|
||||
sudo apt-get update && sudo apt-get install libvulkan-dev libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libavahi-client-dev libeigen3-dev glslang-tools libudev-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev libpulse-dev xz-utils libpipewire-0.3-dev
|
||||
sudo apt-get update && sudo apt-get install libvulkan-dev libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libavahi-client-dev libeigen3-dev glslang-tools libudev-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev libpulse-dev xz-utils libpipewire-0.3-dev libcli11-dev
|
||||
- name: Prepare Vulkan SDK
|
||||
uses: humbletim/setup-vulkan-sdk@286ed76c72de45dbf50c515779cf4ca2f6aa3944
|
||||
with:
|
||||
|
||||
@@ -139,6 +139,7 @@ if (WIVRN_BUILD_SERVER)
|
||||
pkg_check_modules(AVAHI REQUIRED IMPORTED_TARGET avahi-client)
|
||||
find_package(Eigen3 REQUIRED)
|
||||
find_package(nlohmann_json REQUIRED)
|
||||
find_package(CLI11 REQUIRED)
|
||||
endif()
|
||||
|
||||
if (WIVRN_BUILD_CLIENT AND NOT ANDROID)
|
||||
|
||||
@@ -77,6 +77,7 @@ WiVRn uses the following software:
|
||||
- [Avahi](https://www.avahi.org/)
|
||||
- [Boost.Locale](https://github.com/boostorg/locale)
|
||||
- [Boost.PFR](https://github.com/boostorg/pfr)
|
||||
- [CLI11](https://github.com/CLIUtils/CLI11)
|
||||
- [Dear ImGui](https://github.com/ocornut/imgui)
|
||||
- [fastgltf](https://github.com/spnda/fastgltf)
|
||||
- [ffmpeg](https://ffmpeg.org/) optional, for hardware encoding on AMD/Intel
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ Additionally, if your environment requires absolute paths inside the OpenXR runt
|
||||
# Client (headset)
|
||||
|
||||
#### Build dependencies
|
||||
As Arch package names: git pkgconf glslang cmake jre17-openjdk librsvg
|
||||
As Arch package names: git pkgconf glslang cmake jre17-openjdk librsvg cli11
|
||||
|
||||
#### Android environment
|
||||
Download [sdkmanager](https://developer.android.com/tools/sdkmanager) commandline tool and extract it to any directory.
|
||||
|
||||
@@ -95,6 +95,8 @@ target_compile_definitions(wivrn-server PRIVATE VULKAN_HPP_NO_CONSTRUCTORS)
|
||||
target_include_directories(wivrn-server SYSTEM PRIVATE ${monado_SOURCE_DIR}/src/xrt/compositor/)
|
||||
target_include_directories(wivrn-server PRIVATE .)
|
||||
|
||||
target_link_libraries(wivrn-server PRIVATE CLI11::CLI11)
|
||||
|
||||
if(WIVRN_USE_NVENC)
|
||||
target_sources(wivrn-server PRIVATE encoder/video_encoder_nvenc.cpp)
|
||||
endif()
|
||||
|
||||
Vendored
+1
-1
@@ -3,7 +3,7 @@ Description=OpenXR streaming server
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=@CMAKE_INSTALL_PREFIX@/bin/wivrn-server
|
||||
ExecStart=@CMAKE_INSTALL_PREFIX@/bin/wivrn-server --systemd
|
||||
CapabilityBoundingSet=CAP_SYS_NICE
|
||||
AmbientCapabilities=CAP_SYS_NICE
|
||||
LockPersonality=true
|
||||
|
||||
+28
-30
@@ -17,6 +17,7 @@
|
||||
#include "wivrn_ipc.h"
|
||||
#include "wivrn_sockets.h"
|
||||
|
||||
#include <CLI/CLI.hpp>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <poll.h>
|
||||
@@ -122,11 +123,13 @@ void waitpid_verbose(pid_t pid, const std::string & name)
|
||||
}
|
||||
}
|
||||
|
||||
int inner_main(int argc, char * argv[])
|
||||
int inner_main(int argc, char * argv[], bool use_systemd)
|
||||
{
|
||||
std::cerr << "WiVRn " << xrt::drivers::wivrn::git_version << " starting" << std::endl;
|
||||
#ifdef WIVRN_USE_SYSTEMD
|
||||
create_listen_socket();
|
||||
#else
|
||||
assert(not systemd);
|
||||
#endif
|
||||
|
||||
u_trace_marker_init();
|
||||
@@ -176,7 +179,11 @@ int inner_main(int argc, char * argv[])
|
||||
|
||||
active_runtime runtime_setter;
|
||||
|
||||
#ifdef WIVRN_USE_SYSTEMD
|
||||
pid_t client_pid = use_systemd ? start_unit_file() : fork_application();
|
||||
#else
|
||||
pid_t client_pid = fork_application();
|
||||
#endif
|
||||
|
||||
pid_t server_pid = fork();
|
||||
|
||||
@@ -208,12 +215,6 @@ int inner_main(int argc, char * argv[])
|
||||
// FIXME: synchronization fails on gfx pipeline
|
||||
setenv("XRT_COMPOSITOR_COMPUTE", "1", true);
|
||||
|
||||
// FIXME: use a proper library for cli options
|
||||
if (argc == 2 and strcmp(argv[1], "-f") == 0)
|
||||
{
|
||||
configuration::set_config_file(argv[2]);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return ipc_server_main(argc, argv);
|
||||
@@ -338,32 +339,29 @@ int inner_main(int argc, char * argv[])
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
if (argc > 1)
|
||||
{
|
||||
if ((strcmp(argv[1], "--application") == 0))
|
||||
{
|
||||
pid_t pid = exec_application(configuration::read_user_configuration());
|
||||
if (pid < 0)
|
||||
{
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
else if ((strcmp(argv[1], "-f") != 0 or argc < 3))
|
||||
{
|
||||
std::cerr << "Usage: " << argv[0] << " [-f file]" << std::endl
|
||||
<< "\t -f file: configuration file to use" << std::endl;
|
||||
if (strcmp(argv[1], "-h") != 0 and strcmp(argv[1], "--help") != 0)
|
||||
{
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
CLI::App app;
|
||||
|
||||
std::string config_file;
|
||||
bool use_systemd = false;
|
||||
app.add_option("-f", config_file, "configuration file")->option_text("FILE")->check(CLI::ExistingFile);
|
||||
#ifdef WIVRN_USE_SYSTEMD
|
||||
// --application should only be used from wivrn-application unit file
|
||||
auto app_flag = app.add_flag("--application")->group("");
|
||||
app.add_flag("--systemd", use_systemd, "use systemd to launch user-configured application");
|
||||
#endif
|
||||
|
||||
CLI11_PARSE(app, argc, argv);
|
||||
|
||||
if (not config_file.empty())
|
||||
configuration::set_config_file(config_file);
|
||||
|
||||
#ifdef WIVRN_USE_SYSTEMD
|
||||
if (*app_flag)
|
||||
return exec_application(configuration::read_user_configuration());
|
||||
#endif
|
||||
try
|
||||
{
|
||||
return inner_main(argc, argv);
|
||||
return inner_main(argc, argv, use_systemd);
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "start_application.h"
|
||||
|
||||
#include "driver/configuration.h"
|
||||
#include "wivrn_config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
@@ -21,26 +20,7 @@
|
||||
#include <string>
|
||||
#include <systemd/sd-bus.h>
|
||||
#include <thread>
|
||||
#endif
|
||||
|
||||
int exec_application(configuration config)
|
||||
{
|
||||
if (config.application.empty())
|
||||
return 0;
|
||||
|
||||
std::vector<char *> argv;
|
||||
argv.reserve(config.application.size() + 1);
|
||||
for (auto & arg: config.application)
|
||||
argv.push_back(arg.data());
|
||||
argv.push_back(nullptr);
|
||||
|
||||
execvp(config.application.front().c_str(), argv.data());
|
||||
|
||||
perror("Cannot start application");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
#ifdef WIVRN_USE_SYSTEMD
|
||||
int get_service_pid(const std::string & service_name, pid_t & pid)
|
||||
{
|
||||
sd_bus * bus = nullptr;
|
||||
@@ -185,7 +165,7 @@ finish:
|
||||
return is_active;
|
||||
}
|
||||
|
||||
pid_t fork_application()
|
||||
pid_t start_unit_file()
|
||||
{
|
||||
std::string service_name = "wivrn-application.service";
|
||||
pid_t pid;
|
||||
@@ -218,30 +198,46 @@ pid_t fork_application()
|
||||
return pid;
|
||||
}
|
||||
|
||||
#else
|
||||
#endif
|
||||
|
||||
pid_t fork_application()
|
||||
{
|
||||
auto config = configuration::read_user_configuration();
|
||||
|
||||
if (!config.application.empty())
|
||||
if (config.application.empty())
|
||||
return 0;
|
||||
|
||||
pid_t application_pid = fork();
|
||||
if (application_pid < 0)
|
||||
{
|
||||
pid_t application_pid = fork();
|
||||
if (application_pid < 0)
|
||||
{
|
||||
throw std::system_error(errno, std::system_category(), "fork");
|
||||
}
|
||||
|
||||
if (application_pid == 0)
|
||||
{
|
||||
// Start a new process group so that all processes started by the
|
||||
// application can be signaled
|
||||
setpgrp();
|
||||
|
||||
return exec_application(config);
|
||||
}
|
||||
throw std::system_error(errno, std::system_category(), "fork");
|
||||
}
|
||||
|
||||
return 0;
|
||||
if (application_pid == 0)
|
||||
{
|
||||
// Start a new process group so that all processes started by the
|
||||
// application can be signaled
|
||||
setpgrp();
|
||||
|
||||
return exec_application(config);
|
||||
}
|
||||
|
||||
return application_pid;
|
||||
}
|
||||
|
||||
int exec_application(configuration config)
|
||||
{
|
||||
if (config.application.empty())
|
||||
return 0;
|
||||
|
||||
std::vector<char *> argv;
|
||||
argv.reserve(config.application.size() + 1);
|
||||
for (auto & arg: config.application)
|
||||
argv.push_back(arg.data());
|
||||
argv.push_back(nullptr);
|
||||
|
||||
execvp(config.application.front().c_str(), argv.data());
|
||||
|
||||
perror("Cannot start application");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "wivrn_config.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
struct configuration;
|
||||
|
||||
pid_t fork_application();
|
||||
#ifdef WIVRN_USE_SYSTEMD
|
||||
pid_t start_unit_file();
|
||||
#endif
|
||||
int exec_application(configuration);
|
||||
|
||||
Reference in New Issue
Block a user