svn commit: r335310 - head/usr.bin/top

Eitan Adler eadler at FreeBSD.org
Mon Jun 18 02:06:17 UTC 2018


Author: eadler
Date: Mon Jun 18 02:06:16 2018
New Revision: 335310
URL: https://svnweb.freebsd.org/changeset/base/335310

Log:
  top(1): use more modern signal code
  
  Rather than manually build signal masks use functions designed for that
  reason. Also use sigprocmask instead of sigblock.

Modified:
  head/usr.bin/top/top.c

Modified: head/usr.bin/top/top.c
==============================================================================
--- head/usr.bin/top/top.c	Sun Jun 17 23:08:54 2018	(r335309)
+++ head/usr.bin/top/top.c	Mon Jun 18 02:06:16 2018	(r335310)
@@ -50,10 +50,6 @@ typedef void sigret_t;
 /* The buffer that stdio will use */
 static char stdoutbuf[Buffersize];
 
-/* build Signal masks */
-#define Smask(s)	(1 << ((s) - 1))
-
-
 static int fmt_flags = 0;
 int pcpu_stats = false;
 
@@ -233,7 +229,7 @@ main(int argc, char *argv[])
 
     static char tempbuf1[50];
     static char tempbuf2[50];
-    int old_sigmask;		/* only used for BSD-style signals */
+	sigset_t old_sigmask, new_sigmask;
     int topn = Infinity;
     double delay = 2;
     int displays = 0;		/* indicates unspecified */
@@ -591,13 +587,18 @@ main(int argc, char *argv[])
     }
 
     /* hold interrupt signals while setting up the screen and the handlers */
-    old_sigmask = sigblock(Smask(SIGINT) | Smask(SIGQUIT) | Smask(SIGTSTP));
+
+	sigemptyset(&new_sigmask);
+	sigaddset(&new_sigmask, SIGINT);
+	sigaddset(&new_sigmask, SIGQUIT);
+	sigaddset(&new_sigmask, SIGTSTP);
+	sigprocmask(SIG_BLOCK, &new_sigmask, &old_sigmask);
     init_screen();
     signal(SIGINT, leave);
     signal(SIGQUIT, leave);
     signal(SIGTSTP, tstop);
     signal(SIGWINCH, top_winch);
-    sigsetmask(old_sigmask);
+    sigprocmask(SIG_SETMASK, &old_sigmask, NULL);
     if (warnings)
     {
 	fputs("....", stderr);


More information about the svn-src-head mailing list