[PATCH wayland 2/4] wayland-client: use wl_get_runtime_dir()

Emilio Pozuelo Monfort pochu27 at gmail.com
Mon Mar 11 09:10:55 PDT 2013


https://bugs.freedesktop.org/show_bug.cgi?id=62092
---
 src/wayland-client.c |   17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/wayland-client.c b/src/wayland-client.c
index 74e4657..ba88e5c 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -433,17 +433,13 @@ connect_to_socket(const char *name)
 {
 	struct sockaddr_un addr;
 	socklen_t size;
-	const char *runtime_dir;
+	char *runtime_dir;
 	int name_size, fd;
 
-	runtime_dir = getenv("XDG_RUNTIME_DIR");
+	runtime_dir = wl_get_runtime_dir();
 	if (!runtime_dir) {
 		fprintf(stderr,
-			"error: XDG_RUNTIME_DIR not set in the environment.\n");
-
-		/* to prevent programs reporting
-		 * "failed to create display: Success" */
-		errno = ENOENT;
+			"error: Could not determine the runtime directory.\n");
 		return -1;
 	}
 
@@ -453,8 +449,10 @@ connect_to_socket(const char *name)
 		name = "wayland-0";
 
 	fd = wl_os_socket_cloexec(PF_LOCAL, SOCK_STREAM, 0);
-	if (fd < 0)
+	if (fd < 0) {
+		free(runtime_dir);
 		return -1;
+	}
 
 	memset(&addr, 0, sizeof addr);
 	addr.sun_family = AF_LOCAL;
@@ -467,6 +465,7 @@ connect_to_socket(const char *name)
 		fprintf(stderr,
 		       "error: socket path \"%s/%s\" plus null terminator"
 		       " exceeds 108 bytes\n", runtime_dir, name);
+		free(runtime_dir);
 		close(fd);
 		/* to prevent programs reporting
 		 * "failed to add socket: Success" */
@@ -474,6 +473,8 @@ connect_to_socket(const char *name)
 		return -1;
 	};
 
+	free(runtime_dir);
+
 	size = offsetof (struct sockaddr_un, sun_path) + name_size;
 
 	if (connect(fd, (struct sockaddr *) &addr, size) < 0) {
-- 
1.7.10.4



More information about the wayland-devel mailing list