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:
parent
1760ebb236
commit
de13448c92
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user