-
Notifications
You must be signed in to change notification settings - Fork 177
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 #957 from MisterDA/cloexec-proc-dev-null-fixes
Fix null file descriptor being closed when used as redirection for standard fd of child processes
- Loading branch information
Showing
5 changed files
with
112 additions
and
39 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
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 |
---|---|---|
@@ -1,6 +1,31 @@ | ||
(* This file is part of Lwt, released under the MIT license. See LICENSE.md for | ||
details, or visit https://github.com/ocsigen/lwt/blob/master/LICENSE.md. *) | ||
|
||
|
||
|
||
let test_input_str = "the quick brown fox jumps over the lazy dog" | ||
let test_input = Bytes.of_string test_input_str | ||
let test_input_len = Bytes.length test_input | ||
|
||
let read () = | ||
let buf = Bytes.create test_input_len in | ||
let rec aux n = | ||
let i = Unix.read Unix.stdin buf n (Bytes.length buf - n) in | ||
if i = 0 || n + i = test_input_len then | ||
Bytes.equal buf test_input | ||
else aux (n + i) | ||
in | ||
if aux 0 then | ||
(* make sure there's nothing more to read *) | ||
0 = Unix.read Unix.stdin buf 0 1 | ||
else false | ||
|
||
let write fd = | ||
assert (test_input_len = Unix.write fd test_input 0 test_input_len) | ||
|
||
let () = | ||
let str = "the quick brown fox jumps over the lazy dog" in | ||
match Sys.argv.(1) with | ||
| "read" -> if read_line () <> str then exit 1 | ||
| "write" -> print_string str | ||
| "read" -> exit @@ if read () then 0 else 1 | ||
| "write" -> write Unix.stdout | ||
| "errwrite" -> write Unix.stderr | ||
| _ -> invalid_arg "Sys.argv" |
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 |
---|---|---|
|
@@ -5,7 +5,8 @@ | |
|
||
(executable | ||
(name dummy) | ||
(modules dummy)) | ||
(modules dummy) | ||
(libraries unix)) | ||
|
||
(executable | ||
(name main) | ||
|
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