From: Kristian Høgsberg Date: Sun, 15 Jan 2012 21:05:28 +0000 (-0500) Subject: xserver: Just dup fd instead of two fcntls to get a non-O_CLOEXEC fd X-Git-Tag: 0.85.0~65 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=de13448c9260d58795ca7cd10e6045212940c9b2;p=profile%2Fivi%2Fweston.git 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. --- 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);