Commit 60f6bb3
authored
fix(run): exec target/ninja directly, scope LD_LIBRARY_PATH to child (#133)
* fix(run): exec target/ninja directly, scope LD_LIBRARY_PATH to child
mcpp run/test/build injected the bundled-glibc LD_LIBRARY_PATH into mcpp's
own process (setenv) before std::system/capture, so the host /bin/sh it
spawned inherited it. On newer-glibc distros sh then loaded the bundled
(older) libc, which could not satisfy host libtinfo's GLIBC_2.42 symbols,
and aborted before the target ran (reported as a 'sh:' version error).
Add platform::process::run_exec/capture_exec (no shell; child-scoped env)
and route the run, test, fast-path-ninja, and full-build-ninja launches
through them. The produced binary is already self-contained (bundled
--dynamic-linker + RUNPATH via gcc-specs/clang-cfg patch), so the loader
env was redundant for normal binaries anyway.
- store BuildResult::ninjaProgram raw (execvp needs argv, not a shell
string); quote only at the remaining shell site; defensive unquote for
legacy caches.
- tests/unit/test_process_run_exec.cpp: proves parent env is never mutated.
- tests/e2e/74: hostile LD_LIBRARY_PATH + bundled-interp guard.
- ci-fresh-install: linux-distro-matrix across fedora/arch/tumbleweed/
debian-testing (+ old-glibc ubuntu-2004/debian-11).
* fix(process): use posix_spawn (parent-built envp); fix Windows/macOS
CI surfaced two cross-platform bugs in the first cut:
- macOS: fork()+setenv()-in-child mutated the test's parent-env expectation
(post-fork setenv is async-signal-unsafe on macOS). Switch POSIX run_exec/
capture_exec to posix_spawnp with an envp built in the PARENT — the child
env never touches the parent, and there is no post-fork setenv.
- Windows: capture_exec force-quoted argv[0], so popen's cmd.exe /c "..."
stripped the outer quotes and mangled the ninja path ('filename syntax
incorrect'). Keep argv[0] raw (per platform.shell guidance) and quote only
later args.
Unit tests gated to POSIX (they reference /bin/*); Windows path is covered by
the integration build that launches ninja via capture_exec.
Verified on Linux: unit 19/19, e2e 74, fast-path rebuild.
* fix(process): shell env-prefix launcher (no spawn) — fixes Windows/macOS
Both spawn-based attempts regressed non-Linux: posix_spawn returned an error
on the macOS runner (run_exec rc!=0), and _spawnvpe segfaulted mcpp run on
Windows (0xC0000005). The leak is Linux-only (macOS injects no runtime env;
Windows has no glibc symbol versioning), so changing the launch primitive on
every platform was the wrong call.
Reimplement run_exec/capture_exec on top of the existing shell helpers:
- run_exec: std::system with the env as a prefix via
build_env_prefix (POSIX) / _putenv_s (Windows). The shell std::system
spawns starts clean, so a bundled-glibc LD_LIBRARY_PATH reaches only the
target child, never /bin/sh — which fixes the original crash.
- capture_exec: command_from_argv + ' 2>&1' through the existing
capture_with_env (same prefix semantics).
No spawn primitives, no per-platform exec code. Linux: unit 19/19, e2e 74,
hostile-LD_LIBRARY_PATH run, and fast-path rebuild all green.
* test(process): use /bin/sh not /bin/true (absent on macOS)
The macOS CI failures across every launcher attempt were this test, not the
implementation: /bin/true lives at /usr/bin/true on macOS, so run_exec returned
127 and the rc==0 assertion failed. Use /bin/sh -c 'exit 0' (present on Linux
and macOS).
* refactor(process): hybrid launcher — Linux posix_spawn, macOS/Windows shell
Per review: use a direct exec (posix_spawn) on Linux, where the leak actually
lives and where it can be iterated locally, and keep the proven std::system
shell path on macOS/Windows (which inject no runtime env / have no glibc symbol
versioning). This gives Linux the clean child-only env isolation with no shell
quoting/signal/injection surface, while not risking the platforms that can't be
reproduced here. A TODO(launcher-unify) marks unifying onto spawn later if
macOS/Windows ever need the same isolation.
Linux verified: unit 19/19, e2e 74, hostile-LD_LIBRARY_PATH run, fast-path,
passthrough args.1 parent 435e1fa commit 60f6bb3
7 files changed
Lines changed: 1106 additions & 53 deletions
File tree
- .agents/docs
- .github/workflows
- src
- build
- platform
- tests
- e2e
- unit
Lines changed: 705 additions & 0 deletions
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
123 | 200 | | |
124 | 201 | | |
125 | 202 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
274 | 274 | | |
275 | 275 | | |
276 | 276 | | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
277 | 281 | | |
278 | 282 | | |
279 | 283 | | |
| |||
317 | 321 | | |
318 | 322 | | |
319 | 323 | | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
325 | 329 | | |
326 | | - | |
327 | | - | |
328 | | - | |
| 330 | + | |
329 | 331 | | |
330 | | - | |
331 | | - | |
332 | | - | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
333 | 339 | | |
334 | 340 | | |
335 | 341 | | |
| |||
386 | 392 | | |
387 | 393 | | |
388 | 394 | | |
389 | | - | |
390 | | - | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
391 | 398 | | |
392 | | - | |
| 399 | + | |
393 | 400 | | |
394 | 401 | | |
395 | 402 | | |
396 | | - | |
397 | | - | |
398 | | - | |
| 403 | + | |
| 404 | + | |
399 | 405 | | |
400 | | - | |
401 | | - | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
402 | 410 | | |
403 | 411 | | |
404 | 412 | | |
| |||
505 | 513 | | |
506 | 514 | | |
507 | 515 | | |
508 | | - | |
509 | 516 | | |
510 | 517 | | |
511 | 518 | | |
512 | | - | |
513 | | - | |
514 | | - | |
515 | 519 | | |
516 | 520 | | |
517 | 521 | | |
518 | 522 | | |
519 | 523 | | |
520 | 524 | | |
521 | | - | |
522 | | - | |
523 | | - | |
524 | | - | |
525 | | - | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
526 | 536 | | |
527 | 537 | | |
528 | 538 | | |
529 | 539 | | |
530 | 540 | | |
531 | | - | |
532 | | - | |
533 | | - | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
534 | 546 | | |
535 | 547 | | |
536 | 548 | | |
537 | | - | |
538 | | - | |
539 | | - | |
| 549 | + | |
540 | 550 | | |
541 | 551 | | |
542 | 552 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
714 | 714 | | |
715 | 715 | | |
716 | 716 | | |
717 | | - | |
718 | | - | |
719 | | - | |
720 | | - | |
721 | | - | |
722 | | - | |
723 | | - | |
724 | | - | |
725 | | - | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
726 | 722 | | |
727 | 723 | | |
728 | 724 | | |
| |||
734 | 730 | | |
735 | 731 | | |
736 | 732 | | |
737 | | - | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
738 | 738 | | |
739 | | - | |
740 | | - | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
741 | 742 | | |
742 | | - | |
| 743 | + | |
743 | 744 | | |
744 | | - | |
745 | | - | |
| 745 | + | |
746 | 746 | | |
747 | | - | |
748 | | - | |
| 747 | + | |
749 | 748 | | |
750 | | - | |
751 | | - | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
752 | 754 | | |
753 | 755 | | |
754 | 756 | | |
| |||
0 commit comments