Skip to content

Shell and Run: fixes from AROS - #166

Open
pulchart wants to merge 20 commits into
ApolloTeam-dev:masterfrom
pulchart:wip/jpu/run-redirect
Open

pulchart wants to merge 20 commits into
ApolloTeam-dev:masterfrom
pulchart:wip/jpu/run-redirect

Conversation

@pulchart

@pulchart pulchart commented Nov 22, 2026 •

Copy link
Copy Markdown

The ApolloOS Shell has not changed since it left AROS in 2020. This brings the AROS fixes for the Shell and Run that apply to it. Commits taken as they are keep their authors; the Run child redirection fix had to be ported by hand to the older Shell. The first commit expands tabs to spaces in the Shell and Run sources, whitespace only, as AROS did in f6943e7 and f4f7022, so the fixes apply as they are.

  • Run: a child command keeps its own redirections. In Run >NIL: cmd >file the second > failed with error 217 (too many levels) and the child never ran, silently. Ported from AROS bf7075aab8 by Nicolas Ramz (shell: preserve redirections in Run's child command aros-development-team/AROS#1708). Shell 41.5.
  • Run: a quoted child command name with spaces or escapes reaches the background CLI as written (shell: let Run start programs with spaces in their names aros-development-team/AROS#1714).
  • Run: output redirected to a RAM: file reaches the background command (Run >RAM:x cmd gave an empty file), >> appends instead of overwriting, and Run >NIL: no longer prints the [CLI n] line.
  • Shell: a redirection that cannot be opened prints the error instead of skipping the command silently.
  • Shell: unload what cli_Module holds after a command, as the Kickstart CLI does. Self-decrunching executables (PowerPacker, Imploder) were freed twice and leaked the unpacked program (Shell: unload cli_Module after a command, like the Kickstart CLI aros-development-team/AROS#1778).
  • Shell: the backtick temporary file T:Shell$embed<n> is deleted after use.
  • Scripts: .key names match exactly (.key AB,A gave <A> unexpanded), names longer than the limit are rejected instead of overflowing, .pushis/.popis need the full name in any case, /N accepts a sign.
  • Scripts: *" inside quotes is an escaped quote, + continues a line only after a space, as in AmigaOS.
  • Smaller fixes: buffer reallocation frees the size it allocated, ReadArgs and backtick state cleanup, the CLI number inside backticks.
  • Run: run every '+' continuation line once
Case Before After
Run >NIL: Echo child >RAM:child.txt nothing ran writes child; runcommandredir 0 failures, before 1
Run >RAM:runout.txt Echo hello empty file hello
Run >>RAM:app.txt Echo more PREFIX overwritten PREFIX kept
.key AB,A with one two A=<A> AB=one A=two AB=one
Echo "bt=`Echo hi`" T:Shell$embed1 stays no temporary file
Echo >RAM:nodir/x hi nothing printed object not found
Echo "a*";b" argument line invalid or too long a";b
Run with + continuation lines only the first line runs every line runs once

pulchart and others added 19 commits November 22, 2026 08:10
Whitespace only, as AROS did in f6943e7 and f4f7022, so the Shell and Run sources line up with AROS and its fixes apply.
Validates with original AmigaOS Shell.

This now allows invoking g++ without parameters from Shell

(cherry picked from commit f8e2814)
The [CLI n] announcement went to StandardError unconditionally (unless QUIET),
so 'Run >NIL: ...' still printed it, which is noise during boot. Only announce
when the command's output is interactive; QUIET and the interactive case are
unchanged.

Fixes ApolloTeam-dev#40

(cherry picked from commit 14592dddf78f42aabfe70a103b321d2d256f3da4)
(cherry picked from commit 2948bf7a86d5d6229d273e788fff5c774a8c38a4)
A redirection whose file would not open set Result2 and nothing else, so
the command silently did not run. executeLine() already prints its own
failures, hence the flag.

(cherry picked from commit 4622c04a6b4a465813f36d0f04bb4575931fc5fd)
(cherry picked from commit b638d1316f0964da4a8d617a09537a012699b337)
(cherry picked from commit c740f4f7aa6233759a23f34781c50388331f620b)
(cherry picked from commit c988aa538d11545c3baa6cb5f2a24b8328cc52b8)
(cherry picked from commit 0bc387a50b4faa464ca5b2717a3ad7b584e9592a)
(cherry picked from commit 4ad38eaa1547cabf4e0593b05960a53dc615bc18)
(cherry picked from commit 63ba39ea0f6349360340c48f9c3299d83ae93207)
(cherry picked from commit 8593679171bdebe7a47688f3af79ce22c13bd218)
(cherry picked from commit 278b8cb90f700113c0d0b9d71ccea8e38841a1c3)
Run needs independent child output/error handles because the parent Shell
closes its redirections when the command returns. MODE_NEWFILE on the
RAM-handler creates an exclusive lock; DupLockFromFH can fail with
ERROR_OBJECT_IN_USE. The old nested OpenFromLock(DupLockFromFH(...)) call
ignored both failures and Run could report success with no child output.

Duplicate through a checked helper. Retry sharing only after
ERROR_OBJECT_IN_USE, free a lock if OpenFromLock fails, and preserve the
position of seekable streams so >> does not overwrite the existing prefix.
Do not interpret an I/O or range error while reading the source position
as a nonseekable stream: only -1/ERROR_ACTION_NOT_KNOWN permits a
positionless duplicate. Reject unrepresentable LONG positions explicitly.

Check NIL/input/output/error setup, centralize failure cleanup, and close
handles for an empty command. Keep the existing successful CLI_RUN stream
ownership transfer. The private helper is shared with a host fault test;
it is not a public API.

Add a native DOS regression that runs an explicit standalone Run binary,
asserts launch status and exact bytes for > and >>, and checks cleanup.
Temporary files live in an exclusively created test directory and are
retained after failure rather than reused by a potentially active child.
Add host fault injection for source/copy seek failures, range rejection,
sharing and lock/handle cleanup, plus build and limitation documentation.

Verified strict standalone and embedded-command x86_64 builds, native
baseline FAIL/fixed PASS for overwrite and append on CON and XTerm, and
host tests with ASan/UBSan. Installed/resident Run was not replaced.

This LONG-based helper does not add large-file positioning, concurrent
append atomicity or allocation-failure coverage of the full Shell launch.
Sharing is not rolled back if a later duplication step fails.

(cherry picked from commit 1d191502345fa0a54b670a0b2f4901e209d84fc4)
(cherry picked from commit 92a7198be120fd4b3b43bfc38f37ec75e698f124)
(cherry picked from commit 9d6f145b44bac5e1a2557c06825dd35f1a1af833)
Self-decrunching executables (PowerPacker, Imploder and similar stubs,
very common on old disks, also used by AMOS runtimes) unpack into new
memory, free their own packed hunks and put the new SegList into
cli_Module for the CLI to unload. The Shell unloaded the segment it had
loaded instead, so the packed hunks were freed twice and the unpacked
program leaked.

Unload what cli_Module holds when the command returns (resident commands
are unchanged).

Found with LCD Dreams (1992, Solstice), an AMOS program that now gets
past its intro instead of failing with "Memory freed twice".

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit fef7adea47cfcd38d1b653efa1ab0d38f5486353)
The Shell opened every redirection on a line itself. In `Run >NIL: cmd >file` the second `>` failed with error 217 (too many levels) and the child never ran; an input redirection such as `<NIL:` was already opened during the <arg> substitution pass.

Run's leading redirections still apply to Run. From the child command on, the text goes unchanged to the background CLI, which applies the child's own redirections. Input redirections now wait for the redirection pass. Shell 41.5.

Ported from AROS commit bf7075aab8 by Nicolas Ramz (aros-development-team/AROS#1708), with its runcommandredir test.
Keep the original child command text instead of forwarding ReadArgs /F's unquoted first item. Skip Run's parsed options while retaining child quoting, escapes, and redirections, and preserve the existing help-prompt path.

Add native launch regressions for spaced and escaped filenames, QUIET, COMMAND keywords, outer redirections, and the help prompt. The quoting regression fails on the unchanged ROM; the fixed ROM passes it and the RunBack redirection regression.

(cherry picked from commit cc44e4a360ca2da151226850e6f152446967f5e6)
@pulchart
pulchart force-pushed the wip/jpu/run-redirect branch from a01967f to 44e256b Compare November 22, 2026 07:25
@pulchart pulchart changed the title shell: keep the redirections of Run's child command Shell and Run: fixes from AROS Nov 22, 2026
The Shell joins '+' continuation lines into Run's argument line, and the
background CLI reads them from its script input. Run gave the commands the
same handle as Input(). RunCommand() injects each command's arguments into
Input() and flushes it afterwards, so only the first line ran. With
continuation lines the commands now get their own NIL: input.

The command taken from the argument line already holds these lines, so the
buffered input is appended only to a single line; otherwise they would run
twice.

runcommandredir checks that every continued line runs once.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants