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.open_process_args_*: look up program in PATH #10084
Conversation
otherlibs/unix/unix.mli
Outdated
@@ -879,7 +879,7 @@ val open_process_args_in : string -> string array -> in_channel | |||
command to run, and the second argument specifies the argument array passed | |||
to the command. This function runs the command in parallel with the program. | |||
The standard output of the command is redirected to a pipe, which can be read | |||
via the returned input channel. | |||
via the returned input channel. The program is looked up in the [PATH]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we would need a @since
marker for the PATH lookup, or at least a clear indication in the documentation that older versions of OCaml may not do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a clarification about this to the docstring, but without using a @since
marker since it wasn't clear to me how to specify more than one such marker.
@@ -917,13 +917,13 @@ let create_process_gen usepath cmd args optenv | |||
(if new_stderr = 2 then 2 else file_descr_not_standard new_stderr) | |||
|] in | |||
Fun.protect ~finally:close_after | |||
(fun () -> spawn cmd args optenv usepath redirections) | |||
(fun () -> spawn cmd args optenv true (* usepath *) redirections) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if spawn
is not exported, we should make usepath
a labelled argument instead of using comments to alleviate the problems of non-labelled boolean arguments.
(Looking at the code, I see that spawn
is an external. Can external have labels too?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Externals can have labeled and even optional arguments. There are examples elsewhere in this unix.ml
file.
This said, spawn
is not exported, and is called only twice in unix.ml
, so it doesn't need to have a bulletproof interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I'm not adding a label as it seems a bit overkill in this case...
Changes
Outdated
@@ -26,6 +26,11 @@ Working version | |||
|
|||
### Other libraries: | |||
|
|||
- #10084: Unix.open_process_args_* functions now look up the program in the PATH |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The glob only matches 3 of the 4 functions because of the trailing underscore 😈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change, strictly speaking, so it should be listed with a *
instead of a -
.
Why is this breaking? Assume the current directory contains an executable named foo.exe
, and PATH
does not contain .
, like it should. Unix.open_process_args "foo.exe" ...
succeeds with the current implementation and fails with the new implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I amended the Changes
entry and the docstring for the function.
b1bb24c
to
4fdb4ac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am in favor of the change, which improves compatibility between the different platforms and seems more consistent with what our users actually want.
Changes
Outdated
@@ -26,6 +26,12 @@ Working version | |||
|
|||
### Other libraries: | |||
|
|||
* #10084: Unix.open_process_args* functions now look up the program in the PATH. | |||
This was already the case under Windows, but this is now also done under | |||
Unix. Note that previusly the program was interpreted relative to the current |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unix. Note that previusly the program was interpreted relative to the current | |
Unix. Note that previously the program was interpreted relative to the current |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed.
otherlibs/unix/unix.mli
Outdated
@@ -879,7 +879,9 @@ val open_process_args_in : string -> string array -> in_channel | |||
command to run, and the second argument specifies the argument array passed | |||
to the command. This function runs the command in parallel with the program. | |||
The standard output of the command is redirected to a pipe, which can be read | |||
via the returned input channel. | |||
via the returned input channel. The program is looked up in the [PATH] (this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you break a line before this new sentence, so that the behavior changes catches the eye?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an approval stamp.
Before we merge, do we need to do anything specific to the fact that we are proposing a change to the sdlib that is "a bugfix" or "a breaking change" according to who you ask?
I was wondering if we needed more opinions on this; let me cc the @ocaml/caml-devel group, in case people want to chime in. If there is no negative feedback for about a week, please feel free to remind me to merge.
Sounds good, thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have zero problems with the change of semantics. Yes, technically it is a breaking change, so that's why it must be starred in the change log. But the previous behavior was an oversight, and the only way to do something useful with the previous behavior was to use absolute paths /bin/ls
, in which case the new behavior is the same. So, I don't think we have an issue here.
Nonetheless I have hairs to split about the documentation strings, see below.
otherlibs/unix/unix.mli
Outdated
The program is looked up in the [PATH] (this behaviour changed in 4.12; | ||
previously the program was interpreted relative to the current directory). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Elsewhere in unix.mli we write "The executable file is searched in the path". (4 occurrences.)
Also, you first talk about "the command" and then "the program". For me, "the command" is a shell command line, as used in open_process_in
for instance. "The program" is better.
Also, "the program was interpreted relative to the current directory" is still true: the path is not searched for programs like ./foo
or foo/bar
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I pushed revised docs for the open_process_args*
functions to make them more uniform with the rest of the docstrings in this file (also added a line about the environment passed to the new process, which was previously missing). Let me know what you think!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new documentation is just fine (modulo a typo that I fixed by a direct push), thank you very much!
I'm so happy that I'll merge right now.
The `Unix.open_process_args*` used to treat their first arguments as a file name for the executable to be run, like `execv` does. This commit ensures that the first argument is searched in the executable path, like `execvp` does. This is a more useful behavior. Closes: ocaml#10083
Fixes #10083, see the discussion in #10057, especially #10057 (comment) and #10057 (comment)
cc @xavierleroy