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

Improve shell #43

Merged
merged 12 commits into from
Mar 5, 2024
Merged

Improve shell #43

merged 12 commits into from
Mar 5, 2024

Conversation

fischerling
Copy link
Contributor

This is a collection of all the shell patches I collected.

It included bugfixes next to new features, like redirects using dup or support for executing commands from files.

If the changes are too big let me know an I will break them into smaller pieces.

Redirections have the form [[2|&]> <file>].

Supported redirection are:
  * '>': redirecting stdout
  * '2>': redirecting stderr
  * '&>': redirecting stdout and stderr

Only one redirection is allowed and it must follow the command
the behavior otherwise is undefined.
Our signal handler for SIGCHLD may run any time reaping any
terminated child processes.
It even may reap processes the main loop is explicitly waiting for.
This may cause the status of some processes not being reported properly.

Imagine simply calling a non-exiting binary.
The forked child will exit with status 1 after execvp failed.
The signal handler of the shell may run before the specific "blocking"
waitpid call is reached, reaping the child and dropping its exit status.

In order to prevent this race, we block SIGCHLD before forking.
We immediately enable it again in the forked child.

In the shell however, the signal is unblocked after we have waited for
the child or immediately if we are not blocking.
This is more in line with what other shells actually do.
Additionally, add a simple man page mentioning the new behavior.
Extract the command completion logic from the __cmd_get loop
into a separate function.
__cmd_clr() already resets the cursor to 0.
@Galfurian Galfurian added bug Something isn't working enhancement New feature or request labels Mar 1, 2024
@Galfurian Galfurian merged commit 2579cec into mentos-team:develop Mar 5, 2024
17 checks passed
@fischerling fischerling deleted the improve-shell branch March 14, 2024 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants