]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
lib/file: support POSIX O_CLOEXEC
authorOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:44 +0000 (11:23 -0700)
committerOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:44 +0000 (11:23 -0700)
On POSIX systems add support for O_CLOEXEC - close the file descriptor
if the program does a variant of the exec system call.

open-vm-tools/lib/file/fileIOPosix.c
open-vm-tools/lib/include/fileIO.h

index ee9f4b0028559079510f250ed354058f9d269ecf..5fb0e39cca78acc930add6236bd1cd42942bc4cf 100644 (file)
@@ -448,6 +448,12 @@ FileIO_CreateFDPosix(int posix,  // IN: UNIX file descriptor
       fd.flags |= FILEIO_OPEN_APPEND;
    }
 
+#if defined(__linux__) && defined(O_CLOEXEC)
+   if (flags & O_CLOEXEC) {
+      fd.flags |= FILEIO_OPEN_CLOSE_ON_EXEC;
+   }
+#endif
+
    fd.posix = posix;
 
    return fd;
@@ -917,6 +923,12 @@ FileIOCreateRetry(FileIODescriptor *file,   // OUT:
    }
 #endif
 
+#if defined(__linux__) && defined(O_CLOEXEC)
+   if (flags & FILEIO_OPEN_CLOSE_ON_EXEC) {
+      flags |= O_CLOEXEC;
+   }
+#endif
+
    flags |= FileIO_OpenActions[action];
 
    file->flags = access;
index 00e1d9eb34e975621da3c2c6ff21fa27498df767..91517872d9e746707662b7eb5966e70d11954c85 100644 (file)
@@ -202,22 +202,29 @@ typedef enum {
  */
 #define FILEIO_OPEN_OPTIMISTIC_LOCK   (1 << 22)
 
+// Flag passed to open() to enable use of oplocks on VMFS.  This definition
+// must match USEROBJ_OPEN_OPTIMISTIC_LOCK in user_vsiTypes.h.
+#define O_OPTIMISTIC_LOCK             (1 << 22)  // 0x00400000
+
+/*
+ * POSIX specific close the file descriptor when the program uses a variant
+ * of the exec system call capability. This is useful in fork/exec scenarios.
+ */
+#define FILEIO_OPEN_CLOSE_ON_EXEC     (1 << 23)
+
 /*
- * Flag passed to open() to not attempt to get the lun attributes as part of
+ * Flag passed to open() to not attempt to get the LUN attributes as part of
  * the open operation. Applicable only to opening of SCSI devices. This
  * definition must match the definition of USEROBJ_OPEN_NOATTR in
  * user_vsiTypes.h and FS_OPEN_NOATTR in fs_public.h
  */
-#define O_NOATTR 0x04000000
+#define O_NOATTR                      (1 << 26)  // 0x04000000
 // Flag passed to open() to get multiwriter VMFS lock.  This definition must
 // match USEROBJ_OPEN_MULTIWRITER_LOCK in user_vsiTypes.h.
-#define O_MULTIWRITER_LOCK 0x08000000
+#define O_MULTIWRITER_LOCK            (1 << 27)  //0x08000000
 // Flag passed to open() to get exclusive VMFS lock.  This definition must
 // match USEROBJ_OPEN_EXCLUSIVE_LOCK in user_vsiTypes.h.
-#define O_EXCLUSIVE_LOCK 0x10000000
-// Flag passed to open() to enable use of oplocks on VMFS.  This definition
-// must match USEROBJ_OPEN_OPTIMISTIC_LOCK in user_vsiTypes.h.
-#define O_OPTIMISTIC_LOCK 0x00400000
+#define O_EXCLUSIVE_LOCK              (1 << 28)  // 0x10000000
 
 /* File Access check args */
 #define FILEIO_ACCESS_READ       (1 << 0)