top: only use 'pthread_sigmask' under separate threads
When multi-threading was introduced in the patch shown
below, the former calls to sigprocmask were traded for
a pthread_sigmask call. This was done unconditionally.
As a result, even when those threads weren't enabled a
need to link with libpthread was created. In hindsight
the need should only arise when top is multi-threaded.
This commit will make pthread_sigmask use conditional.
Reference(s):
. 09/2021, separate threads introduced
commit 29f0a674a8
Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
parent
0496b39876
commit
5d09875488
20
top/top.c
20
top/top.c
@ -365,9 +365,13 @@ static void bye_bye (const char *str) __attribute__((__noreturn__));
|
|||||||
static void bye_bye (const char *str) {
|
static void bye_bye (const char *str) {
|
||||||
sigset_t ss;
|
sigset_t ss;
|
||||||
|
|
||||||
// POSIX.1 async-signal-safe: sigfillset, pthread_sigmask
|
// POSIX.1 async-signal-safe: sigfillset, sigprocmask, pthread_sigmask
|
||||||
sigfillset(&ss);
|
sigfillset(&ss);
|
||||||
|
#if defined THREADED_CPU || defined THREADED_MEM || defined THREADED_TSK
|
||||||
pthread_sigmask(SIG_BLOCK, &ss, NULL);
|
pthread_sigmask(SIG_BLOCK, &ss, NULL);
|
||||||
|
#else
|
||||||
|
sigprocmask(SIG_BLOCK, &ss, NULL);
|
||||||
|
#endif
|
||||||
at_eoj(); // restore tty in preparation for exit
|
at_eoj(); // restore tty in preparation for exit
|
||||||
#ifdef ATEOJ_RPTSTD
|
#ifdef ATEOJ_RPTSTD
|
||||||
{
|
{
|
||||||
@ -497,16 +501,24 @@ static void sig_abexit (int sig) __attribute__((__noreturn__));
|
|||||||
static void sig_abexit (int sig) {
|
static void sig_abexit (int sig) {
|
||||||
sigset_t ss;
|
sigset_t ss;
|
||||||
|
|
||||||
// POSIX.1 async-signal-safe: sigfillset, signal, sigemptyset, sigaddset, pthread_sigmask, raise
|
// POSIX.1 async-signal-safe: sigfillset, signal, sigemptyset, sigaddset, sigprocmask, pthread_sigmask, raise
|
||||||
sigfillset(&ss);
|
sigfillset(&ss);
|
||||||
|
#if defined THREADED_CPU || defined THREADED_MEM || defined THREADED_TSK
|
||||||
pthread_sigmask(SIG_BLOCK, &ss, NULL);
|
pthread_sigmask(SIG_BLOCK, &ss, NULL);
|
||||||
|
#else
|
||||||
|
sigprocmask(SIG_BLOCK, &ss, NULL);
|
||||||
|
#endif
|
||||||
at_eoj(); // restore tty in preparation for exit
|
at_eoj(); // restore tty in preparation for exit
|
||||||
fprintf(stderr, N_fmt(EXIT_signals_fmt)
|
fprintf(stderr, N_fmt(EXIT_signals_fmt)
|
||||||
, sig, signal_number_to_name(sig), Myname);
|
, sig, signal_number_to_name(sig), Myname);
|
||||||
signal(sig, SIG_DFL); // allow core dumps, if applicable
|
signal(sig, SIG_DFL); // allow core dumps, if applicable
|
||||||
sigemptyset(&ss);
|
sigemptyset(&ss);
|
||||||
sigaddset(&ss, sig);
|
sigaddset(&ss, sig);
|
||||||
|
#if defined THREADED_CPU || defined THREADED_MEM || defined THREADED_TSK
|
||||||
pthread_sigmask(SIG_UNBLOCK, &ss, NULL);
|
pthread_sigmask(SIG_UNBLOCK, &ss, NULL);
|
||||||
|
#else
|
||||||
|
sigprocmask(SIG_UNBLOCK, &ss, NULL);
|
||||||
|
#endif
|
||||||
raise(sig); // ( plus set proper return code )
|
raise(sig); // ( plus set proper return code )
|
||||||
_exit(EXIT_FAILURE); // if default sig action is ignore
|
_exit(EXIT_FAILURE); // if default sig action is ignore
|
||||||
} // end: sig_abexit
|
} // end: sig_abexit
|
||||||
@ -3370,10 +3382,12 @@ static void before (char *me) {
|
|||||||
if ((rc = procps_pids_new(&Pids_ctx, Pids_itms, Pids_itms_tot)))
|
if ((rc = procps_pids_new(&Pids_ctx, Pids_itms, Pids_itms_tot)))
|
||||||
error_exit(fmtmk(N_fmt(LIB_errorpid_fmt),__LINE__, strerror(-rc)));
|
error_exit(fmtmk(N_fmt(LIB_errorpid_fmt),__LINE__, strerror(-rc)));
|
||||||
|
|
||||||
/* in case any of our threads have neen enabled, they'll inherit this mask
|
#if defined THREADED_CPU || defined THREADED_MEM || defined THREADED_TSK
|
||||||
|
/* in case any of our threads have been enabled, they'll inherit this mask
|
||||||
with everything blocked. therefore, signals go to the main thread (us). */
|
with everything blocked. therefore, signals go to the main thread (us). */
|
||||||
sigfillset(&sa.sa_mask);
|
sigfillset(&sa.sa_mask);
|
||||||
pthread_sigmask(SIG_BLOCK, &sa.sa_mask, NULL);
|
pthread_sigmask(SIG_BLOCK, &sa.sa_mask, NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef THREADED_CPU
|
#ifdef THREADED_CPU
|
||||||
if (0 != sem_init(&Semaphore_cpus_beg, 0, 0)
|
if (0 != sem_init(&Semaphore_cpus_beg, 0, 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user