From 51967594bc6fe5336e3ac85822d495752306dee5 Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Fri, 18 Oct 2019 11:05:47 +0000 Subject: [PATCH] common: add platform checks O_CLOEXEC is not available on Windows. Subprocesses do not inherit handles unless explicitly requested when creating the handle. That being considered, we'll avoid setting this flag on Windows. The zfs check will also be skipped for now. Signed-off-by: Lucian Petrut --- src/common/compat.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/common/compat.cc b/src/common/compat.cc index a8d57bd7758..c039ae9bb2f 100644 --- a/src/common/compat.cc +++ b/src/common/compat.cc @@ -19,7 +19,9 @@ #include #include #include +#ifndef _WIN32 #include +#endif #include #include #include @@ -63,9 +65,13 @@ int manual_fallocate(int fd, off_t offset, off_t len) { } int on_zfs(int basedir_fd) { + #ifndef _WIN32 struct statfs basefs; (void)fstatfs(basedir_fd, &basefs); return (basefs.f_type == FS_ZFS_TYPE); + #else + return 0; + #endif } int ceph_posix_fallocate(int fd, off_t offset, off_t len) { @@ -102,6 +108,7 @@ int pipe_cloexec(int pipefd[2], int flags) if (pipe(pipefd) == -1) return -1; + #ifndef _WIN32 /* * The old-fashioned, race-condition prone way that we have to fall * back on if pipe2 does not exist. @@ -113,6 +120,7 @@ int pipe_cloexec(int pipefd[2], int flags) if (fcntl(pipefd[1], F_SETFD, FD_CLOEXEC) < 0) { goto fail; } + #endif return 0; fail: @@ -133,8 +141,10 @@ int socket_cloexec(int domain, int type, int protocol) if (fd == -1) return -1; + #ifndef _WIN32 if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) goto fail; + #endif return fd; fail: @@ -156,11 +166,13 @@ int socketpair_cloexec(int domain, int type, int protocol, int sv[2]) if (rc == -1) return -1; + #ifndef _WIN32 if (fcntl(sv[0], F_SETFD, FD_CLOEXEC) < 0) goto fail; if (fcntl(sv[1], F_SETFD, FD_CLOEXEC) < 0) goto fail; + #endif return 0; fail: @@ -180,8 +192,10 @@ int accept_cloexec(int sockfd, struct sockaddr* addr, socklen_t* addrlen) if (fd == -1) return -1; + #ifndef _WIN32 if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) goto fail; + #endif return fd; fail: -- 2.39.5