Skip to content

Conversation

@rolfan-ish
Copy link
Collaborator

POSIX specifies that if the action of trap is null the shell shall ignore each specified condition. Currently oils doesn't adhere.

POSIX also says:

When a subshell is entered, traps that are not being ignored shall
be set to the default actions, except in the case of a command
substitution containing only a single trap command, when the traps
need not be altered.

However dash and bash don't fully follow this behavior, which I am pretty sure is a bug in both shells. I haven't tested other shells yet, including oils.

TODO: Add the spec tests for the exception of traps.

@rolfan-ish rolfan-ish changed the title WIP add tests for subshell trap ignoring [WIP] add tests for subshell trap ignoring Oct 12, 2025
@andychu
Copy link
Contributor

andychu commented Oct 12, 2025

I would think of it in terms of what strace says each shell is doing, not necessarily what POSIX says

"ignored" is an ambiguous term

  • does it mean it executes nothing?
  • does it mean SIG_IGN ?

@rolfan-ish
Copy link
Collaborator Author

Is it good now?
Otherwise I would appreciate any pointers to resources/examples in order to catch on the guidelines.

Note: Detailed information on the commits can be found in the commit messages.

@rolfan-ish
Copy link
Collaborator Author

Looking at the source code the fix seems simple.
TODO: decide how much to adhere to POSIX (specially on case 0). As much as bash? As much as ash? Not at all like dash and mksh?

@andychu
Copy link
Contributor

andychu commented Oct 15, 2025

@andychu
Copy link
Contributor

andychu commented Oct 15, 2025

OK the general idea does look good ! Other shells pass and OSH fails

We need assertions for the other shells, like

## BUG mk STDOUT:
## END

See https://github.com/oils-for-unix/oils/wiki/Spec-Tests


And we are inhibited by

this is a really bad bug ... seems like it may block this spec test, gah

@andychu
Copy link
Contributor

andychu commented Oct 15, 2025

I think we have to figure out what OSH does here first:

Most shells don't respect traps in subshells: pipelines etc.

I think these tests are a bit confused by this issue, especially because bash behaves differently

Let's discuss on Zulip about what we're trying to accomplish

POSIX specifies that if the action of trap is null the shell shall ignore
each specified condition (with SIG_IGN). oils doesn't do it.

POSIX also says:
> When a subshell is entered, traps that are not being ignored shall
> be set to the default actions, except in the case of a command
> substitution containing only a single trap command, when the traps
> need not be altered.

`dash` and `bash` always reset traps (except ignored ones).
@rolfan-ish rolfan-ish changed the title [WIP] add tests for subshell trap ignoring [spec/builtin-trap] Add test case for ignored traps in subshells Oct 16, 2025
@rolfan-ish rolfan-ish marked this pull request as ready for review October 16, 2025 18:51
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.

3 participants