Skip to contentSkip to conversation

libxl: allow building without O_CLOEXEC definition

PATCH New Jan Beulich 1 participant 1 message Jun 21, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl: allow building without O_CLOEXEC definition

tools/libxl/xl_cmdimpl.c +14 -0
@@ -199,11 +199,25 @@ static int acquire_lock(void)
     fl.l_whence = SEEK_SET;
     fl.l_start = 0;
     fl.l_len = 0;
+#ifndef O_CLOEXEC
+# define O_CLOEXEC 0
+#endif
     fd_lock = open(lockfile, O_WRONLY|O_CREAT|O_CLOEXEC, S_IWUSR);
     if (fd_lock < 0) {
         fprintf(stderr, "cannot open the lockfile %s errno=%d\n", lockfile, errno);
         return ERROR_FAIL;
     }
+#if !O_CLOEXEC
+    {
+        int flags = fcntl(fd_lock, F_GETFD);
+
+        if (flags < 0 ||
+            fcntl(fd_lock, F_SETFD, flags | FD_CLOEXEC) < 0)
+            fprintf(stderr,
+                    "cannot mark lockfile %s close-on-exec errno=%d\n",
+                    lockfile, errno);
+    }
+#endif
 get_lock:
     rc = fcntl(fd_lock, F_SETLKW, &fl);
     if (rc < 0 && errno == EINTR)
tools/libxl/xl_cmdimpl.c +14 -0
@@ -199,11 +199,25 @@ static int acquire_lock(void)
     fl.l_whence = SEEK_SET;
     fl.l_start = 0;
     fl.l_len = 0;
+#ifndef O_CLOEXEC
+# define O_CLOEXEC 0
+#endif
     fd_lock = open(lockfile, O_WRONLY|O_CREAT|O_CLOEXEC, S_IWUSR);
     if (fd_lock < 0) {
         fprintf(stderr, "cannot open the lockfile %s errno=%d\n", lockfile, errno);
         return ERROR_FAIL;
     }
+#if !O_CLOEXEC
+    {
+        int flags = fcntl(fd_lock, F_GETFD);
+
+        if (flags < 0 ||
+            fcntl(fd_lock, F_SETFD, flags | FD_CLOEXEC) < 0)
+            fprintf(stderr,
+                    "cannot mark lockfile %s close-on-exec errno=%d\n",
+                    lockfile, errno);
+    }
+#endif
 get_lock:
     rc = fcntl(fd_lock, F_SETLKW, &fl);
     if (rc < 0 && errno == EINTR)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel