Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show error message when processes are killed by SIGSEGV/SIGILL/etc #12874

Open
tgross35 opened this issue May 15, 2024 · 3 comments
Open

Show error message when processes are killed by SIGSEGV/SIGILL/etc #12874

tgross35 opened this issue May 15, 2024 · 3 comments
Labels
enhancement New feature or request error-handling How errors in externals/nu code are caught or handled programmatically (see also unhelpful-error) external-commands Issues related to external commands

Comments

@tgross35
Copy link

tgross35 commented May 15, 2024

Related problem

Nushell currently does not print anything when a program is terminated by a signal:

> echo "int main() { asm("ud2"); }" out> sigill.c
> gcc sigill.c -o sigill.out
> ./sigill.out
> # *crickets*
> echo "int main() { int v = *((int *)0x0); }" out> sigsegv.c
> gcc sigsegv.c -o sigsegv.out
> ./sigsegv.out
> # *crickets*

This could be okay if you have the exit code displayed as part of the prompt, but if you don't then it looks like everything completed successfully.

By contrast, Bash tells you what went wrong:

$ ./sigill.out
Illegal instruction
$ ./sigsegv.out
Segmentation fault

Describe the solution you'd like

If a signal is the reason a program exits prematurely, print the associated comment so the user is aware of the problem (available at https://man7.org/linux/man-pages/man7/signal.7.html "Standard signals" table), or the same for the Windows equivalent. This can be retrieved on nix with ExitStatusExt::signal.

Describe alternatives you've considered

No response

Additional context and details

No response

@tgross35 tgross35 added enhancement New feature or request needs-triage An issue that hasn't had any proper look labels May 15, 2024
@sholderbach
Copy link
Member

Related challenge #12369 (not a duplicate)

@IanManske built some parts to potentially fix this in #12774 if I recall, I tried some things in #12370 but that did not work yet.

@sholderbach sholderbach added external-commands Issues related to external commands error-handling How errors in externals/nu code are caught or handled programmatically (see also unhelpful-error) and removed needs-triage An issue that hasn't had any proper look labels May 15, 2024
@sholderbach
Copy link
Member

With #12774 we now properly pull out the signal but don't report the error as mentioned here (I think we had code for that at some point.) The $env.LAST_EXIT_CODE contains the signal value in negated form (which I think is not the conventional form. If I recall on Linux it is signal value + 128?)

@tgross35
Copy link
Author

Does nushell not use std::process::Command? If so, the signal is available with .signal() under the ExitSignalExt trait (which calls libc::WIFSIGNALED(self.0).then(|| libc::WTERMSIG(self.0)) internally)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request error-handling How errors in externals/nu code are caught or handled programmatically (see also unhelpful-error) external-commands Issues related to external commands
Projects
None yet
Development

No branches or pull requests

2 participants