mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-31 19:08:30 +00:00
ipc: Use xdg runtime directory for socket
u_file_get_runtime_dir falls back to /tmp if $XDG_RUNTIME_DIR is not set. ipc: %t/monado_comp_ipc socket for systemd socket activation
This commit is contained in:
parent
4ea68b89a4
commit
fd6bd0f592
src/xrt
ipc
targets
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -7,7 +7,7 @@ ConditionUser=!root
|
|||
Conflicts=@conflicts@.socket
|
||||
|
||||
[Socket]
|
||||
ListenStream=/tmp/monado_comp_ipc
|
||||
ListenStream=%t/monado_comp_ipc
|
||||
RemoveOnStop=true
|
||||
|
||||
[Install]
|
||||
|
|
Loading…
Reference in a new issue