[PATCH wayland 3/4] wayland-server: use wl_get_runtime_dir()

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


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

diff --git a/src/wayland-server.c b/src/wayland-server.c
index 2f3ddc9..816cbf1 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -1279,24 +1279,23 @@ wl_display_add_socket(struct wl_display *display, const char *name)
 	struct wl_socket *s;
 	socklen_t size;
 	int name_size;
-	const char *runtime_dir;
+	char *runtime_dir;
 
-	runtime_dir = getenv("XDG_RUNTIME_DIR");
+	runtime_dir = wl_get_runtime_dir();
 	if (!runtime_dir) {
-		wl_log("error: XDG_RUNTIME_DIR not set in the environment\n");
-
-		/* to prevent programs reporting
-		 * "failed to add socket: Success" */
-		errno = ENOENT;
+		wl_log("warning: Couldn't determine runtime dir\n");
 		return -1;
 	}
 
 	s = malloc(sizeof *s);
-	if (s == NULL)
+	if (s == NULL) {
+		free(runtime_dir);
 		return -1;
+	}
 
 	s->fd = wl_os_socket_cloexec(PF_LOCAL, SOCK_STREAM, 0);
 	if (s->fd < 0) {
+		free(runtime_dir);
 		free(s);
 		return -1;
 	}
@@ -1308,6 +1307,7 @@ wl_display_add_socket(struct wl_display *display, const char *name)
 
 	memset(&s->addr, 0, sizeof s->addr);
 	s->addr.sun_family = AF_LOCAL;
+
 	name_size = snprintf(s->addr.sun_path, sizeof s->addr.sun_path,
 			     "%s/%s", runtime_dir, name) + 1;
 
@@ -1316,6 +1316,7 @@ wl_display_add_socket(struct wl_display *display, const char *name)
 		wl_log("error: socket path \"%s/%s\" plus null terminator"
 		       " exceeds 108 bytes\n", runtime_dir, name);
 		close(s->fd);
+		free(runtime_dir);
 		free(s);
 		/* to prevent programs reporting
 		 * "failed to add socket: Success" */
@@ -1323,6 +1324,8 @@ wl_display_add_socket(struct wl_display *display, const char *name)
 		return -1;
 	};
 
+	free(runtime_dir);
+
 	wl_log("using socket %s\n", s->addr.sun_path);
 
 	s->fd_lock = get_socket_lock(s);
-- 
1.7.10.4



More information about the wayland-devel mailing list