Skip to content

Make cleanup dispatcher resilient to control flow in pre-existing EXIT traps #157

Description

@codeforester

Problem

At main commit a107134, __std_run_cleanup_hooks__ evaluates the pre-existing EXIT trap before registered hooks and paths. Because the saved command is evaluated inside the dispatcher function, a trap containing return returns from the dispatcher and skips all registered cleanup. A trap containing exit terminates the shell before library cleanup runs.

Both behaviors were reproduced: a registered hook did not create its marker after either trap 'return 0' EXIT or trap 'exit 7' EXIT was installed before registration.

The current composable-cleanup contract should not allow control flow in an older trap to bypass later registered cleanup.

Scope

  • Isolate or sequence the original trap so return and exit cannot skip registered hooks and paths.
  • Preserve the original trap's observable side effects and intended final exit status.
  • Define and document execution order and status precedence.
  • Retain support for multiline commands and embedded single quotes.

Acceptance Criteria

  • Registered hooks and paths run when the original trap contains return.
  • Registered hooks and paths run before the shell honors an explicit exit status from the original trap.
  • Normal, multiline, and quoted original traps continue to run exactly once.
  • The incoming shell exit status remains available to the original trap and cleanup hooks.

Validation

  • bats lib/bash/std/tests/lib_std.bats
  • ./tests/validate.sh
  • git diff --check

Metadata

Metadata

Assignees

Labels

bugSomething is not working

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions