tools/ocaml/libs/xs/xs.ml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
... 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@citrix.com>
---
CC: Andrii Sultanov <andriy.sultanov@vates.tech>
CC: Guillaume Thouvenin <guillaume.thouvenin@vates.tech>
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
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@citrix.com> > --- > CC: Andrii Sultanov <andriy.sultanov@vates.tech> > CC: Guillaume Thouvenin <guillaume.thouvenin@vates.tech> > > 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@vates.tech>
On 26/10/2026 2:18 pm, Andrii Sultanov wrote: > 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@citrix.com> >> --- >> CC: Andrii Sultanov <andriy.sultanov@vates.tech> >> CC: Guillaume Thouvenin <guillaume.thouvenin@vates.tech> >> >> 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. Agreed, but it's still better to have code be correct, in case anyone else is using it. Independently, we should see about pruning the libraries which aren't used. Sadly, they're all mutually entangled. > > 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@vates.tech> > Thanks. ~Andrew
© 2016 - 2026 Red Hat, Inc.