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) ...@@ -110,14 +110,23 @@ 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 HAVE_FCNTL
if (fd != -1) #ifdef O_CLOEXEC
fd = open (local_name, flags | O_CLOEXEC, mode);
if (fd == -1 && errno == EINVAL)
#endif
{ {
int flags = fcntl (fd, F_GETFD); fd = open (local_name, flags, mode);
fcntl (fd, F_SETFD, FD_CLOEXEC | ((flags != -1) ? flags : 0)); #ifdef HAVE_FCNTL
} if (fd != -1)
{
int flags = fcntl (fd, F_GETFD);
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