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.
This commit is contained in:
@@ -1296,7 +1296,7 @@ weston_xserver_handle_event(int listen_fd, uint32_t mask, void *data)
|
|||||||
{
|
{
|
||||||
struct weston_xserver *mxs = data;
|
struct weston_xserver *mxs = data;
|
||||||
char display[8], s[8];
|
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) {
|
if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sv) < 0) {
|
||||||
fprintf(stderr, "socketpair failed\n");
|
fprintf(stderr, "socketpair failed\n");
|
||||||
@@ -1308,11 +1308,11 @@ weston_xserver_handle_event(int listen_fd, uint32_t mask, void *data)
|
|||||||
case 0:
|
case 0:
|
||||||
/* SOCK_CLOEXEC closes both ends, so we need to unset
|
/* SOCK_CLOEXEC closes both ends, so we need to unset
|
||||||
* the flag on the client fd. */
|
* the flag on the client fd. */
|
||||||
flags = fcntl(sv[1], F_GETFD);
|
client_fd = dup(sv[1]);
|
||||||
if (flags != -1)
|
if (client_fd < 0)
|
||||||
fcntl(sv[1], F_SETFD, flags & ~FD_CLOEXEC);
|
return 1;
|
||||||
|
|
||||||
snprintf(s, sizeof s, "%d", sv[1]);
|
snprintf(s, sizeof s, "%d", client_fd);
|
||||||
setenv("WAYLAND_SOCKET", s, 1);
|
setenv("WAYLAND_SOCKET", s, 1);
|
||||||
|
|
||||||
snprintf(display, sizeof display, ":%d", mxs->display);
|
snprintf(display, sizeof display, ":%d", mxs->display);
|
||||||
|
|||||||
Reference in New Issue
Block a user