From 5f59dfb589ee2ceeae82d8e7178a03f52daa7d76 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Tue, 8 Oct 2024 23:02:26 +0200 Subject: [PATCH] More reliable mechanism to pass monado socket Using systemd's socket activation path fails in case file descriptor is not 3. Use a global variable instead. --- .../monado/0003-Use-extern-socket-fd.patch | 38 +++++++++++++++++++ server/main.cpp | 16 ++------ 2 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 patches/monado/0003-Use-extern-socket-fd.patch diff --git a/patches/monado/0003-Use-extern-socket-fd.patch b/patches/monado/0003-Use-extern-socket-fd.patch new file mode 100644 index 00000000..6b011c7a --- /dev/null +++ b/patches/monado/0003-Use-extern-socket-fd.patch @@ -0,0 +1,38 @@ +From d587f4215cbdfebef6de7537338a889c082b3f64 Mon Sep 17 00:00:00 2001 +From: Patrick Nicolas +Date: Tue, 8 Oct 2024 22:13:15 +0200 +Subject: [PATCH] Use extern socket fd + +--- + src/xrt/ipc/server/ipc_server_mainloop_linux.c | 8 ++++++++ + 1 file changed, 8 insertions(+) + +diff --git a/src/xrt/ipc/server/ipc_server_mainloop_linux.c b/src/xrt/ipc/server/ipc_server_mainloop_linux.c +index ad6b473b7..ea6fad65b 100644 +--- a/src/xrt/ipc/server/ipc_server_mainloop_linux.c ++++ b/src/xrt/ipc/server/ipc_server_mainloop_linux.c +@@ -55,6 +55,8 @@ + */ + DEBUG_GET_ONCE_BOOL_OPTION(skip_stdin, "XRT_NO_STDIN", false) + ++extern int listen_socket; ++ + /* + * + * Static functions. +@@ -63,6 +65,12 @@ DEBUG_GET_ONCE_BOOL_OPTION(skip_stdin, "XRT_NO_STDIN", false) + static int + get_systemd_socket(struct ipc_server_mainloop *ml, int *out_fd) + { ++ if (listen_socket >= 0) ++ { ++ ml->launched_by_socket = true; ++ *out_fd = listen_socket; ++ return 0; ++ } + #ifdef XRT_HAVE_SYSTEMD + // We may have been launched with socket activation + int num_fds = sd_listen_fds(0); +-- +2.47.0 + diff --git a/server/main.cpp b/server/main.cpp index 9919c19d..07a1914f 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -48,6 +48,8 @@ extern "C" { int ipc_server_main(int argc, char * argv[]); + + int listen_socket = -1; } using namespace wivrn; @@ -64,7 +66,6 @@ std::filesystem::path socket_path() return {sock_file, sock_file + size}; } -#if WIVRN_USE_SYSTEMD int create_listen_socket() { sockaddr_un addr{}; @@ -109,15 +110,8 @@ int create_listen_socket() throw std::system_error(errno, std::system_category()); } - // we use "socket activation" mode of monado, - // it requires fd to be SD_LISTEN_FDS_START, which is 3 - assert(fd == 3); - - setenv("LISTEN_FDS", "1", true); - return fd; } -#endif void display_child_status(int wstatus, const std::string & name) { @@ -604,11 +598,7 @@ int inner_main(int argc, char * argv[], bool show_instructions) std::filesystem::create_directories(socket_path().parent_path()); -#if WIVRN_USE_SYSTEMD - create_listen_socket(); -#else - assert(not use_systemd); -#endif + listen_socket = create_listen_socket(); u_trace_marker_init();