2026-05-18 Bruno Haible <bruno@clisp.org>
+ term-style-control: Make multithread-safe, part 4: Redirect signals.
+ * lib/term-style-control.c (active_thread): New variable.
+ (fatal_signal_handler, stopping_signal_handler): Redirect the signal
+ from the current thread to the active_thread.
+ (activate_term_non_default_mode): Initialize active_thread.
+ (deactivate_term_non_default_mode): Reset active_thread to NULL.
+
term-style-control: Make multithread-safe, part 3: Use sigdelay.
* lib/term-style-control.h (struct term_style_control_data): Add field
'multithreaded'.
: -1). */
static int volatile active_fd = -1;
+#if HAVE_POSIX_THREADS
+/* The thread to which the active controller is attached, (pthread_t) 0
+ otherwise. */
+static pthread_t volatile active_thread;
+#endif
+
/* The exit handler. */
static void
atexit_handler (void)
fatal_signal_handler (int sig)
{
log_signal_handler_called (sig);
- fatal_or_stopping_signal_handler (sig);
+ #if HAVE_POSIX_THREADS
+ pthread_t target_thread = active_thread;
+ if (target_thread != pthread_self ())
+ {
+ if (target_thread != (pthread_t) 0)
+ {
+ pthread_kill (target_thread, sig);
+ return;
+ }
+ log_message ("target_thread is NULL. Not calling fatal_or_stopping_signal_handler!\n");
+ }
+ else
+ #endif
+ {
+ fatal_or_stopping_signal_handler (sig);
+ }
}
#if defined SIGCONT
int saved_errno = errno;
log_signal_handler_called (sig);
- fatal_or_stopping_signal_handler (sig);
+ #if HAVE_POSIX_THREADS
+ pthread_t target_thread = active_thread;
+ if (target_thread != pthread_self ())
+ {
+ if (target_thread != (pthread_t) 0)
+ {
+ pthread_kill (target_thread, sig);
+ return;
+ }
+ log_message ("target_thread is NULL. Not calling fatal_or_stopping_signal_handler!\n");
+ }
+ else
+ #endif
+ {
+ fatal_or_stopping_signal_handler (sig);
+ }
/* Now execute the signal's default action.
We reinstall the handler later, during the SIGCONT handler. */
we set active_controller to a non-NULL value only after the memory
locations active_user_data, active_control_data, active_fd have been
filled. */
+ #if HAVE_POSIX_THREADS
+ active_thread = pthread_self ();
+ #endif
active_fd = control_data->fd;
active_control_data = control_data;
active_user_data = user_data;
active_user_data = NULL;
active_control_data = NULL;
active_fd = -1;
+ #if HAVE_POSIX_THREADS
+ active_thread = (pthread_t) 0;
+ #endif
#if BLOCK_SIGNALS_DURING_NON_DEFAULT_STYLE_OUTPUT
/* Unblock the relevant signals. */