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,7 +110,14 @@ int utf8_open (const char *filename, int flags, mode_t mode) ...@@ -110,7 +110,14 @@ int utf8_open (const char *filename, int flags, mode_t mode)
return -1; return -1;
} }
int fd = open (local_name, flags, mode); int fd;
#ifdef O_CLOEXEC
fd = open (local_name, flags | O_CLOEXEC, mode);
if (fd == -1 && errno == EINVAL)
#endif
{
fd = open (local_name, flags, mode);
#ifdef HAVE_FCNTL #ifdef HAVE_FCNTL
if (fd != -1) if (fd != -1)
{ {
...@@ -118,6 +125,8 @@ int utf8_open (const char *filename, int flags, mode_t mode) ...@@ -118,6 +125,8 @@ int utf8_open (const char *filename, int flags, mode_t mode)
fcntl (fd, F_SETFD, FD_CLOEXEC | ((flags != -1) ? flags : 0)); fcntl (fd, F_SETFD, FD_CLOEXEC | ((flags != -1) ? flags : 0));
} }
#endif #endif
}
LocaleFree (local_name); LocaleFree (local_name);
return fd; 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