Commit f5c8524
authored
Carry a caller's redirection across a spawn, and let abort end the program (#17)
* Carry a caller's redirection across a spawn, and let abort end the program
Three defects reported by a consumer as openkal-linux#13, and each of the three
is a place where the specification already carried the atom and this library had
no route to it. The specification does not change.
WHERE A STARTED PROGRAM'S OUTPUT GOES. okm_spawn.c passed {0, 0, 0} and let a
caller's file actions overwrite it. openkal spells inheritance as a handle of
zero, and an implementation reads that as the descriptor the calling image
holds --- which dup2 cannot change, because it rebinds this library's table and
there is no operation that replaces one of a running program's own streams. So
dup2(fd, 1) followed by posix_spawn, by system, or by fork and execve started a
program writing to the stream this program had been started with, and the file
the caller had redirected onto stayed empty. The three positions are now seeded
from the descriptor table; the ones that were not redirected are still passed as
zero, so a backend without KAL_PROCESS_PROP_STREAM_PASSING still starts every
program that does not redirect.
Three adjacent defects fell out of the same reading. A file action is now
applied in the order it was added --- musl's add* prepend and this library
followed next, so a caller's actions were applied in reverse. addopen is
implemented, having been refused although kal_fs_open and kal_fs_stream express
it exactly. addclose upon one of the three standard positions is refused rather
than accepted and not performed, which used to hand a program the standard input
its caller had just taken away.
WHAT abort DOES. SYS_tkill and SYS_tgkill had no case, so musl's raise answered
ENOSYS and abort --- which raises, uninstalls, raises again, and then reaches
the line its own comment calls unreachable --- ended in a_crash(). On x86_64
that is hlt, which faults outside ring 0 and is delivered as SIGSEGV. Measured
on the host kernel: a program whose entire body is hlt exits 139 with a core
dumped. Every uncaught exception, assert, std::terminate and __stack_chk_fail
over this port therefore reported a segmentation fault. A signal aimed at this
program now performs its default action, and SIGABRT reaches kal_abort, which
raises the signal on openkal-linux and ends with a distinguished status
elsewhere. Three numbers are musl's own and are refused: pthread_impl.h reserves
32, 33 and 34, and pthread_cancel is pthread_kill(t, SIGCANCEL).
ASKING AFTER A CHILD WITHOUT WAITING. waitpid discarded its options and blocked,
which is the one thing WNOHANG exists to prevent. kal_timeout_wait_process has
been in the specification since 0.8.
AND ONE THING A CONSUMER COULD NOT SEE. The default arm of the dispatcher
answered ENOSYS in silence; OPENKAL_MUSL_TRACE=enosys now names the operation,
once per number, on the standard error stream, and only the operations that have
no case rather than the ones that answer ENOSYS by decision.
CRITERIA. examples/subprocess grows from 7 observations to 22 and no longer
depends on a shell, so every row of the matrix runs the redirection criteria.
Measured against port/src at 93c247f with the new probe: seven observations
fail, one for each fix, and fifteen controls hold. Continuous integration states
the half a program cannot state about itself --- that the redirected bytes did
not arrive on the caller's own stream, and that the unredirected ones did.
Two capability words are worth naming. kal_process_props is an object and not a
function, so the weak reference is tested by taking its address; the twenty-five
weak references this port already held are all functions, where the established
spelling reads the address anyway. And a stream handle of zero is a valid handle
on an implementation whose streams are its own descriptors, so a caller that
redirects its output onto its own standard input asks for something
kal_spawn_streams cannot express; that spawn is refused rather than answered
wrongly, and the collision is reported upstream.
* Ask after any child, bound the files a spawn opens, and run the program just built
Three findings from reading the change back, and the third is a defect of the
criteria rather than of the library.
waitpid(-1, ..., WNOHANG) asked after the first recorded child rather than after
any of them, so it reported "none has finished" while a later one had --- which
is the reading a caller draining its children in a loop acts upon. The blocking
form has no such choice to make. examples/subprocess starts a slow program
FIRST, so that a library asking only about the earlier slot answers zero until
the slow one finishes and then names the wrong program.
A set of file actions may name one position more than once, and POSIX says the
last such action decides; every file it opened is still open and still has to be
released. The bound is stated as eight rather than derived from the three
positions, and a sequence that exceeds it is refused rather than truncated.
tools/run-probe.sh chose the program to run with `find target | head -1`.
`target/` accumulates one directory per configuration --- the version is part of
the fingerprint --- so after 0.5.0 became 0.6.0 the search answered with the
program built before the change, and two newly added observations did not appear
in the output of a run reporting `-- failures: 0 --`. The criteria had not
failed; they had not run. It cannot bite in continuous integration, where a
fresh checkout builds one configuration, and it bites on the machine where the
change is being written. tools/one-artifact.sh asserts the count before anything
is read, and the three steps that run a program from an accumulating tree call
it.1 parent 93c247f commit f5c8524
14 files changed
Lines changed: 1799 additions & 68 deletions
File tree
- .agents/docs
- .github/workflows
- examples/subprocess/src
- musl
- port/src
- tools
Lines changed: 429 additions & 0 deletions
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | | - | |
55 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
56 | 74 | | |
57 | 75 | | |
58 | 76 | | |
59 | 77 | | |
60 | | - | |
| 78 | + | |
61 | 79 | | |
62 | 80 | | |
63 | 81 | | |
| |||
265 | 283 | | |
266 | 284 | | |
267 | 285 | | |
| 286 | + | |
268 | 287 | | |
269 | 288 | | |
270 | 289 | | |
| |||
279 | 298 | | |
280 | 299 | | |
281 | 300 | | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
282 | 324 | | |
283 | 325 | | |
284 | 326 | | |
| |||
510 | 552 | | |
511 | 553 | | |
512 | 554 | | |
513 | | - | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
514 | 658 | | |
515 | 659 | | |
516 | 660 | | |
| |||
533 | 677 | | |
534 | 678 | | |
535 | 679 | | |
536 | | - | |
| 680 | + | |
537 | 681 | | |
538 | 682 | | |
539 | 683 | | |
| |||
545 | 689 | | |
546 | 690 | | |
547 | 691 | | |
548 | | - | |
| 692 | + | |
549 | 693 | | |
550 | 694 | | |
551 | 695 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
0 commit comments