Commit 9f59c674 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

utf8_open: set the close-on-exec descriptor flag

This departs from utf8_open() being a pure open() + Unicode function.
We should really always set the flag anyway, so lets factor the code.
There is still a tiny race between open() and the second fcntl() system
call, but it cannot quite be fixed within the current POSIX standards.

By the way, the correct way to clear the flag would be _after_ fork(),
but I am not aware of any such case involving utf8_open() in the
current tree.
parent 6ce34a21
......@@ -111,6 +111,13 @@ int utf8_open (const char *filename, int flags, mode_t mode)
}
int 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