xserver: Just dup fd instead of two fcntls to get a non-O_CLOEXEC fd
authorKristian Høgsberg <krh@bitplanet.net>
Sun, 15 Jan 2012 21:05:28 +0000 (16:05 -0500)
committerKristian Høgsberg <krh@bitplanet.net>
Sun, 15 Jan 2012 21:05:43 +0000 (16:05 -0500)
Yeah, it's the same number of lines of code, but this actually checks
the error return.

src/xserver-launcher.c

index c7b8e98..9d00c41 100644 (file)
@@ -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);