Skip to content

Commit

Permalink
Use FD.use_exn API for processes
Browse files Browse the repository at this point in the history
  • Loading branch information
patricoferris committed Mar 1, 2023
1 parent 066e666 commit 67e3ae5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 19 deletions.
2 changes: 0 additions & 2 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
(mdx (and (>= 1.10.0) :with-test))
(logs (>= 0.7.0))
(fmt (>= 0.8.9))
(spawn (>= v0.15.1))
(cmdliner (and (>= 1.1.0) :with-test))
(uring (>= 0.5))))
(package
Expand All @@ -50,7 +49,6 @@
(eio (= :version))
(luv (>= 0.5.11))
(luv_unix (>= 0.5.0))
(spawn (>= v0.15.1)) ; unnecessary dependency in order to have eio_unix available.
(mdx (and (>= 1.10.0) :with-test))
(fmt (>= 0.8.9))))
(package
Expand Down
1 change: 0 additions & 1 deletion eio_linux.opam
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ depends: [
"mdx" {>= "1.10.0" & with-test}
"logs" {>= "0.7.0"}
"fmt" {>= "0.8.9"}
"spawn" {>= "v0.15.1"}
"cmdliner" {>= "1.1.0" & with-test}
"uring" {>= "0.5"}
"odoc" {with-doc}
Expand Down
1 change: 0 additions & 1 deletion eio_luv.opam
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ depends: [
"eio" {= version}
"luv" {>= "0.5.11"}
"luv_unix" {>= "0.5.0"}
"spawn" {>= "v0.15.1"}
"mdx" {>= "1.10.0" & with-test}
"fmt" {>= "0.8.9"}
"odoc" {with-doc}
Expand Down
20 changes: 12 additions & 8 deletions lib_eio_linux/eio_linux.ml
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ module Low_level = struct
t.status <- Some p;
await_readable t.process;
Switch.remove_hook t.hook;
let status = pidfd_wait (FD.to_unix `Peek t.process) in
let status = FD.use_exn "wait" t.process pidfd_wait in
Promise.resolve r status;
status

Expand All @@ -975,13 +975,17 @@ module Low_level = struct
| Some prog -> prog
| None -> raise (Eio.Fs.err (Eio.Fs.Not_found (Eio_unix.Unix_error (Unix.ENOENT, "", ""))))
in
let stdin = FD.to_unix `Peek stdin in
let stdout = FD.to_unix `Peek stdout in
let stderr = FD.to_unix `Peek stderr in
let cwd : Cwd.internal = match cwd with
| Cwd.Path p -> Cwd.Path (snd p)
| Cwd.Fd fd -> Cwd.Fd (FD.to_unix `Peek fd)
FD.use_exn "spawn_stdin" stdin @@ fun stdin ->
FD.use_exn "spawn_stdout" stdout @@ fun stdout ->
FD.use_exn "spawn_stderr" stderr @@ fun stderr ->
let with_cwd (fn : (Cwd.internal -> 'a)) : 'a = match cwd with
| Cwd.Path p ->
fn (Cwd.Path (snd p))
| Cwd.Fd fd ->
FD.use_exn "spawn_cwd" fd @@ fun cwd ->
fn (Cwd.Fd cwd)
in
with_cwd @@ fun cwd ->
let pid = spawn ~env ~cwd ~stdin ~stdout ~stderr ~prog ~argv ~use_vfork:true ~setpgid:None ~sigprocmask:None in
let fd = pidfd_open pid in
let process = FD.of_unix ~sw ~seekable:false ~close_unix:true fd in
Expand All @@ -993,7 +997,7 @@ module Low_level = struct
t.hook <- hook;
t

let signal t i = pidfd_send_signal (FD.to_unix `Peek t.process) i
let signal t i = FD.use_exn "signal" t.process (fun fd -> pidfd_send_signal fd i)
end
end

Expand Down
7 changes: 0 additions & 7 deletions lib_eio_linux/tests/basic_eio_linux.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ let setup_log level =
Logs.set_level level;
Logs.set_reporter (Logs_fmt.reporter ())

let exec ?stdin ?stdout ?stderr ?cwd ~env ~sw prog args =
let stdin = Option.value ~default:(Eio_linux.get_fd env#stdin) stdin in
let stdout = Option.value ~default:(Eio_linux.get_fd env#stdout) stdout in
let stderr = Option.value ~default:(Eio_linux.get_fd env#stderr) stderr in
let cwd = Option.value ~default:env#cwd cwd in
Eio_linux.Low_level.Process.spawn ~sw ~cwd ~stdin ~stderr ~stdout prog args

let () =
setup_log (Some Logs.Debug);
Eio_linux.run @@ fun _stdenv ->
Expand Down

0 comments on commit 67e3ae5

Please sign in to comment.