Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FD_CLOEXEC not set for all systems #273

Closed
rittneje opened this issue Jul 24, 2021 · 0 comments · Fixed by #275
Closed

FD_CLOEXEC not set for all systems #273

rittneje opened this issue Jul 24, 2021 · 0 comments · Fixed by #275

Comments

@rittneje
Copy link
Contributor

rittneje commented Jul 24, 2021

Currently this library only opens the database file with close-on-exec set if the kernel supports O_CLOEXEC (namely, modern versions of Linux).

#ifdef O_CLOEXEC
flags |= O_CLOEXEC;
#endif
int fd = open(mmdb->filename, flags);

However, some Unix systems, such as macos, do not support O_CLOEXEC. In such cases, this library needs to fall back to setting the flag via fcntl. While not as airtight as the atomic syscall in a multithreaded program, it is better than nothing.

Something like this should work.

#ifdef FD_CLOEXEC
int flags = fcntl(fd, F_GETFD);
if (flags >= 0) {
    fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant