You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 6851 Reporter: avaron Assigned to:@mshinwell Status: closed (set by @mshinwell on 2015-04-28T15:48:41Z) Resolution: not a bug Priority: normal Severity: minor Platform: Linux OS: CentOS OS Version: 6.6 (Final) Version: 4.02.1 Category: otherlibs Monitored by: ascvortov
Bug description
This code snippet is perhaps the easiest way to reproduce the issue:
let a = Unix.open_process_in "echo 'yes'" in
ignore (Unix.close_process_in a);
ignore (input_line a);
I would have expected End_of_file in input_line. The line may or may not have 'yes', I would basically be sold on both options.
The text was updated successfully, but these errors were encountered:
I would actually expect exactly what happened to you. The documentation is quite clear, Unix.close_process_in closes the channel. See the documentation of Pervasives.close_in to see what that means.
Unfortunately I think there may be a bug here. I think the fact that the example involves [Unix.process] functions isn't relevant.
Looking at the documentation for [close_in], I see:
"Input functions raise a Sys_error exception when they are applied to a closed input channel"
which makes me think that [input_line] should raise [Sys_error], not [End_of_file]. However, the implementation of [input_line] (in particular, the function [caml_ml_input_scan_line] and so forth) do not seem to check whether [channel->fd] is minus one before trying to read. This means that it can attempt to read from fd -1, causing "bad file descriptor". (Thankfully I think it always uses -1, so there's no problem with a file descriptor being closed and reopened onto something else.)
The fix is presumably to add the check as to whether [channel->fd == -1], but I'm not sure of all the potential ramifications of such change.
Ah yes, I failed to notice that the error text is indeed wrapped in Sys_error :) In which case, I think you're right, the semantics appears to be as per the documentation.
Original bug ID: 6851
Reporter: avaron
Assigned to: @mshinwell
Status: closed (set by @mshinwell on 2015-04-28T15:48:41Z)
Resolution: not a bug
Priority: normal
Severity: minor
Platform: Linux
OS: CentOS
OS Version: 6.6 (Final)
Version: 4.02.1
Category: otherlibs
Monitored by: ascvortov
Bug description
This code snippet is perhaps the easiest way to reproduce the issue:
let a = Unix.open_process_in "echo 'yes'" in
ignore (Unix.close_process_in a);
ignore (input_line a);
I would have expected End_of_file in input_line. The line may or may not have 'yes', I would basically be sold on both options.
The text was updated successfully, but these errors were encountered: