Skip to content

Update unix.mli#12338

Merged
Octachron merged 9 commits intoocaml:trunkfrom
craff:patch-1
Jul 12, 2023
Merged

Update unix.mli#12338
Octachron merged 9 commits intoocaml:trunkfrom
craff:patch-1

Conversation

@craff
Copy link
Copy Markdown
Contributor

@craff craff commented Jun 28, 2023

address #12330

@craff
Copy link
Copy Markdown
Contributor Author

craff commented Jun 28, 2023

I wnated to fix the hygiene pb:
This should be fixable by just running tools/sync_stdlib_docs and reviewing the changes it makes.

But I can't find tools/sync_stdlib_docs ?

Using {!create_process} or one of the [open_process_*] functions
instead is recommended.

The first element of the array [args] will often be [argv[0]] or
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using will often be doesn't really make sense for a specification, you are not documenting an optional behavior: programs will break if they are not send the correct number of arguments.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative wording might be:

On both unix and windows, the convention is that the first element of the array [args] is the name of the executed program.


The first element of the array [args] will often be [argv[0]] or
[Sys.argv.(0)] in the new process [prog]. This is plateform
dependant and you should refer to the man page of execv, which for
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

man page are already Unix-only.

The executable file [prog] is searched in the path.
The new process has the same environment as the current process. *)
The new process has the same environment as the current process.
The first element of the array [args] may or may not be required to
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may or may not be required sounds mostly confusing.

Copy link
Copy Markdown
Contributor Author

@craff craff Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was vague because of your comments on the same issue... I will rephrase as you suggest, but do you have a system in mind that does not follow the convention of first args being the process name ?

Maybe what is not clear is what happens when the first args is not the same as the process name.

In fact, my main concern is that if you do

Unix.open_process_args "cmd" [| "-l" |] it will not work as expected while
Unix.open_process_args "cmd" [| ""; "-l" |] probably will (I did not test), because most commands look for option from argv[1] ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I have in mind is that the specification of program name may vary. Typically, the C17 standard reads as

If the value of argc is greater than zero, the string pointed to by argv[0]
represents the program name; argv[0][0] shall be the null character if the
program name is not available from the host environment.

but the represent verb is quite ambiguous.

Famously, the busybox executable mimics the behavior of the program which name in its argv[0].

Overall, we should focus on the important points: we want to warn users that argv[0] has a special meaning.

- rephrase by copying the doc of create_process which was ok to execve and open_process

- also clarify process_pid and alike
@craff
Copy link
Copy Markdown
Contributor Author

craff commented Jul 5, 2023

@Octachron : I rephrased the PR and also applied your suggestion of documentation in issue #12329.

(** [execv prog args] execute the program in file [prog], with
the arguments [args], and the current process environment.
the arguments [args], and the current process environment.
Note that the first argument is by convention the filename of
Copy link
Copy Markdown
Member

@Octachron Octachron Jul 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, "first argument" feels slightly ambiguous to me: it may refer to prog. I would propose to be very explicit: "the first argument, [args.(0)], "

@Octachron
Copy link
Copy Markdown
Member

Octachron commented Jul 5, 2023

The syncing tool is in the tools directory at the top of the tree, but you should transfer your change to unixLabels.mli by hand first (otherwise the tools will erase your changes).

@craff
Copy link
Copy Markdown
Contributor Author

craff commented Jul 5, 2023

The syncing tool is in the tools directory at the top of the tree, but you should transfer your change to unixLabels.mli by hand first (otherwise the tools will erase your changes.

And you need to compile ocaml to have it ! I got it, thanks.

@craff
Copy link
Copy Markdown
Contributor Author

craff commented Jul 5, 2023

I do not understant why one test in the test suite failed while I only changed comments ?

@lthls
Copy link
Copy Markdown
Contributor

lthls commented Jul 6, 2023

I do not understant why one test in the test suite failed while I only changed comments ?

It is a known, unrelated issue (see #12345 for a few more details).

(** [execv prog args] execute the program in file [prog], with the arguments
[args], and the current process environment. Note that the first
argument, [args.(0)], is by convention the filename of the program being
executed, just like [Sys.argv.(0)] These [execv*] functions never return:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing dot: like [Sys.argv.(0)] These [execv*]just like [Sys.argv.(0)]. These [execv*]

program being executed, just like [Sys.argv.(0)].

The pid of the new process is returned immediately; the new process
executes concurrently with the current process. The standard input and
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are separating paragraphs by a newline, you should do so here too (and in the rest of the paragraph below).

Changes Outdated

- #12338: clarification of the documentation of process related function in
the unix module regarding the first element of args and shell's pid.
(Christophe Raffalli review by Florian Angeletti)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing , before review.

Copy link
Copy Markdown
Member

@Octachron Octachron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that documenting those potential pitfalls is worthwhile (and not only for beginners). Thanks !

@Octachron
Copy link
Copy Markdown
Member

Note that the the documentation needs to be synced, and the Changes entry updated.

@craff
Copy link
Copy Markdown
Contributor Author

craff commented Jul 12, 2023

Actually the "Resolve Conflict" button in github does a better job that git on my laptop ;-(

@Octachron Octachron merged commit 686f498 into ocaml:trunk Jul 12, 2023
NickBarnes pushed a commit to NickBarnes/ocaml that referenced this pull request Jul 14, 2023
* convention for first argument
* process_pid  and friend returns the pid of the shell for process function opening a shell.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants