-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
wip: feat: terminate jq immediately after the outgoing pipe closed #1703
base: master
Are you sure you want to change the base?
Conversation
{ | ||
#ifndef WIN32 | ||
signal(SIGPIPE, SIG_IGN); | ||
fprintf(stderr, "jq: error: received SIGPIPE\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fprintf
is not async-signal-safe, so it can't be used from a signal handler.
#ifndef WIN32 | ||
signal(SIGPIPE, SIG_IGN); | ||
fprintf(stderr, "jq: error: received SIGPIPE\n"); | ||
exit(128 + SIGPIPE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exit()
is not async-signal-safe, so it can't be used from a signal handler. Use _exit()
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If and when we add an FFI this (exiting in a signal handler) will probably not be a safe thing to do.
See also commentary in #1285. |
This should work. In reality, this does compile, but doesn't function when I actually try to emit SIGPIPE by doing:
My understanding is that the missing command
foo
should immediately result in SIGPIPE on the jq command, so thatthis feature terminates jq immediately.
I'd greatly appreciate it if anyone could share your insight on how I could make it actually work 🙏
Resolves #1691