@@ -16,7 +16,10 @@
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"
@@ -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
@@ -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)