-
-
Notifications
You must be signed in to change notification settings - Fork 240
patch libedit to stop re-broadcasting signals #652
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
Conversation
|
Opened a ticket upstream, will see if we get any comments: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=287452 |
|
@zoulasc I would love your take on this, this looks like a bug dating from the original 4.4BSD version of libedit :) Briefly, our understanding is that libedit never puts the terminal into I suspect that, at least for an interactive shell, it's uncommon for it to be sharing its pgrp with anyone, and so The patch in this PR changes to |
|
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=159226 also looks like someone noticing this issue, judging from the patch, though they are running into a seemingly different problem. FreeBSD seems to now use snapshots of libedit from some other upstream, presumably NetBSD. |
|
Changed to use raise(signo). Thanks! |
geofft
left a comment
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.
Thanks, Christos! That means the Thrysoee libedit distribution will pick this up soon enough so I feel very comfortable merging this.
|
NetBSD has taken this change upstream 🎉 https://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libedit/sig.c?rev=1.29 |
I've been investigating astral-sh/uv#13919, and I believe I've traced it to some questionable behavior in libedit, but I genuinely don't know where to report that. We might want to patch it as in this PR, but even if not I wanted some place to write all this down so we can reference it.
Our standalone build substitutes libedit for libreadline on Linux. It turns out that libedit has some funny signal handling behavior. Here's a minimized repro. First, a toy C program that we can link against either libreadline or libedit, call it
test.c:Now, a wrapper Rust program that starts the C program (or anything else you give it on the command line), signals it (currently
SIGTERM, butSIGINTbehaves the same in these examples if you edit it in), and waits for it to exit, listening for signals the whole time:If I link the C code against libreadline and run it, nothing is amiss (libreadline also clears its prompt when signaled, which is neat). Here's me doing it on Arch Linux, with both
readlineandlibeditinstalled:However, if I link the C code against libedit, the wrapper process catches a signal (libedit also doesn't clear its prompt, but that doesn't matter):
Similarly, if I comment out the
libc::killcall in the wrapper and use ^C myself in the terminal, the wrapper usually catchesSIGINTonce as expected, but occasionally it catchesSIGINTtwice:The origin of this behavior is the
sig_handlerfunction in libedit'ssig.c, which re-broadcasts all(?) signals to the entire pgroup. Even though we're working around the originaluv^C issue in a different way at the same time (astral-sh/uv#13925), this is pretty weird behavior, and we might want to consider patching it. I have some comments and speculation about why the behavior is there, inline above the patch.You can use the same wrapper program with our existing standalone builds, putting the
libc::killback in (though note that Python 3.13 no longer uses readline/libedit unless you setPYTHON_BASIC_REPL=1):After running
./build-linux.shwith this patched version ofcpython-unix/build-libedit.shand untar'ing the result, I've confirmed that the misguided signal is gone:@geofft I'm curious to get your thoughts about this. Have you seen it before? It's obscure enough that we might decide that fixing it isn't worth the trouble of maintaining the patch, but I at least wanted to write all this down. It also seems like something I should report upstream, but again I'm not sure where...FreeBSD?