diff --git a/src/xrt/ipc/client/ipc_client_instance.c b/src/xrt/ipc/client/ipc_client_instance.c index 5dce95eed..a94d4d2ce 100644 --- a/src/xrt/ipc/client/ipc_client_instance.c +++ b/src/xrt/ipc/client/ipc_client_instance.c @@ -20,6 +20,7 @@ #include "shared/ipc_protocol.h" #include "client/ipc_client.h" #include "ipc_client_generated.h" +#include "util/u_file.h" #include <stdio.h> #include <sys/socket.h> @@ -31,7 +32,7 @@ #include <errno.h> #include <fcntl.h> #include <unistd.h> - +#include <limits.h> #ifdef XRT_GRAPHICS_BUFFER_HANDLE_IS_AHARDWAREBUFFER #include "android/android_ahardwarebuffer_allocator.h" @@ -126,9 +127,17 @@ ipc_connect(struct ipc_connection *ipc_c) int socket = ret; + char sock_file[PATH_MAX]; + + int size = u_file_get_path_in_runtime_dir(IPC_MSG_SOCK_FILE, sock_file, PATH_MAX); + if (size == -1) { + IPC_ERROR(ipc_c, "Could not get socket file name"); + return -1; + } + memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; - strcpy(addr.sun_path, IPC_MSG_SOCK_FILE); + strcpy(addr.sun_path, sock_file); ret = connect(socket, (struct sockaddr *)&addr, sizeof(addr)); if (ret < 0) { diff --git a/src/xrt/ipc/server/ipc_server_mainloop_linux.c b/src/xrt/ipc/server/ipc_server_mainloop_linux.c index 31b1c6348..376e09dda 100644 --- a/src/xrt/ipc/server/ipc_server_mainloop_linux.c +++ b/src/xrt/ipc/server/ipc_server_mainloop_linux.c @@ -20,6 +20,7 @@ #include "util/u_misc.h" #include "util/u_debug.h" #include "util/u_trace_marker.h" +#include "util/u_file.h" #include "shared/ipc_shmem.h" #include "server/ipc_server.h" @@ -39,6 +40,7 @@ #include <stdio.h> #include <string.h> #include <assert.h> +#include <limits.h> #ifdef XRT_HAVE_SYSTEMD #include <systemd/sd-daemon.h> @@ -82,21 +84,30 @@ create_listen_socket(struct ipc_server_mainloop *ml, int *out_fd) return fd; } + + char sock_file[PATH_MAX]; + + int size = u_file_get_path_in_runtime_dir(IPC_MSG_SOCK_FILE, sock_file, PATH_MAX); + if (size == -1) { + U_LOG_E("Could not get socket file name"); + return -1; + } + memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; - strcpy(addr.sun_path, IPC_MSG_SOCK_FILE); + strcpy(addr.sun_path, sock_file); ret = bind(fd, (struct sockaddr *)&addr, sizeof(addr)); #ifdef XRT_HAVE_LIBBSD // no other instance is running, or we would have never arrived here if (ret < 0 && errno == EADDRINUSE) { - U_LOG_W("Removing stale socket file %s", IPC_MSG_SOCK_FILE); + U_LOG_W("Removing stale socket file %s", sock_file); - ret = unlink(IPC_MSG_SOCK_FILE); + ret = unlink(sock_file); if (ret < 0) { - U_LOG_E("Failed to remove stale socket file %s: %s", IPC_MSG_SOCK_FILE, strerror(errno)); + U_LOG_E("Failed to remove stale socket file %s: %s", sock_file, strerror(errno)); return ret; } ret = bind(fd, (struct sockaddr *)&addr, sizeof(addr)); @@ -104,27 +115,27 @@ create_listen_socket(struct ipc_server_mainloop *ml, int *out_fd) #endif if (ret < 0) { - U_LOG_E("Could not bind socket to path %s: %s. Is the service running already?", IPC_MSG_SOCK_FILE, + U_LOG_E("Could not bind socket to path %s: %s. Is the service running already?", sock_file, strerror(errno)); #ifdef XRT_HAVE_SYSTEMD U_LOG_E("Or, is the systemd unit monado.socket or monado-dev.socket active?"); #endif if (errno == EADDRINUSE) { U_LOG_E("If monado-service is not running, delete %s before starting a new instance", - IPC_MSG_SOCK_FILE); + sock_file); } close(fd); return ret; } // Save for later - ml->socket_filename = strdup(IPC_MSG_SOCK_FILE); + ml->socket_filename = strdup(sock_file); ret = listen(fd, IPC_MAX_CLIENTS); if (ret < 0) { close(fd); return ret; } - U_LOG_D("Created listening socket %s.", IPC_MSG_SOCK_FILE); + U_LOG_D("Created listening socket %s.", sock_file); *out_fd = fd; return 0; } diff --git a/src/xrt/ipc/shared/ipc_protocol.h b/src/xrt/ipc/shared/ipc_protocol.h index 5d3060e5a..e2dcdb868 100644 --- a/src/xrt/ipc/shared/ipc_protocol.h +++ b/src/xrt/ipc/shared/ipc_protocol.h @@ -20,7 +20,7 @@ #include "xrt/xrt_tracking.h" -#define IPC_MSG_SOCK_FILE "/tmp/monado_comp_ipc" +#define IPC_MSG_SOCK_FILE "monado_comp_ipc" #define IPC_MAX_SWAPCHAIN_HANDLES 8 #define IPC_CRED_SIZE 1 // auth not implemented #define IPC_BUF_SIZE 512 // must be >= largest message length in bytes diff --git a/src/xrt/targets/ctl/main.c b/src/xrt/targets/ctl/main.c index 06f68b850..bd915dc24 100644 --- a/src/xrt/targets/ctl/main.c +++ b/src/xrt/targets/ctl/main.c @@ -16,6 +16,9 @@ #include <unistd.h> #include <errno.h> #include <sys/mman.h> +#include <limits.h> + +#include "util/u_file.h" #define P(...) fprintf(stdout, __VA_ARGS__) #define PE(...) fprintf(stderr, __VA_ARGS__) @@ -212,9 +215,17 @@ do_connect(struct ipc_connection *ipc_c) return -1; } + char sock_file[PATH_MAX]; + + int rt_size = u_file_get_path_in_runtime_dir(IPC_MSG_SOCK_FILE, sock_file, PATH_MAX); + if (rt_size == -1) { + PE("Could not get socket file name"); + return -1; + } + struct sockaddr_un addr = {0}; addr.sun_family = AF_UNIX; - strcpy(addr.sun_path, IPC_MSG_SOCK_FILE); + strcpy(addr.sun_path, sock_file); ret = connect(ipc_c->imc.socket_fd, // socket (struct sockaddr *)&addr, // address diff --git a/src/xrt/targets/service/monado.in.socket b/src/xrt/targets/service/monado.in.socket index 545486bb8..59f490985 100644 --- a/src/xrt/targets/service/monado.in.socket +++ b/src/xrt/targets/service/monado.in.socket @@ -7,7 +7,7 @@ ConditionUser=!root Conflicts=@conflicts@.socket [Socket] -ListenStream=/tmp/monado_comp_ipc +ListenStream=%t/monado_comp_ipc RemoveOnStop=true [Install]