Commit graph

116 commits

Author SHA1 Message Date
AnotherTest a2879f53c8 Shell: Restore the terminal PGID before printing out job status on exit
This fixes the assert tripping when interrupting a foreground job.
Also make `bg` mark the job as 'should announce exit'.
2020-12-10 16:20:39 +01:00
AnotherTest 17e1e1f114 Shell: Actually make shebangs work
Also check for executable permissions before actually trying to run, and
print a helpful message if not executable.
Fixes #4358
2020-12-08 23:34:38 +01:00
AnotherTest 0141f7e7fd Shell: Avoid recreating the event loop before exec()
This stops the local socket creation spam.
2020-12-08 23:34:38 +01:00
AnotherTest cd8268e6fb Shell: Put background jobs into new process groups too
Fixes #4345.
This was done in 54b453b in the name of "fixing event loop processing in
subshells", but I do not see how a new PGID is supposed to affect the event
loop.
This seems to have been done by mistake, let's see if any tests fail
because of this.
2020-12-08 23:34:38 +01:00
AnotherTest 59b46a1f51 Shell: Show termination signal if job did not exit cleanly 2020-12-08 23:34:38 +01:00
AnotherTest 48a1f7e55c Shell: Silence TCSETPGRP errors when not interactive 2020-12-08 23:34:38 +01:00
AnotherTest 57728ef29f Shell: Replace all dbg()'s with dbgln() 2020-12-08 23:34:38 +01:00
AnotherTest 5325d6871d Shell: Make <return> go to a new line when the command is incomplete
"incomplete" meaning that it has a syntax error that can be recovered
from by continuing the input.
2020-12-08 23:34:38 +01:00
AnotherTest 1aed61964a Shell: Do not leak the value of ARGV in nested function calls 2020-11-01 18:45:05 +01:00
AnotherTest e87e580eb3 Shell: Search for variables in the last frame first
Otherwise, we'll end up overwriting another frame's variables if the
names match up.
2020-11-01 18:45:05 +01:00
AnotherTest bedad383b5 Shell: Store LocalFrames as NonnullOwnPtr<LocalFrame> instead
As Vector<T> will relocate objects to resize, we cannot assume that the
address of a specific LocalFrame will stay constant, or that the
reference will not be dangling to begin with.
Fixes an assertion that fires when a frame push causes the Vector to
reallocate.
2020-11-01 18:45:05 +01:00
AnotherTest 6e2a383f25 Shell: Wait for the rest of the members of a pipeline when one exits
Assuming we were blocking on one to begin with.
2020-10-29 11:53:01 +01:00
AnotherTest c92865bd05 Shell: Use kill_job() to kill jobs 2020-10-29 11:53:01 +01:00
AnotherTest 384e872ff9 Shell: Add redirections to the formatted command string 2020-10-29 11:53:01 +01:00
AnotherTest f4b7a688b1 Shell: Rename {source,dest}_fd to {old,new}_fd
This makes `Rewiring' much more understandable, and un-confuses the uses
of `dup2()'.
Also fixes `dup2()' bugs.
2020-10-29 11:53:01 +01:00
AnotherTest 0bc758d34a Shell: Run builtins that cannot be run in the main process in a new child
e.g. `$(jobs | wc -l)` would blow up horribly otherwise.
(it still does)
2020-10-29 11:53:01 +01:00
AnotherTest a8c18f9fd2 Shell: Drop all the jobs after killing them in stop_all_jobs() 2020-10-29 11:53:01 +01:00
AnotherTest 5a4673d468 Shell: Ensure that jobs going through run_tail() retain should_wait
This allows putting logic in the background as well.
2020-10-26 14:28:38 +01:00
AnotherTest 9ad858bcbf Shell: Make the ENSURE_WAITID_ONCE requirements a bit less strict
waitid() *may* be called many times if a job does not exit, so only
assert this fact when the job has in fact exited.
Also allows Background nodes to contain non-execute nodes.
2020-10-26 14:28:38 +01:00
Linus Groh 4a4b1b1131 Shell: Support HISTFILE environment variable
This allows changing the Shell's history file path.
2020-10-26 11:27:54 +01:00
Linus Groh b2e4fe1299 Shell+LibLine: Move Shell::{load,save}_history() to Line::Editor
This allows us to easily re-use history loading and saving in other
programs using Line::Editor, as well as implementing universally
recognized HISTCONTROL.
2020-10-26 11:27:54 +01:00
AnotherTest 956e9aa736 Shell: Fix off-by-one in EOL mark printing
Fixes #3844.
2020-10-25 16:39:18 +01:00
Andreas Kling 1d96ecf148 Everywhere: Add missing <AK/TemporaryChange.h> includes
Don't rely on HashTable.h pulling this in.
2020-10-15 23:49:53 +02:00
AnotherTest a9cee8ee02 Shell+LibLine: Record the input offset of completions
This makes the completion entry retain information about how much of the
suggestion was part of the string that caused the match.
2020-10-04 23:12:28 +02:00
AnotherTest f164b808b5 Shell: Move everything to the Shell namespace
Also provide a basic default-constructor.
2020-10-04 23:12:28 +02:00
asynts d5ffb51a83 AK: Don't add newline for outf/dbgf/warnf.
In the future all (normal) output should be written by any of the
following functions:

    out    (currently called new_out)
    outln
    dbg    (currently called new_dbg)
    dbgln
    warn   (currently called new_warn)
    warnln

However, there are still a ton of uses of the old out/warn/dbg in the
code base so the new functions are called new_out/new_warn/new_dbg. I am
going to rename them as soon as all the other usages are gone (this
might take a while.)

I also added raw_out/raw_dbg/raw_warn which don't do any escaping,
this should be useful if no formatting is required and if the input
contains tons of curly braces. (I am not entirely sure if this function
will stay, but I am adding it for now.)
2020-10-04 17:04:55 +02:00
AnotherTest 254d66cd81 Shell: Assert that the same pid is not given to waitpid()
Theoretically, this assertion should never trip (at least, on serenity
where we don't really reuse PIDs).
This change should be considered temporary, until we figure out whether
waitpid() is being called twice (and succeeding) for one given PID.
2020-10-01 21:20:14 +02:00
AnotherTest 519d1811fd Shell: Wait for *any* child to change state when receiving a SIGCHLD
This really just works around the core issue, which is that we have no
reliable way to know exactly who raised the signal (yet).
Fixes #3645, in a very weird (yet apparently standard) way.
2020-10-01 21:20:14 +02:00
AnotherTest b91be8b9fd Shell: Make 'editor' a member of Shell, and provide a LibShell 2020-09-30 20:05:24 +02:00
asynts afa2523724 Shell: Don't execute scripts interactively.
The following example should illustrate one issue arising from this:

    $ echo 'exit 1' > example.sh
    $ Shell example.sh
    Good-bye!

This message is meant to be shown to an interactive user, but not in a
shell script.
2020-09-28 17:39:50 +02:00
AnotherTest 5f1cc64504 Shell: Fix use-after-move in alias resolution
This unbreaks aliases!
2020-09-26 22:11:28 +02:00
AnotherTest b3dd97a694 Shell: Add a (very basic) formatter 2020-09-26 21:28:35 +02:00
AnotherTest 51e598cf0b Shell: Use NonnullRefPtr to store non-null subnodes
Also replaces null-is-invalid nodes with syntax error nodes.
2020-09-26 21:28:35 +02:00
AnotherTest 29ef65c458 Shell: Fix Vector OOB access in `add_entry_to_cache()'
Fixes #3530.
2020-09-19 00:38:41 +02:00
AnotherTest a43d9c4fe0 Shell: Make a new session at start if there's no active session 2020-09-19 00:38:41 +02:00
AnotherTest 4c2f86c24f Shell: Do not strip glob base path when it was explicitly requested
Fixes #3544.
2020-09-19 00:24:16 +02:00
AnotherTest cd0ddf27f3 Shell: Allow builtins and functions as conditions for 'if' 2020-09-14 17:40:18 +02:00
AnotherTest d1550ea64f Shell: Add support for functions
This implementation does not have support for 'return' yet.
2020-09-14 17:40:18 +02:00
AnotherTest 0b57cdff82 Shell: Add support for $0,$1,... 2020-09-14 17:40:18 +02:00
AnotherTest 063fb02ef4 Shell: Move the first command in a pipeline to the pipeline pgid too
This process is supposed to be the session leader of the pipeline
process group, we can't *not* move it into that group :P
2020-09-12 21:18:24 +02:00
AnotherTest 927e2fc6bc Shell: Do not reset the terminal attributes when command is run in bg
Also removes a FIXME that no longer applies.
2020-09-10 11:20:22 +02:00
AnotherTest 54b453be57 Shell: Fix event loop processing and backgrounding in subshells 2020-09-09 20:35:21 +02:00
AnotherTest aa2df9277d Shell: Allow control structures to appear in pipe sequences
This makes commands like the following to be possible:
```sh
$ ls && for $(seq 10) { echo $it }
$ ls | for $(seq 1) { cat > foobar }
```
2020-09-09 20:35:21 +02:00
AnotherTest 7b5ead64a5 Shell: Announce job events at the right times
This fixes a duplicate message when running `jobs` for the first time
after a job has been moved to the background.
Also actually announces background exits now :^)
2020-09-09 20:35:21 +02:00
AnotherTest 715e11f692 Shell: Fix job control and backgrounding
This patchset makes the shell capable of lazily resolving and executing
sequences of commands, to allow for putting logical sequences in the
background.
In particular, it enables And/Or/Sequence nodes to be run in the background,
and consequently unmarks them as `would_execute`.
Doing so also fixes job control to an extent, as jobs are now capable of
having 'tails', so sequences can be put in the background while
preserving their following sequences.
2020-09-09 20:35:21 +02:00
Nico Weber 8b166e57df
Misc: Remove some unneeded includes of Timer.h and ElapsedTimer.h (#3286) 2020-08-25 09:41:56 +02:00
AnotherTest cf18bff72a Shell: Do not attempt to yank the TTY from background processes
They don't own the TTY anyway!
2020-08-19 21:21:34 +02:00
AnotherTest 20d4287eaf Shell: Fix outdated debug log code 2020-08-19 21:21:34 +02:00
AnotherTest 4ee4c94d60 Shell: Respect the 'PROMPT_EOL_MARK' environment variable
This allows the users to customise what is shown when a command ends
without a newline.
2020-08-18 16:58:17 +02:00
AnotherTest 14a54a72fa Shell: Ensure that the cursor starts on a new line
And print an indicator when it doesn't, a la zsh.
2020-08-17 17:44:02 +02:00