Skip to content

Commit

Permalink
build: move errExit macro into inline function
Browse files Browse the repository at this point in the history
Move most of the `errExit` macro into a new `_errExit` inline function
and use the former just to forward arguments to the latter.

This reduces the noise in the build output when using `-fanalyze`, as it
causes the `errExit` macro to stop being expanded.

For example, the complete output of the following warning in
src/firejail/dbus.c is reduced from 243 lines to 141 lines (a ~41%
reduction):

    $ pacman -Q gcc
    gcc 13.2.1-5
    $ ./configure --enable-analyzer --enable-apparmor >/dev/null &&
      make clean >/dev/null && make >/dev/null
    [...]
    ../../src/firejail/dbus.c: In function ‘dbus_proxy_start’:
    ../../src/firejail/dbus.c:311:36: warning: leak of file descriptor ‘dup2(output_fd, 1)’ [CWE-775] [-Wanalyzer-fd-leak]
      311 |                                 if (dup2(output_fd, STDOUT_FILENO) != STDOUT_FILENO)
    [...]
             ‘dbus_create_user_dir’: event 5
               |
               |../../src/firejail/../include/common.h:42:25:
               |   42 | #define errExit(msg) do { \
               |      |                         ^
               |      |                         |
               |      |                         (5) ...to here
    ../../src/firejail/dbus.c:239:17: note: in expansion of macro ‘errExit’
               |  239 |                 errExit("asprintf");
               |      |                 ^~~~~~~
    [...]

Relates to #6190.
  • Loading branch information
kmk3 committed Feb 19, 2024
1 parent 092bb0a commit a696391
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@
// dbus proxy path used by firejail and firemon
#define XDG_DBUS_PROXY_PATH "/usr/bin/xdg-dbus-proxy"

#define errExit(msg) do { \
char msgout[500]; \
snprintf(msgout, 500, "Error %s:%d: %s: %s", \
__FILE__, __LINE__, __func__, msg); \
perror(msgout); \
exit(1); \
} while (0)
#define errExit(msg) _errExit(__FILE__, __LINE__, __func__, msg)

static inline void __attribute__((noreturn))
_errExit(const char *fname, int lineno, const char *func, const char *msg) {
char msgout[500];
snprintf(msgout, 500, "Error %s:%d: %s: %s", fname, lineno, func, msg);
perror(msgout);
exit(1);
}

// macro to print ip addresses in a printf statement
#define PRINT_IP(A) \
Expand Down

0 comments on commit a696391

Please sign in to comment.