mORMot2 DailyDaily read of upstream commits

External processes gain cross-platform stream control

A new TExternalProcess class brings redirected stdin, stdout and stderr to Windows and POSIX, with callbacks, buffered reads and process-tree termination. POSIX RunRedirect now uses the same machinery, and a follow-up avoids scanning huge descriptor limits before every child launch. Delphi and FPC backends are both covered, but the intermediate Windows and Delphi POSIX revisions should not be taken without their later fixes.

TL;DR

  • TExternalProcess is a new public API for interactive child processes with redirected input and separate or merged output streams.
  • Windows uses an inherited-handle allow-list and a job object; POSIX uses close-on-exec pipes, process groups and explicit descriptor cleanup.
  • POSIX RunRedirect now uses TExternalProcess, while Windows RunRedirect continues to use RunCommandWin.
  • The final Delphi Linux follow-up fixes signed descriptor types and was tested with Delphi 13 on Linux64.

Upgrade advice

Take the complete PR #734 merge, not an intermediate revision. The first Windows implementation is followed by thread-safe startup API resolution, and the first Delphi POSIX enablement is followed by a required signed-descriptor compile fix. The raw payload contains neither build metadata nor superseded_by records, so no build range is claimed.

Commits8
Lines+4700 -404
Read4 min

7 of 7 entries · 8 commits upstream

Stories
# Entry Category Units
1 Medium Windows process attributes are resolved before concurrent use mormot.core.os.windows moves resolution of InitializeProcThreadAttributeList, UpdateProcThreadAttribute and DeleteProcThreadAttributeList into InitializeSpecificUnit. HasProcThreadAttribute now only checks the three function pointers. This removes the mutable ProcThreadAttributeChecked flag and the unlocked GetProcAddress sequence from the first TExternalProcess launch. Fixes mormot.core.os.windows d1de8cc6+5-13

core: TExternalProcess resolves the Windows attribute list API at startup - see #648

Impact

Delphi and FPC Windows servers can create the first TExternalProcess instances from multiple threads without racing during Vista+ API discovery. Systems lacking the APIs still use the existing serialized inheritance fallback. No application API changes.

zen010101 · 11:33 UTC · PR #648 · view the commit on GitHub →

2 Medium A stateful child-process API can stream input and output mormot.core.os adds TExternalProcess and TExternalProcessState. Start accepts either a command line or an argument array; Write and CloseStdin feed stdin; callbacks or ReadAvailable and ReadErrorAvailable consume output. New TRunOptions members select null or piped stdin and merged or separate stderr. The POSIX backend uses close-on-exec pipes, execve, a process group and a background reader, and POSIX RunRedirect is rebuilt on the same class. At this revision the Windows methods are still stubs. New features mormot.core.os+2 cd48e5ef+1478-129

core: new TExternalProcess class with redirected stdin/stdout/stderr - see #648

Impact

Delphi and FPC applications gain a non-shell API for long-running or interactive children on POSIX, including controlled stdin and incremental output. Existing POSIX RunRedirect calls keep their signature but now run through new fork, pipe and reap code, so process launch, environment handling and termination behavior are on a new path. Windows applications cannot use TExternalProcess at this exact revision and should take the later implementation.

Worth a look

Review POSIX services that depend on RunRedirect timeouts, callbacks or custom environments, and adopt the complete merged series before using TExternalProcess on Windows.

Public API

  • TExternalProcessadded — Starts a child, redirects streams, reads output and terminates the process tree.
  • TExternalProcessStateadded — Exposes not-started, running, exited and failed states.
  • TRunOptions.roStdinNull/roStdinPipe/roStderrMerge/roStderrPipeadded — Selects stdin and stderr redirection for TExternalProcess.
  • RUN_PROCESSadded — Defaults to null stdin and stderr merged into stdout.
  • RunRedirectbehaviour-changed — The POSIX implementation now runs through TExternalProcess instead of the previous popen path.

zen010101 · 04:08 UTC · PR #648 · view the commit on GitHub →

3 Medium Windows children inherit only their assigned standard handles mormot.core.os.windows implements TExternalProcess with CreateProcessW. On Vista and later, PROC_THREAD_ATTRIBUTE_HANDLE_LIST limits inheritance to the selected stdin, stdout and stderr handles; older systems use a serialized fallback. Each child starts suspended in its own process group and job, then a background thread drains stdout and stderr. Argument arrays are quoted for CommandLineToArgvW, and termination escalates from CTRL_BREAK and WM_QUIT to the whole job. New features mormot.core.os+1 4b165bd9+722-22

core: TExternalProcess Windows implementation - see #648

Impact

Delphi and FPC Windows backends can now use the same TExternalProcess API as POSIX without leaking unrelated inheritable handles into children. Process-tree termination is stronger than a single TerminateProcess call, and argument-array launches avoid shell parsing. Windows RunRedirect itself remains on RunCommandWin. Do not stop on this revision because the later d1de8cc6 fix removes an unlocked first-use API lookup.

Worth a look

Test Windows commands that depend on inherited handles, console attachment or nested child processes, using the merged series that includes d1de8cc6.

Public API

  • TExternalProcess.Startbehaviour-changed — The previously unavailable Windows backend now launches and supervises processes.

zen010101 · 05:41 UTC · PR #648 · view the commit on GitHub →

4 Medium POSIX child startup no longer scans the full descriptor limit When close_range or closefrom is unavailable, mormot.core.os.posix now inspects /proc/self/fd on Linux or /dev/fd elsewhere before fork. The child closes descriptors only through the highest observed descriptor plus a margin of 64, rather than looping to RLIMIT_NOFILE. A regression test places a descriptor far above the others and confirms that the child neither inherits it nor delays its closure. Performance mormot.core.os.posix fa95d0f3+84-2

core: TExternalProcess child closes descriptors up to the highest opened - see #648

Impact

FPC and Delphi POSIX services with large file-descriptor limits avoid a launch-time cost on every TExternalProcess or RunRedirect call. The measured case drops from 118 ms at 524288 descriptors and 230 ms at 1048576 descriptors to about 1.3 ms on Linux, and from 33 ms to 6 ms on a macOS runner. Descriptor isolation remains intact.

zen010101 · 15:47 UTC · PR #648 · view the commit on GitHub →

5 Medium Delphi POSIX receives the process and signal wrappers needed for redirection mormot.core.os.delphi publishes wrappers and types for pipes, dup2, fcntl, waitpid and POSIX signal operations. The conditional split that left TExternalProcess and RunRedirect as Delphi POSIX stubs is removed, so the shared mormot.core.os.posix implementation is compiled for Delphi. Linux Delphi calls libc pipe2, while close_range remains FPC-only to avoid requiring glibc 2.34. Tests are enabled for Delphi POSIX except the SIGUSR1 sender. The commit explicitly says it had not yet been compiled with a Delphi POSIX compiler. Compiler & platform mormot.core.os+2 8c07aafe+116-94

core: TExternalProcess and RunRedirect() on Delphi POSIX - see #648

Impact

Delphi Linux and macOS applications gain the same external-process surface as FPC, including environment-aware RunRedirect and TExternalProcess stream control. This exact revision is provisional: the next commit fixes unsigned THandle descriptors and a PosChar type mismatch found by Delphi 13 Linux64, so it should not be used as a landing point.

Worth a look

Review Delphi POSIX code that previously worked around missing RunRedirect features, but test only the follow-up 1d5b3085 or the merged PR #734 result.

Public API

  • TFilDes/TSigSet/SigactionRecadded — Delphi POSIX types needed by the shared process implementation.
  • fppipe/fpdup2/fpfcntl/fpwaitpid/wifexited/wexitstatusadded — Published Delphi wrappers matching the FPC-style POSIX calls.
  • fpsigemptyset/fpsigprocmask/fpsigactionadded — Published signal wrappers used around fork and exec.
  • RunRedirectbehaviour-changed — Delphi POSIX now uses the shared implementation instead of returning an unimplemented error.
  • TExternalProcess.Startbehaviour-changed — Delphi POSIX now enters the real process-launch path instead of the stub.

zen010101 · 11:33 UTC · PR #648 · view the commit on GitHub →

6 Medium Signed POSIX descriptors make TExternalProcess compile on Delphi Linux mormot.core.os changes the protected stdin, stdout, stderr and wake-up descriptor fields from THandle to integer on POSIX, preserving -1 as the invalid value even though Delphi defines THandle as unsigned there. NO_HANDLE follows the same conditional type. mormot.core.os.posix also casts the command name to PUtf8Char before calling PosChar. The author compiled and ran _RunRedirect and _TExternalProcess with Delphi 13 Linux64 on Debian 11. Compiler & platform mormot.core.os+1 1d5b3085+5-3

core: TExternalProcess compiles with the Delphi Linux compiler - see #648

Impact

Delphi Linux64 can compile the new external-process implementation and correctly recognize closed descriptors. Without this fix, the preceding Delphi POSIX enablement does not compile cleanly and its -1 validity checks are type-incompatible. FPC POSIX behavior is unchanged.

zen010101 · 15:06 UTC · PR #648 · view the commit on GitHub →

7 Low The signal-interruption test tolerates slower macOS runners TTestCoreBase._RunRedirect lowers the required number of SIGUSR1 deliveries during a one-second command from more than ten to at least three. The assertion still proves that RunRedirect survives repeated signals, while allowing for macOS arm64 runners whose sender thread wakes roughly every 100 ms instead of every 20 ms. Tests 96554b8e+2-1

test: TTestCoreBase._RunRedirect expects fewer signals - see #648

Impact

There is no application-code or runtime behavior change for Delphi or FPC backends. Continuous integration is less likely to report a false failure on slow macOS arm64 hosts.

zen010101 · 19:06 UTC · PR #648 · view the commit on GitHub →

Upstream activity commits per day · last 60 days
Commits1007
Active days49/60
Busiest2026-09-30
Peak60
2026-09-30: 60 commits2026-10-01: 26 commits2026-10-02: 30 commits2026-10-03: 32 commits2026-10-04: 15 commits2026-10-05: 1 commit2026-10-06: 26 commits2026-10-07: 37 commits2026-10-08: 27 commits2026-10-09: 35 commits2026-10-10: 12 commits2026-10-11: 2 commits2026-10-12: 40 commits2026-10-13: 31 commits2026-10-14: 23 commits2026-10-15: 16 commits2026-10-16: 27 commits2026-10-17: 0 commits2026-10-18: 0 commits2026-10-19: 0 commits2026-10-20: 0 commits2026-10-21: 0 commits2026-10-22: 3 commits2026-10-23: 6 commits2026-10-24: 29 commits2026-10-25: 7 commits2026-10-26: 25 commits2026-10-27: 4 commits2026-10-28: 8 commits2026-10-29: 17 commits2026-10-30: 20 commits2026-10-31: 0 commits2026-11-01: 0 commits2026-11-02: 16 commits2026-11-03: 32 commits2026-11-04: 15 commits2026-11-05: 32 commits2026-11-06: 26 commits2026-11-07: 19 commits2026-11-08: 2 commits2026-11-09: 29 commits2026-11-10: 17 commits2026-11-11: 8 commits2026-11-12: 38 commits2026-11-13: 39 commits2026-11-14: 9 commits2026-11-15: 6 commits2026-11-16: 21 commits2026-11-17: 30 commits2026-11-18: 37 commits2026-11-19: 28 commits2026-11-20: 31 commits2026-11-21: 0 commits2026-11-22: 0 commits2026-11-23: 1 commit2026-11-24: 6 commits2026-11-25: 3 commits2026-11-26: 3 commits2026-11-27: 0 commits2026-11-28: 0 commits
2026-09-302026-11-28