From eca1c53a42af292844359cfaea23c6739e783f1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonin=20D=C3=A9cimo?= Date: Mon, 6 Dec 2021 15:45:33 +0100 Subject: [PATCH] Add ?cloexec parameter to Lwt_io.pipe See also #872, #901. --- CHANGES | 4 ++++ src/unix/lwt_io.ml | 4 ++-- src/unix/lwt_io.mli | 5 +++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index e561bac97..f57e5ca13 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,9 @@ ===== dev ===== +====== Additions ====== + + * In the Lwt_io module, add `?cloexec:bool` optional arguments to functions that create file descriptors (`pipe`). The `?cloexec` argument is simply forwarded to the wrapped Lwt_unix function. (#872, #911, Antonin Décimo) + ====== Fixes ====== * Fix win32_spawn leaking dev_null fd in the parent process. (#906, Antonin Décimo) diff --git a/src/unix/lwt_io.ml b/src/unix/lwt_io.ml index 5bb2e258c..22dcd40a8 100644 --- a/src/unix/lwt_io.ml +++ b/src/unix/lwt_io.ml @@ -1367,8 +1367,8 @@ let eprintl txt = write_line stderr txt let eprintf fmt = Printf.ksprintf eprint fmt let eprintlf fmt = Printf.ksprintf eprintl fmt -let pipe ?in_buffer ?out_buffer _ = - let fd_r, fd_w = Lwt_unix.pipe () in +let pipe ?cloexec ?in_buffer ?out_buffer _ = + let fd_r, fd_w = Lwt_unix.pipe ?cloexec () in (of_fd ?buffer:in_buffer ~mode:input fd_r, of_fd ?buffer:out_buffer ~mode:output fd_w) diff --git a/src/unix/lwt_io.mli b/src/unix/lwt_io.mli index 030b6482c..7a2fcffcf 100644 --- a/src/unix/lwt_io.mli +++ b/src/unix/lwt_io.mli @@ -86,9 +86,10 @@ val null : output_channel (** {2 Channels creation/manipulation} *) -val pipe : ?in_buffer : Lwt_bytes.t -> ?out_buffer : Lwt_bytes.t -> unit -> +val pipe : ?cloexec : bool -> + ?in_buffer : Lwt_bytes.t -> ?out_buffer : Lwt_bytes.t -> unit -> input_channel * output_channel - (** [pipe ?in_buffer ?out_buffer ()] creates a pipe using + (** [pipe ?cloexec ?in_buffer ?out_buffer ()] creates a pipe using {!Lwt_unix.pipe} and makes two channels from the two returned file descriptors *)