Commit 2f8c8c5e authored by Manuel Stoeckl's avatar Manuel Stoeckl
Browse files

Add option to set Wayland display socket path

The default socket path has been adjusted to fall inside
$XDG_RUNTIME_DIR. This lets waypipe provide a 'relative' socket
name in $WAYLAND_DISPLAY, making it possible for waypipe to work
with versions of libwayland that do not support absolute display
socket paths.
parent 3247bf4b
Pipeline #46771 passed with stages
in 58 seconds
......@@ -41,11 +41,11 @@ Build with meson[0]. A typical incantation is
Requirements:
* meson (build, >= 0.47. and its dependencies `ninja` and `pkg-config`)
* wayland (build; clients need >= 1.15 to handle absolute paths in WAYLAND_DISPLAY)
* meson (build, >= 0.47. with dependencies `ninja`, `pkg-config`, `python3`)
* wayland (build, >= 1.10 for the `wl_surface::damage_buffer` request)
* wayland-protocols (build, >= 1.12, for the xdg-shell protocol, and others)
* libzstd (optional)
* liblz4 (optional)
* libzstd (optional, >= 1.4.0)
* libgbm (optional, to support programs using OpenGL via DMABUFs)
* libdrm (optional, same as for libgbm)
* ffmpeg (optional, >=3.1, needs avcodec/avutil/swscale for lossy video encoding)
......
......@@ -16,7 +16,6 @@ wl_registry_req_bind
wl_shm_req_create_pool
wl_shm_pool_req_create_buffer
wl_shm_pool_req_resize
wl_surface_req_amage_buffer
wl_surface_req_attach
wl_surface_req_commit
wl_surface_req_damage
......
......@@ -38,8 +38,9 @@
#include <sys/wait.h>
#include <unistd.h>
int run_server(const char *socket_path, const struct main_config *config,
bool oneshot, bool unlink_at_end, const char *application,
int run_server(const char *socket_path, const char *wayland_display,
const struct main_config *config, bool oneshot,
bool unlink_at_end, const char *application,
char *const app_argv[])
{
wp_log(WP_DEBUG, "I'm a server on %s, running: %s", socket_path,
......@@ -52,10 +53,24 @@ int run_server(const char *socket_path, const struct main_config *config,
socket_path);
return EXIT_FAILURE;
}
char display_path[256];
if (!oneshot) {
if (wayland_display[0] == '/') {
snprintf(display_path, 256, "%s", wayland_display);
} else {
const char *xdg_dir = getenv("XDG_RUNTIME_DIR");
if (!xdg_dir) {
wp_log(WP_ERROR,
"Env. var XDG_RUNTIME_DIR not available, cannot place display socket for WAYLAND_DISPLAY=\"%s\"",
wayland_display);
return EXIT_FAILURE;
}
snprintf(display_path, 256, "%s/%s", xdg_dir,
wayland_display);
}
}
// Setup connection to program
char displaypath[256];
sprintf(displaypath, "%s.disp.sock", socket_path);
int wayland_socket = -1, server_link = -1, wdisplay_socket = -1;
if (oneshot) {
int csockpair[2];
......@@ -69,7 +84,7 @@ int run_server(const char *socket_path, const struct main_config *config,
} else {
// Bind a socket for WAYLAND_DISPLAY, and listen
int nmaxclients = 128;
wdisplay_socket = setup_nb_socket(displaypath, nmaxclients);
wdisplay_socket = setup_nb_socket(display_path, nmaxclients);
if (wdisplay_socket == -1) {
// Error messages already made
return EXIT_FAILURE;
......@@ -81,7 +96,7 @@ int run_server(const char *socket_path, const struct main_config *config,
if (pid == -1) {
wp_log(WP_ERROR, "Fork failed");
if (!oneshot) {
unlink(displaypath);
unlink(display_path);
}
return EXIT_FAILURE;
} else if (pid == 0) {
......@@ -98,7 +113,7 @@ int run_server(const char *socket_path, const struct main_config *config,
// Since Wayland 1.15, absolute paths are supported in
// WAYLAND_DISPLAY
unsetenv("WAYLAND_SOCKET");
setenv("WAYLAND_DISPLAY", displaypath, 1);
setenv("WAYLAND_DISPLAY", wayland_display, 1);
close(wdisplay_socket);
}
......@@ -205,7 +220,7 @@ int run_server(const char *socket_path, const struct main_config *config,
if (unlink_at_end) {
unlink(socket_path);
}
unlink(displaypath);
unlink(display_path);
close(wdisplay_socket);
// Wait for child processes to exit
......
......@@ -163,12 +163,19 @@ run_test(
False,
False,
)
run_test(
"b_server_no_env",
[waypipe_path, "-s", server_socket_path, "server", "sleep", "0.26"],
base_env,
False,
False,
)
# Configurations that should succeed
run_test(
"g_server_no_env",
"g_server_std_env",
[waypipe_path, "-s", server_socket_path, "server", "sleep", "0.26"],
base_env,
standard_env,
False,
True,
)
......
......@@ -39,8 +39,9 @@
#include <time.h>
#include <unistd.h>
int run_server(const char *socket_path, const struct main_config *config,
bool oneshot, bool unlink_at_end, const char *application,
int run_server(const char *socket_path, const char *display_path,
const struct main_config *config, bool oneshot,
bool unlink_at_end, const char *application,
char *const app_argv[]);
int run_client(const char *socket_path, const struct main_config *config,
bool oneshot, bool via_socket, pid_t eol_pid);
......@@ -77,13 +78,14 @@ static const char usage_string[] =
" client default: /tmp/waypipe-client.sock\n"
" ssh mode: sets the prefix for the socket path\n"
" -v, --version print waypipe version and exit\n"
" --display D server,ssh mode: set the Wayland display name or path\n"
" --drm-node R set the local render node. default: /dev/dri/renderD128\n"
" --remote-node R ssh mode: set the remote render node path\n"
" --linear-dmabuf only permit gpu buffers without modifier flags\n"
" --login-shell server mode: if server CMD is empty, run a login shell\n"
" --threads T set thread pool size, default=hardware threads/2\n"
" --unlink-socket server mode: unlink the socket that waypipe connects to\n"
" --linear-dmabuf only permit gpu buffers without modifier flags\n"
" --video compress certain linear dmabufs only with a video codec\n"
" --threads T set thread pool size, default=hardware threads/2\n"
"\n";
static int usage(int retcode)
......@@ -250,13 +252,14 @@ static void setup_login_shell_command(char shell[static 256],
void handle_noop(int sig) { (void)sig; }
#define ARG_UNLINK 1001
#define ARG_DISPLAY 1001
#define ARG_DRMNODE 1002
#define ARG_REMOTENODE 1003
#define ARG_LINEAR_DMABUF 1003
#define ARG_LOGIN_SHELL 1004
#define ARG_LINEAR_DMABUF 1005
#define ARG_VIDEO 1006
#define ARG_THREADS 1007
#define ARG_REMOTENODE 1005
#define ARG_THREADS 1006
#define ARG_UNLINK 1007
#define ARG_VIDEO 1008
static const struct option options[] = {
{"compress", required_argument, NULL, 'c'},
......@@ -273,6 +276,7 @@ static const struct option options[] = {
{"linear-dmabuf", no_argument, NULL, ARG_LINEAR_DMABUF},
{"video", no_argument, NULL, ARG_VIDEO},
{"threads", required_argument, NULL, ARG_THREADS},
{"display", required_argument, NULL, ARG_DISPLAY},
{0, 0, NULL, 0}};
int main(int argc, char **argv)
......@@ -287,6 +291,7 @@ int main(int argc, char **argv)
char *remote_drm_node = NULL;
char *comp_string = NULL;
char *nthread_string = NULL;
char *wayland_display = NULL;
const char *socketpath = NULL;
struct main_config config = {
......@@ -368,6 +373,12 @@ int main(int argc, char **argv)
case 'v':
version = true;
break;
case ARG_DISPLAY:
if (mode == MODE_CLIENT) {
fail = true;
}
wayland_display = optarg;
break;
case ARG_UNLINK:
if (mode != MODE_SERVER) {
fail = true;
......@@ -487,8 +498,16 @@ int main(int argc, char **argv)
if (!socketpath) {
socketpath = "/tmp/waypipe-server.sock";
}
return run_server(socketpath, &config, oneshot, unlink_at_end,
application, app_argv);
char display_path[20];
if (!wayland_display) {
char rbytes[9];
fill_rand_token(rbytes);
rbytes[8] = 0;
sprintf(display_path, "wayland-%s", rbytes);
wayland_display = display_path;
}
return run_server(socketpath, wayland_display, &config, oneshot,
unlink_at_end, application, app_argv);
} else {
if (!socketpath) {
socketpath = "/tmp/waypipe";
......@@ -510,9 +529,14 @@ int main(int argc, char **argv)
char linkage[256];
char serversock[110];
char clientsock[110];
char remote_display[20];
sprintf(serversock, "%s-server-%s.sock", socketpath, rbytes);
sprintf(clientsock, "%s-client-%s.sock", socketpath, rbytes);
sprintf(linkage, "%s:%s", serversock, clientsock);
sprintf(remote_display, "wayland-%s", rbytes);
if (!wayland_display) {
wayland_display = remote_display;
}
bool allocates_pty = false;
int dstidx = locate_openssh_cmd_hostname(
......@@ -532,13 +556,14 @@ int main(int argc, char **argv)
wp_log(WP_ERROR, "Fork failure");
return EXIT_FAILURE;
} else if (conn_pid == 0) {
int nextra = 10 + debug + oneshot +
int nextra = 12 + debug + oneshot +
2 * (remote_drm_node != NULL) +
2 * (config.compression != COMP_NONE) +
config.video_if_possible +
2 * needs_login_shell +
2 * (config.n_worker_threads != 0);
char **arglist = calloc(argc + nextra, sizeof(char *));
char **arglist = calloc((size_t)(argc + nextra),
sizeof(char *));
int offset = 0;
arglist[offset++] = "/usr/bin/ssh";
......@@ -589,6 +614,8 @@ int main(int argc, char **argv)
arglist[dstidx + 1 + offset++] = "--unlink-socket";
arglist[dstidx + 1 + offset++] = "-s";
arglist[dstidx + 1 + offset++] = serversock;
arglist[dstidx + 1 + offset++] = "--display";
arglist[dstidx + 1 + offset++] = wayland_display;
arglist[dstidx + 1 + offset++] = "server";
for (int i = dstidx + 1; i < argc; i++) {
arglist[offset + i] = argv[i];
......
......@@ -60,11 +60,11 @@ will be displayed locally.
*-v, --version*
Print the version number and quit.
*--unlink-socket*
Only for server mode; on shutdown, unlink the Unix socket that waypipe connects to.
*--login-shell*
Only for server mode; if no command is being run, open a login shell.
*--display D*
For server or ssh mode, provide _WAYLAND_DISPLAY_ and let waypipe configure
its Wayland display socket to have a matching path. (If *D* is not an
absolute path, the socket will be created in the folder given by the
environment variable _XDG_RUNTIME_DIR_.)
*--drm-node R*
Specify the path *R* to the drm device that this instance of waypipe should
......@@ -80,9 +80,8 @@ will be displayed locally.
DMABUF image layout modifiers which are very slow for waypipe to copy
and update; this flag can ensure that they fall back to friendlier formats.
*--video*
Compress specific DMABUF formats using a lossy video codec. Opaque, 10-bit, and
multiplanar formats, among others, are not supported.
*--login-shell*
Only for server mode; if no command is being run, open a login shell.
*--threads T*
Set the number of total threads (including the main thread) which a *waypipe*
......@@ -90,6 +89,13 @@ will be displayed locally.
operations. This flag is passed on to *waypipe server* when given to *waypipe
ssh*.
*--unlink-socket*
Only for server mode; on shutdown, unlink the Unix socket that waypipe connects to.
*--video*
Compress specific DMABUF formats using a lossy video codec. Opaque, 10-bit, and
multiplanar formats, among others, are not supported.
# EXAMPLE
The following *waypipe ssh* subcommand will attempt to run *weston-flower* on
......@@ -103,7 +109,7 @@ One can obtain similar behavior by explictly running waypipe and ssh:
```
waypipe --socket /tmp/socket-client client &
ssh -R/tmp/socket-server:/tmp/socket-client -t user@exserv \
ssh -R/tmp/socket-server:/tmp/socket-client user@exserv \
waypipe --socket /tmp/socket-server server -- weston-flower
kill %1
```
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment