compositor: Use dup instead of fcntl to get a non-CLOEXEC fd
One less syscall and error path to check, and feels like a cleaner approach. The commit adds two lines, but that's because we actually handle the potential error now.
This commit is contained in:
@@ -88,7 +88,7 @@ wlsc_watch_process(struct wlsc_process *process)
|
|||||||
static void
|
static void
|
||||||
child_client_exec(int sockfd, const char *path)
|
child_client_exec(int sockfd, const char *path)
|
||||||
{
|
{
|
||||||
int flags;
|
int clientfd;
|
||||||
char s[32];
|
char s[32];
|
||||||
sigset_t allsigs;
|
sigset_t allsigs;
|
||||||
|
|
||||||
@@ -96,13 +96,15 @@ child_client_exec(int sockfd, const char *path)
|
|||||||
sigfillset(&allsigs);
|
sigfillset(&allsigs);
|
||||||
sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
|
sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
|
||||||
|
|
||||||
/* SOCK_CLOEXEC closes both ends, so we need to unset
|
/* SOCK_CLOEXEC closes both ends, so we dup the fd to get a
|
||||||
* the flag on the client fd. */
|
* non-CLOEXEC fd to pass through exec. */
|
||||||
flags = fcntl(sockfd, F_GETFD);
|
clientfd = dup(sockfd);
|
||||||
if (flags != -1)
|
if (clientfd == -1) {
|
||||||
fcntl(sockfd, F_SETFD, flags & ~FD_CLOEXEC);
|
fprintf(stderr, "compositor: dup failed: %m\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
snprintf(s, sizeof s, "%d", sockfd);
|
snprintf(s, sizeof s, "%d", clientfd);
|
||||||
setenv("WAYLAND_SOCKET", s, 1);
|
setenv("WAYLAND_SOCKET", s, 1);
|
||||||
|
|
||||||
if (execl(path, path, NULL) < 0)
|
if (execl(path, path, NULL) < 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user