From 5106b2ec404d4085cb4f741aeca9f2bdc95878a9 Mon Sep 17 00:00:00 2001 From: "Kelvin M. Klann" Date: Sun, 20 Jun 2021 18:31:12 -0300 Subject: gcov: use no-op functions if not enabled Instead of wrapping every gcov function call in an ifdef. Note: The usage of `((void)0)` is based on section 7.2 of the C99 standard (N1256)[1] [2]: > 7.2 Diagnostics > > 1 The header defines the assert macro and refers to another > macro, > > NDEBUG > > which is not defined by . If NDEBUG is defined as a macro > name at the point in the source file where is included, the > assert macro is defined simply as > > #define assert(ignore) ((void)0) See also assert.h(0p) from POSIX.1-2017[3]. Note: This is a continuation of commit b408b20c7 ("gcov: fix build failure with gcc 11.1.0") / PR #4373. [1] http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf [2] https://port70.net/~nsz/c/c99/n1256.html#7.2 [3] https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/assert.h.html --- src/firemon/interface.c | 9 +++------ src/firemon/netstats.c | 8 ++------ src/firemon/procevent.c | 7 +------ src/firemon/top.c | 8 ++------ 4 files changed, 8 insertions(+), 24 deletions(-) (limited to 'src/firemon') diff --git a/src/firemon/interface.c b/src/firemon/interface.c index 372cdee41..780e3d706 100644 --- a/src/firemon/interface.c +++ b/src/firemon/interface.c @@ -18,6 +18,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "firemon.h" +#include "../include/gcov_wrapper.h" #include #include #include @@ -33,10 +34,6 @@ //#include //#include -#ifdef HAVE_GCOV -#include "../include/gcov_wrapper.h" -#endif - // print IP addresses for all interfaces static void net_ifprint(void) { uint32_t ip; @@ -149,9 +146,9 @@ static void print_sandbox(pid_t pid) { if (rv) return; net_ifprint(); -#ifdef HAVE_GCOV + __gcov_flush(); -#endif + _exit(0); } diff --git a/src/firemon/netstats.c b/src/firemon/netstats.c index 205ad7601..9d8e5d7f5 100644 --- a/src/firemon/netstats.c +++ b/src/firemon/netstats.c @@ -18,16 +18,13 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "firemon.h" +#include "../include/gcov_wrapper.h" #include #include #include #include #include -#ifdef HAVE_GCOV -#include "../include/gcov_wrapper.h" -#endif - #define MAXBUF 4096 // ip -s link: device stats @@ -246,8 +243,7 @@ void netstats(void) { print_proc(i, itv, col); } } -#ifdef HAVE_GCOV + __gcov_flush(); -#endif } } diff --git a/src/firemon/procevent.c b/src/firemon/procevent.c index 79f487582..716a9cba4 100644 --- a/src/firemon/procevent.c +++ b/src/firemon/procevent.c @@ -18,6 +18,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "firemon.h" +#include "../include/gcov_wrapper.h" #include #include #include @@ -30,10 +31,6 @@ #include #include -#ifdef HAVE_GCOV -#include "../include/gcov_wrapper.h" -#endif - #define PIDS_BUFLEN 4096 #define SERVER_PORT 889 // 889-899 is left unassigned by IANA @@ -234,9 +231,7 @@ static void __attribute__((noreturn)) procevent_monitor(const int sock, pid_t my tv.tv_usec = 0; while (1) { -#ifdef HAVE_GCOV __gcov_flush(); -#endif #define BUFFSIZE 4096 char __attribute__ ((aligned(NLMSG_ALIGNTO)))buf[BUFFSIZE]; diff --git a/src/firemon/top.c b/src/firemon/top.c index 585fdcdab..2217cc7de 100644 --- a/src/firemon/top.c +++ b/src/firemon/top.c @@ -18,16 +18,13 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "firemon.h" +#include "../include/gcov_wrapper.h" #include #include #include #include #include -#ifdef HAVE_GCOV -#include "../include/gcov_wrapper.h" -#endif - static unsigned pgs_rss = 0; static unsigned pgs_shared = 0; static unsigned clocktick = 0; @@ -330,8 +327,7 @@ void top(void) { } } head_print(col, row); -#ifdef HAVE_GCOV + __gcov_flush(); -#endif } } -- cgit v1.2.3-54-g00ecf