Commit 825731a1 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Linux: (try to) set close-on-exec in open() system call

This Linux-specific extension fixes the close-on-exec race.
parent 71aa05ad
......@@ -110,14 +110,23 @@ int utf8_open (const char *filename, int flags, mode_t mode)
return -1;
}
int fd = open (local_name, flags, mode);
#ifdef HAVE_FCNTL
if (fd != -1)
int fd;
#ifdef O_CLOEXEC
fd = open (local_name, flags | O_CLOEXEC, mode);
if (fd == -1 && errno == EINVAL)
#endif
{
int flags = fcntl (fd, F_GETFD);
fcntl (fd, F_SETFD, FD_CLOEXEC | ((flags != -1) ? flags : 0));
}
fd = open (local_name, flags, mode);
#ifdef HAVE_FCNTL
if (fd != -1)
{
int flags = fcntl (fd, F_GETFD);
fcntl (fd, F_SETFD, FD_CLOEXEC | ((flags != -1) ? flags : 0));
}
#endif
}
LocaleFree (local_name);
return fd;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment