1From a7a04fa20e36b9d0975797168f3a7189b4d0e9ea Mon Sep 17 00:00:00 2001
2From: Jeffy Chen <jeffy.chen@rock-chips.com>
3Date: Tue, 18 Jul 2023 10:33:55 +0800
4Subject: [PATCH 2/2] wayland-client: Support waiting for socket when
5 connecting
6
7Set WAYLAND_WAIT=1 to enable it.
8
9Tested on RK3588 EVB with:
101/ Run "weston-terminal&"
112/ Run "WAYLAND_WAIT=1 weston&"
12
13Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
14---
15 src/wayland-client.c | 9 ++++++++-
16 1 file changed, 8 insertions(+), 1 deletion(-)
17
18diff --git a/src/wayland-client.c b/src/wayland-client.c
19index 90fb9c7..ce7b385 100644
20--- a/src/wayland-client.c
21+++ b/src/wayland-client.c
22@@ -1067,6 +1067,7 @@ connect_to_socket(const char *name)
23 	const char *runtime_dir;
24 	int name_size, fd;
25 	bool path_is_absolute;
26+	int i;
27
28 	if (name == NULL)
29 		name = getenv("WAYLAND_DISPLAY");
30@@ -1119,7 +1120,13 @@ connect_to_socket(const char *name)
31
32 	size = offsetof (struct sockaddr_un, sun_path) + name_size;
33
34-	if (connect(fd, (struct sockaddr *) &addr, size) < 0) {
35+	i = 500;
36+	while (connect(fd, (struct sockaddr *) &addr, size) < 0) {
37+		if (getenv("WAYLAND_WAIT") && i--) {
38+			usleep(10000);
39+			continue;
40+		}
41+
42 		close(fd);
43 		return -1;
44 	}
45--
462.20.1
47
48