[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] tools/ocaml/libs/xs: Create FDs with the correct CLOEXEC status



... rather than editing them after the fact.

This capability exists from Ocaml 4.05 which is also our minimum supported
version.

Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Andrii Sultanov <andriy.sultanov@xxxxxxxxxx>
CC: Guillaume Thouvenin <guillaume.thouvenin@xxxxxxxxxx>

Found while reviewing the other FD handling patch.
---
 tools/ocaml/libs/xs/xs.ml | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/tools/ocaml/libs/xs/xs.ml b/tools/ocaml/libs/xs/xs.ml
index addccc80099b..a088d67a8cb6 100644
--- a/tools/ocaml/libs/xs/xs.ml
+++ b/tools/ocaml/libs/xs/xs.ml
@@ -155,9 +155,8 @@ exception Failed_to_connect
 let daemon_open () =
   try
     let sockaddr = Unix.ADDR_UNIX(daemon_socket) in
-    let sock = Unix.socket Unix.PF_UNIX Unix.SOCK_STREAM 0 in
+    let sock = Unix.socket ~cloexec:true Unix.PF_UNIX Unix.SOCK_STREAM 0 in
     Unix.connect sock sockaddr;
-    Unix.set_close_on_exec sock;
     make sock
   with _ -> raise Failed_to_connect
 
@@ -169,8 +168,7 @@ let domain_open () =
     with Unix.Unix_error(_, _, _) ->
       "/proc/xen/xenbus" in
 
-  let fd = Unix.openfile path [ Unix.O_RDWR ] 0o550 in
-  Unix.set_close_on_exec fd;
+  let fd = Unix.openfile path [ Unix.O_RDWR; Unix.O_CLOEXEC ] 0o550 in
   make fd
 
 let close xsh = Xsraw.close xsh.con

base-commit: 0d3bb3c98bc99ec1c84ebb3df71b6e18daebff4f
-- 
2.39.5




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.