[ I don't have much experience with either readline or signals, so ]
[ please forgive any ignorance (or stupidity) on my part.  :)      ]


readline 7.0 is causing a bug[*] in Twinkle, where we are normally
blocking SIGALRM in all threads, with one thread dedicated to calling
sigwait().  Upon calling readline(), SIGALRM now apparently becomes
unblocked (or caught and rethrown, I guess), resulting in the program
aborting.  This was not the case with 6.3.

This has been reported and confirmed on Debian/Ubuntu (amd64) so far.


I'm attaching a small example that reproduces this behavior:

 $ gcc -o readline_sigalrm readline_sigalrm.c -lreadline -lpthread 
 $ ./readline_sigalrm
 > Alarm clock

Note that disabling rl_catch_signals doesn't have any effect on this.
(This probably wouldn't be a good solution for us anyway.)

(I also noticed that this only seemed to occur when readline() was
called from the main thread.  I suppose this could very well be
OS-specific, though.)


Please let me know if there's anything I can do to help.  Thanks!

 [*] https://github.com/LubosD/twinkle/issues/89

/*
 * With readline 7.0, this aborts after one second due to SIGALRM.
 */

#include <pthread.h>
#include <readline/readline.h>
#include <signal.h>
#include <sys/time.h>


/* Dedicated thread to catch SIGALRM */
void *sigwait_thread (void *arg) {
	sigset_t *sigset = arg;
	int sig;
	for (;;) sigwait(sigset, &sig);
}

int main() {
	/* Block SIGALRM */
	sigset_t sigset;
	sigemptyset(&sigset);
	sigaddset(&sigset, SIGALRM);
	pthread_sigmask(SIG_BLOCK, &sigset, NULL);

	/* Create and detach sigwait thread */
	pthread_t sigwait_tid;
	pthread_create(&sigwait_tid, NULL, sigwait_thread, &sigset);
	pthread_detach(sigwait_tid);

	/* Set up a 1-second recurring timer */
	struct itimerval itv = {{1, 0}, {1, 0}};
	setitimer(ITIMER_REAL, &itv, NULL);

	//rl_catch_signals = 0;  /* This would have no effect anyway */
	while (readline("> "));

	return 0;
}
_______________________________________________
Bug-readline mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-readline

Reply via email to