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

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


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrii Sultanov <andriy.sultanov@xxxxxxxxxx>
  • Date: Mon, 26 Oct 2026 14:18:28 +0000
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=vates.tech header.i="@vates.tech" header.h="From:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding:In-Reply-To:References:Feedback-ID"
  • Cc: Guillaume Thouvenin <guillaume.thouvenin@xxxxxxxxxx>, Andrew Mbugua <andrewprecious388@xxxxxxxxx>
  • Delivery-date: Mon, 26 Oct 2026 14:18:52 +0000
  • Feedback-id: default:8631fc262581453bbf619ec5b2062170:Sweego
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 10/12/26 21:19, Andrew Cooper wrote:

... 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
The change on its own is fine - there's no functional impact. But as far as I can tell, these functions are not used anywhere (they haven't been used in xapi
in a long time), so there's limited utility in this cleanup.

Regarding your question from the original thread, if this patch was intended
as an answer to it:

> Where do these sockets come from?  What flags where they opened with?

The sockets that are dumped come from xenstored.ml:process_special_fds:

      let (cfd, _addr) = Unix.accept fd in

The default is keep-on-exec, so there shouldn't be any need to call
Unix.clear_close_on_exec in the patches suggested by Andrew Mbugua.

Acked-by: Andrii Sultanov <andriy.sultanov@xxxxxxxxxx>




 


Rackspace

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