Skip to content

Simplify SIGQUIT handling - #11381

Merged
sholderbach merged 1 commit into
nushell:mainfrom
IanManske:simple-sigquit
Dec 21, 2023
Merged

sholderbach merged 1 commit into
nushell:mainfrom
IanManske:simple-sigquit

Conversation

@IanManske

@IanManske IanManske commented Dec 20, 2023 •

Copy link
Copy Markdown
Member

Description

Simplifies SIGQUIT protection to a single signal ignore system call.

User-Facing Changes

SIGQUIT is no longer blocked if nushell is in non-interactive mode (signals should not be blocked in non-interactive mode).
Also a breaking API change for nu_protocol.

Tests + Formatting

Should come after #11178 for testing.

@sholderbach sholderbach left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good call to me based on what we do currently.

Not sure if we should do extra work for non-interactive uses (glibc docs mention the recommendation to dump stuff)

Comment on lines -870 to -873
#[cfg(windows)]
pub fn get_sig_quit(&self) -> &Option<Arc<AtomicBool>> {
&None
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call removing that flag as it is never read.

Comment thread src/signals.rs
pub(crate) fn sigquit_protection(engine_state: &mut EngineState) {
use signal_hook::consts::SIGQUIT;
let sig_quit = Arc::new(AtomicBool::new(false));
signal_hook::flag::register(SIGQUIT, sig_quit.clone()).expect("Error setting SIGQUIT flag");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I read the signal_hook docs correctly this is a confusingly implicit way of in effect ignoring the default system handler

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, signal_hook::flag::register will prevent the default handler from running and instead sets the AtomicBool to true.

@IanManske

IanManske commented Dec 20, 2023 •

Copy link
Copy Markdown
Member Author

Not sure if we should do extra work for non-interactive uses

I don't think we have to. A SIGQUIT signal will cause a core dump by default on most? systems. E.g., I can make bash core dump:

⮞ bash -c 'sleep 100'
^\Quit: oops, process 'bash' core dumped
Error: nu::shell::external_command

  × External command failed
   ╭─[entry #1:1:1]
 1 │ bash -c 'sleep 100'
   · ──┬─
   ·   ╰── core dumped
   ╰────
  help: Quit: child process 'bash' core dumped

And now with this PR, also nushell:

⮞ ./target/debug/nu -n -c 'sleep 100sec'
^\Quit: oops, process './target/debug/nu' core dumped
Error: nu::shell::external_command

  × External command failed
   ╭─[entry #8:1:1]
 1 │ ./target/debug/nu -n -c 'sleep 100sec'
   · ────────┬────────
   ·         ╰── core dumped
   ╰────
  help: Quit: child process './target/debug/nu' core dumped

@sholderbach

Copy link
Copy Markdown
Member

OK, thanks for immediately investigating!

From my side I would be fine with landing this as is, as we reasoned about the impact and the testing was non-existent beforehand.

@IanManske

IanManske commented Dec 20, 2023 •

Copy link
Copy Markdown
Member Author

Ok, because we handle signals incorrectly in other places, this PR makes it so that SIGQUIT remains blocked for child processes launched from interactive mode. I can open another PR after this, or try to fix it in this one (and expand the scope of the PR).

@IanManske
IanManske marked this pull request as ready for review December 21, 2023 01:07
@sholderbach

Copy link
Copy Markdown
Member

Let's go with removing the unused flag and correctly setting the mask for interactive mode.
We can iterate on the rest.

@sholderbach
sholderbach merged commit 3a05086 into nushell:main Dec 21, 2023
@IanManske
IanManske deleted the simple-sigquit branch December 22, 2023 04:05
dmatos2012 pushed a commit to dmatos2012/nushell that referenced this pull request Feb 20, 2024
# Description
Simplifies `SIGQUIT` protection to a single `signal` ignore system call.

# User-Facing Changes
`SIGQUIT` is no longer blocked if nushell is in non-interactive mode
(signals should not be blocked in non-interactive mode).
Also a breaking API change for `nu_protocol`.

# Tests + Formatting
Should come after nushell#11178 for testing.
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.

2 participants