libxl: Introduce libxl__fd_set_cloexec
authorAnthony PERARD <anthony.perard@citrix.com>
Thu, 29 Sep 2011 15:06:02 +0000 (16:06 +0100)
committerAnthony PERARD <anthony.perard@citrix.com>
Thu, 29 Sep 2011 15:06:02 +0000 (16:06 +0100)
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/libxl_internal.c
tools/libxl/libxl_internal.h

index e2592789ce0d583bb1e676de3eb59e4ce8602f5d..8f4678020f37af4d5c6c90de7ef78185a2f43acb 100644 (file)
@@ -242,3 +242,16 @@ int libxl__file_reference_unmap(libxl_file_reference *f)
 
        return ERROR_FAIL;
 }
+
+int libxl__fd_set_cloexec(int fd)
+{
+    int flags = 0;
+
+    if ((flags = fcntl(fd, F_GETFD)) == -1) {
+        flags = 0;
+    }
+    if ((flags & FD_CLOEXEC)) {
+        return 0;
+    }
+    return fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
+}
index b4316321031ed9bc48b39dfa80081d84650e4b8b..1f78f9676ad555d4459c4e8f0fb69e0523354340 100644 (file)
@@ -384,6 +384,7 @@ _hidden int libxl__error_set(libxl__gc *gc, int code);
 
 _hidden int libxl__file_reference_map(libxl_file_reference *f);
 _hidden int libxl__file_reference_unmap(libxl_file_reference *f);
+_hidden int libxl__fd_set_cloexec(int fd);
 
 _hidden int libxl__e820_alloc(libxl_ctx *ctx, uint32_t domid, libxl_domain_config *d_config);