From de13448c9260d58795ca7cd10e6045212940c9b2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristian=20H=C3=B8gsberg?= Date: Sun, 15 Jan 2012 16:05:28 -0500 Subject: [PATCH] xserver: Just dup fd instead of two fcntls to get a non-O_CLOEXEC fd Yeah, it's the same number of lines of code, but this actually checks the error return. --- src/xserver-launcher.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/xserver-launcher.c b/src/xserver-launcher.c index c7b8e98..9d00c41 100644 --- a/src/xserver-launcher.c +++ b/src/xserver-launcher.c @@ -1296,7 +1296,7 @@ weston_xserver_handle_event(int listen_fd, uint32_t mask, void *data) { struct weston_xserver *mxs = data; char display[8], s[8]; - int sv[2], flags; + int sv[2], client_fd; if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sv) < 0) { fprintf(stderr, "socketpair failed\n"); @@ -1308,11 +1308,11 @@ weston_xserver_handle_event(int listen_fd, uint32_t mask, void *data) case 0: /* SOCK_CLOEXEC closes both ends, so we need to unset * the flag on the client fd. */ - flags = fcntl(sv[1], F_GETFD); - if (flags != -1) - fcntl(sv[1], F_SETFD, flags & ~FD_CLOEXEC); + client_fd = dup(sv[1]); + if (client_fd < 0) + return 1; - snprintf(s, sizeof s, "%d", sv[1]); + snprintf(s, sizeof s, "%d", client_fd); setenv("WAYLAND_SOCKET", s, 1); snprintf(display, sizeof display, ":%d", mxs->display); -- 2.7.4