-
-
Notifications
You must be signed in to change notification settings - Fork 698
$prog.ape support #977
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
Merged
Merged
$prog.ape support #977
Conversation
This file contains hidden or 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
jart
reviewed
Dec 3, 2023
jart
requested changes
Dec 3, 2023
If the ape loader is invoked with `$0 = $prog.ape`, then it searches for a `$prog` in the same directory as it and loads that. In particular, the loader searches the `PATH` for an executable named `$prog.ape`, then for an executable named `$prog` in the same directory. If the former but not the latter is found, the search terminates with an error. It also handles the special case of getting started as `-$SHELL`, which getty uses to indicate that the shell is a login shell. The path is not searched in this case, and the program location is read straight out of the `SHELL` variable. It is now possible to have `/usr/local/bin/zsh.ape` act as a login shell for a `/usr/local/bin/zsh` αpε, insofar as the program will get started with the 'correct' args. Unfortunately, many things break if `$0` is not the actual full path of the executable being run; for example, backspace does not update the display properly. To work around the brokenness introduced by not having `$0` be the full path of the binary, we cut the leading `-` out of `argv[0]` if present. This gets the loader's behavior with `$prog.ape` up to par, but doesn't tell login shells that they are login shells. So we introduce a hack to accomplish that: if ape is run as `-$prog.ape` and the shell is `$prog`, the binary that is loaded has a `-l` flag put into its first argument. As of this commit, αpε binaries can be used as login shells on OSX.
Prior to this, execfn was not being properly set for login shells that did not receive `$_`, which was the case for iTerm2 on Mac. There were no observable consequences of this, but fixing it seems good anyway.
In the non-login-shell case, it was leaving a word of uninitialized memory at `envp[i] + 1`. This reuses the previous calculation based on `envp`.
jart
approved these changes
Dec 4, 2023
G4Vi
pushed a commit
to G4Vi/cosmopolitan
that referenced
this pull request
Jan 19, 2024
* ape loader: $prog.ape + login shell support If the ape loader is invoked with `$0 = $prog.ape`, then it searches for a `$prog` in the same directory as it and loads that. In particular, the loader searches the `PATH` for an executable named `$prog.ape`, then for an executable named `$prog` in the same directory. If the former but not the latter is found, the search terminates with an error. It also handles the special case of getting started as `-$SHELL`, which getty uses to indicate that the shell is a login shell. The path is not searched in this case, and the program location is read straight out of the `SHELL` variable. It is now possible to have `/usr/local/bin/zsh.ape` act as a login shell for a `/usr/local/bin/zsh` αpε, insofar as the program will get started with the 'correct' args. Unfortunately, many things break if `$0` is not the actual full path of the executable being run; for example, backspace does not update the display properly. To work around the brokenness introduced by not having `$0` be the full path of the binary, we cut the leading `-` out of `argv[0]` if present. This gets the loader's behavior with `$prog.ape` up to par, but doesn't tell login shells that they are login shells. So we introduce a hack to accomplish that: if ape is run as `-$prog.ape` and the shell is `$prog`, the binary that is loaded has a `-l` flag put into its first argument. As of this commit, αpε binaries can be used as login shells on OSX. * if islogin, execfn = shell Prior to this, execfn was not being properly set for login shells that did not receive `$_`, which was the case for iTerm2 on Mac. There were no observable consequences of this, but fixing it seems good anyway. * Fix auxv location calculation In the non-login-shell case, it was leaving a word of uninitialized memory at `envp[i] + 1`. This reuses the previous calculation based on `envp`.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.