Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unix.dup2/close_process_in behaviour changed in 3.07+2 #2331

Closed
vicuna opened this issue Mar 10, 2004 · 2 comments
Closed

Unix.dup2/close_process_in behaviour changed in 3.07+2 #2331

vicuna opened this issue Mar 10, 2004 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Mar 10, 2004

Original bug ID: 2331
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: Florian Hars
Version: 3.07+2
OS: Linux
Submission from: grisu.bik-gmbh.de (217.110.154.194)

The following code works under 3.06, but fails with
Sys_error("Bad file descriptor") unter 3.07+2.

If I don't Unix.close n_stdin at (* X *) it seems to work in 3.07, too.
Is this change in semantics intended or not?

let _ =
let oc = open_out "input.txt" in
output_string oc "TESTTESTTEST\n";
close_out oc;
let o_stdin = Unix.dup Unix.stdin in
let ic = Unix.open_process_in ("cat input.txt") in
let n_stdin = Unix.descr_of_in_channel ic in
Unix.dup2 n_stdin Unix.stdin; Unix.close n_stdin; (* X )
let l = read_line () in
print_endline ("1 Read string: " ^ l);
let excode= Unix.close_process_in ic in
Unix.dup2 o_stdin Unix.stdin; Unix.close o_stdin;
(
Unix.sleep 1000; *)
print_endline ("2 Read string: " ^ l)

@vicuna
Copy link
Author

vicuna commented Apr 13, 2004

Comment author: administrator

Full_Name: Florian Hars

The following code works under 3.06, but fails with
Sys_error("Bad file descriptor") unter 3.07+2.

If I don't Unix.close n_stdin at (* X *) it seems to work in 3.07, too.
Is this change in semantics intended or not?

Yes. "close_process_in" calls "close_in". In 3.06, "close_in" ignores
any error reported by the "close" system call. In 3.07+2, these errors
are not ignored but reported by raising an exception.

let _ =
let oc = open_out "input.txt" in
output_string oc "TESTTESTTEST\n";
close_out oc;
let o_stdin = Unix.dup Unix.stdin in
let ic = Unix.open_process_in ("cat input.txt") in
let n_stdin = Unix.descr_of_in_channel ic in
Unix.dup2 n_stdin Unix.stdin; Unix.close n_stdin; (* X )
let l = read_line () in
print_endline ("1 Read string: " ^ l);
let excode= Unix.close_process_in ic in
Unix.dup2 o_stdin Unix.stdin; Unix.close o_stdin;
(
Unix.sleep 1000; *)
print_endline ("2 Read string: " ^ l)

You are first closing the file descriptor of ic, then trying to close ic
itself. That's a mistake.

-- Damien

@vicuna
Copy link
Author

vicuna commented Apr 13, 2004

Comment author: administrator

not a bug DD 2004-04-13

@vicuna vicuna closed this as completed Apr 13, 2004
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant