]> granicus.if.org Git - procps-ng/commitdiff
top: only use 'pthread_sigmask' under separate threads
authorJim Warner <james.warner@comcast.net>
Thu, 14 Oct 2021 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@dropbear.xyz>
Mon, 18 Oct 2021 06:38:43 +0000 (17:38 +1100)
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 29f0a674a85bfb92443c56f070956a7dd60bb5f7

Signed-off-by: Jim Warner <james.warner@comcast.net>
top/top.c

index 94a1ff87174d81ea077c5d3f141951909123bf2d..97d12a5f1729b65a10e216638d582bf651df3101 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -365,9 +365,13 @@ static void bye_bye (const char *str) __attribute__((__noreturn__));
 static void bye_bye (const char *str) {
    sigset_t ss;
 
-// POSIX.1 async-signal-safe: sigfillset, pthread_sigmask
+// POSIX.1 async-signal-safe: sigfillset, sigprocmask, pthread_sigmask
    sigfillset(&ss);
+#if defined THREADED_CPU || defined THREADED_MEM || defined THREADED_TSK
    pthread_sigmask(SIG_BLOCK, &ss, NULL);
+#else
+   sigprocmask(SIG_BLOCK, &ss, NULL);
+#endif
    at_eoj();                 // restore tty in preparation for exit
 #ifdef ATEOJ_RPTSTD
 {
@@ -497,16 +501,24 @@ static void sig_abexit (int sig) __attribute__((__noreturn__));
 static void sig_abexit (int sig) {
    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);
+#if defined THREADED_CPU || defined THREADED_MEM || defined THREADED_TSK
    pthread_sigmask(SIG_BLOCK, &ss, NULL);
+#else
+   sigprocmask(SIG_BLOCK, &ss, NULL);
+#endif
    at_eoj();                 // restore tty in preparation for exit
    fprintf(stderr, N_fmt(EXIT_signals_fmt)
       , sig, signal_number_to_name(sig), Myname);
    signal(sig, SIG_DFL);     // allow core dumps, if applicable
    sigemptyset(&ss);
    sigaddset(&ss, sig);
+#if defined THREADED_CPU || defined THREADED_MEM || defined THREADED_TSK
    pthread_sigmask(SIG_UNBLOCK, &ss, NULL);
+#else
+   sigprocmask(SIG_UNBLOCK, &ss, NULL);
+#endif
    raise(sig);               // ( plus set proper return code )
    _exit(EXIT_FAILURE);      // if default sig action is ignore
 } // end: sig_abexit
@@ -3370,10 +3382,12 @@ static void before (char *me) {
    if ((rc = procps_pids_new(&Pids_ctx, Pids_itms, Pids_itms_tot)))
       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). */
    sigfillset(&sa.sa_mask);
    pthread_sigmask(SIG_BLOCK, &sa.sa_mask, NULL);
+#endif
 
 #ifdef THREADED_CPU
    if (0 != sem_init(&Semaphore_cpus_beg, 0, 0)