-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #412 from haesbaert/luvsighack
Fix luv signals (issue #400)
- Loading branch information
Showing
2 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Setting up the environment | ||
|
||
```ocaml | ||
# #require "eio_main";; | ||
# open Eio.Std;; | ||
``` | ||
|
||
# Test cases | ||
|
||
Prove we can catch sigint: | ||
```ocaml | ||
# Eio_main.run @@ fun _stdenv -> | ||
let interrupted = Eio.Condition.create () in | ||
let old = Sys.signal Sys.sigint | ||
(Signal_handle (fun num -> if num = Sys.sigint then Eio.Condition.broadcast interrupted)) | ||
in | ||
Fiber.both | ||
(fun () -> | ||
Eio.Condition.await_no_mutex interrupted; | ||
traceln "interrupted!"; | ||
) | ||
(fun () -> | ||
let ppid = Unix.getpid () in | ||
match Unix.fork () with | ||
| 0 -> | ||
Unix.kill ppid Sys.sigint; | ||
Unix._exit 0 | ||
| child_pid -> | ||
let wait () = | ||
let pid, status = Unix.waitpid [] child_pid in | ||
assert (pid = child_pid); | ||
assert (status = (Unix.WEXITED 0)) | ||
in | ||
try wait () with Unix.Unix_error (Unix.EINTR, _, _) -> wait () | ||
); | ||
Sys.set_signal Sys.sigint old;; | ||
+interrupted! | ||
- : unit = () | ||
``` |