Skip to content

Commit 95430f4

Browse files
committed
Set close-on-exec on files opened with Lwt_io.with_file
1 parent cb65dbc commit 95430f4

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

lib/build_log.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ let tail ?switch t dst =
2929
match t.state with
3030
| `Finished -> invalid_arg "tail: log is finished!"
3131
| `Readonly path ->
32-
Lwt_io.(with_file ~mode:input) path @@ fun ch ->
32+
let flags = [Unix.O_RDONLY; Unix.O_NONBLOCK; Unix.O_CLOEXEC] in
33+
Lwt_io.(with_file ~mode:input ~flags) path @@ fun ch ->
3334
let buf = Bytes.create max_chunk_size in
3435
let rec aux () =
3536
Lwt_io.read_into ch buf 0 max_chunk_size >>= function

lib/os.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ let rec write_all fd buf ofs len =
9090
)
9191

9292
let write_file ~path contents =
93-
Lwt_io.(with_file ~mode:output) path @@ fun ch ->
93+
let flags = [Unix.O_WRONLY; Unix.O_CREAT; Unix.O_TRUNC; Unix.O_NONBLOCK; Unix.O_CLOEXEC] in
94+
Lwt_io.(with_file ~mode:output ~flags) path @@ fun ch ->
9495
Lwt_io.write ch contents
9596

9697
let with_pipe_from_child fn =

lib/tar_transfer.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ let copy_file ~src ~dst ~to_untar ~user =
6565
dst stat.Lwt_unix.LargeFile.st_size
6666
in
6767
Tar_lwt_unix.write_block ~level hdr (fun ofd ->
68-
Lwt_io.(with_file ~mode:input) src (copy_to ~dst:ofd)
68+
let flags = [Unix.O_RDONLY; Unix.O_NONBLOCK; Unix.O_CLOEXEC] in
69+
Lwt_io.(with_file ~mode:input ~flags) src (copy_to ~dst:ofd)
6970
) to_untar
7071

7172
let copy_symlink ~src ~target ~dst ~to_untar ~user =

0 commit comments

Comments
 (0)