Skip to content

Commit

Permalink
Raise exception when waitpid would block.
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Jan 17, 2019
1 parent f154c25 commit 4ef7040
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions otherlibs/threads/unix.ml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ type wait_flag =
WNOHANG
| WUNTRACED

exception Waitpid_would_block

let _ = Callback.register_exception "Unix.Waitpid_would_block" Waitpid_would_block

let stdin = 0
let stdout = 1
let stderr = 2
Expand Down
4 changes: 4 additions & 0 deletions otherlibs/unix/unix.ml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ type wait_flag =
WNOHANG
| WUNTRACED

exception Waitpid_would_block

let _ = Callback.register_exception "Unix.Waitpid_would_block" Waitpid_would_block

external execv : string -> string array -> 'a = "unix_execv"
external execve : string -> string array -> string array -> 'a = "unix_execve"
external execvp : string -> string array -> 'a = "unix_execvp"
Expand Down
4 changes: 4 additions & 0 deletions otherlibs/unix/wait.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <caml/mlvalues.h>
#include <caml/alloc.h>
#include <caml/callback.h>
#include <caml/fail.h>
#include <caml/memory.h>
#include <caml/signals.h>
Expand All @@ -43,6 +44,9 @@ static value alloc_process_status(int pid, int status)
{
value st, res;

if (pid == 0)
caml_raise_constant(*caml_named_value("Unix.Wait_would_block"));

if (WIFEXITED(status)) {
st = caml_alloc_small(1, TAG_WEXITED);
Field(st, 0) = Val_int(WEXITSTATUS(status));
Expand Down

0 comments on commit 4ef7040

Please sign in to comment.