CHECK_SYMBOL_EXISTS(I_SETSIG "sys/types.h;sys/ioctl.h" HAVE_SETSIG)
CHECK_SYMBOL_EXISTS(O_ASYNC "sys/types.h;sys/fcntl.h" HAVE_OASYNC)
CHECK_SYMBOL_EXISTS(O_NOFOLLOW "sys/types.h;sys/fcntl.h" HAVE_ONOFOLLOW)
+CHECK_SYMBOL_EXISTS(O_CLOEXEC "sys/types.h;sys/fcntl.h" HAVE_OCLOEXEC)
LIST(APPEND CMAKE_REQUIRED_INCLUDES "${LIBSSL_INCLUDE}")
CHECK_SYMBOL_EXISTS(SSL_set_tlsext_host_name "openssl/ssl.h" HAVE_SSL_TLSEXT_HOSTNAME)
CHECK_SYMBOL_EXISTS(dirfd "sys/types.h;unistd.h;dirent.h" HAVE_DIRFD)
gboolean allow_symlink)
{
struct stat sb;
- int fd;
+ int fd, flags = oflags;
if (lstat (fname, &sb) == -1) {
}
}
else if (!S_ISREG (sb.st_mode)) {
- return -1;
+ if (S_ISLNK (sb.st_mode)) {
+ if (!allow_symlink) {
+ return -1;
+ }
+ }
+ else {
+ return -1;
+ }
}
+#ifdef HAVE_OCLOEXEC
+ flags |= O_CLOEXEC;
+#endif
+
#ifdef HAVE_ONOFOLLOW
if (!allow_symlink) {
- fd = open (fname, oflags | O_NOFOLLOW, mode);
+ flags |= O_NOFOLLOW;
+ fd = open (fname, flags, mode);
}
else {
- fd = open (fname, oflags, mode);
+ fd = open (fname, flags, mode);
}
#else
- fd = open (fname, oflags, mode);
+ fd = open (fname, flags, mode);
+#endif
+
+#ifndef HAVE_OCLOEXEC
+ if (fcntl (fd, F_SETFD, FD_CLOEXEC) == -1) {
+ msg_warn ("fcntl failed: %d, '%s'", errno, strerror (errno));
+ close (fd);
+
+ return -1;
+ }
#endif
return (fd);