]> xenbits.xensource.com Git - people/tklengyel/xen.git/commitdiff
tools/ocaml/evtchn: Extend the init() binding with a cloexec flag
authorEdwin Török <edvin.torok@citrix.com>
Thu, 3 Nov 2022 14:50:38 +0000 (14:50 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 20 Dec 2022 13:13:40 +0000 (13:13 +0000)
For live update, oxenstored wants to clear CLOEXEC on the evtchn handle, so it
survives the execve() into the new oxenstored.

Have the new interface match how cloexec works in other Ocaml standard
libraries.

Signed-off-by: Edwin Török <edvin.torok@citrix.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Christian Lindig <christian.lindig@citrix.com>
(cherry picked from commit 9bafe4a53306e7aa2ce6ffc96f7477c6f329f7a7)

tools/ocaml/libs/eventchn/xeneventchn.ml
tools/ocaml/libs/eventchn/xeneventchn.mli
tools/ocaml/libs/eventchn/xeneventchn_stubs.c

index be4de82f46b992e55f362d7572ff6e6595c2487f..c16fdd4674f7e9fd007dcb1c3f18cd4095e9f6fd 100644 (file)
 
 type handle
 
-external init: unit -> handle = "stub_eventchn_init"
+external _init: bool -> handle = "stub_eventchn_init"
+
+let init ?(cloexec=true) () = _init cloexec
+
 external fdopen: Unix.file_descr -> handle = "stub_eventchn_fdopen"
 external fd: handle -> Unix.file_descr = "stub_eventchn_fd"
 
index 98b3c86f3702684f4a25153d76d91b9d13aa10ea..870429b6b53aaa68e7f772d373a6fb3aafb87d78 100644 (file)
@@ -43,9 +43,12 @@ val to_int: t -> int
 
 val of_int: int -> t
 
-val init: unit -> handle
-(** Return an initialised event channel interface. On error it
-    will throw a Failure exception. *)
+val init: ?cloexec:bool -> unit -> handle
+(** [init ?cloexec ()]
+    Return an initialised event channel interface.
+    The default is to close the underlying file descriptor
+    on [execve], which can be overriden with [~cloexec:false].
+    On error it will throw a Failure exception. *)
 
 val fdopen: Unix.file_descr -> handle
 (** Return an initialised event channel interface, from an already open evtchn
index 7bdf711bc150694ba4c405e70ec9c7db96f06d7b..aa8a69cc1ecb5813d4c28ece59f60df1a9088db3 100644 (file)
@@ -50,14 +50,18 @@ static struct custom_operations xenevtchn_ops = {
        .compare_ext = custom_compare_ext_default, /* Can't compare     */
 };
 
-CAMLprim value stub_eventchn_init(void)
+CAMLprim value stub_eventchn_init(value cloexec)
 {
-       CAMLparam0();
+       CAMLparam1(cloexec);
        CAMLlocal1(result);
        xenevtchn_handle *xce;
+       unsigned int flags = 0;
+
+       if ( !Bool_val(cloexec) )
+               flags |= XENEVTCHN_NO_CLOEXEC;
 
        caml_enter_blocking_section();
-       xce = xenevtchn_open(NULL, 0);
+       xce = xenevtchn_open(NULL, flags);
        caml_leave_blocking_section();
 
        if (xce == NULL)