Skip to content

Commit

Permalink
Prefer usage of mallinfo2 over mallinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
bbonev committed Dec 14, 2021
1 parent f8cf40c commit acbbfa8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ AC_SUBST(sushell)

# selinux-util.c uses struct mallinfo which is not available for all C libraries (musl).
AC_CHECK_FUNCS([mallinfo])
# mallinfo is deprecated, prefer to use mallinfo2 when available
AC_CHECK_FUNCS([mallinfo2])

# ------------------------------------------------------------------------------

Expand Down
16 changes: 12 additions & 4 deletions src/shared/selinux-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ int mac_selinux_init(const char *prefix) {
#ifdef HAVE_SELINUX
usec_t before_timestamp, after_timestamp;

#ifdef HAVE_MALLINFO
#ifdef HAVE_MALLINFO2
struct mallinfo2 before_mallinfo, after_mallinfo;
#elif HAVE_MALLINFO
struct mallinfo before_mallinfo, after_mallinfo;
#endif

Expand All @@ -79,7 +81,9 @@ int mac_selinux_init(const char *prefix) {
if (label_hnd)
return 0;

#ifdef HAVE_MALLINFO
#ifdef HAVE_MALLINFO2
before_mallinfo = mallinfo2();
#elif HAVE_MALLINFO
before_mallinfo = mallinfo();
#endif

Expand All @@ -100,15 +104,19 @@ int mac_selinux_init(const char *prefix) {
} else {
char timespan[FORMAT_TIMESPAN_MAX];

#ifdef HAVE_MALLINFO
#if defined(HAVE_MALLINFO)|defined(HAVE_MALLINFO2)
int l;
#endif

after_timestamp = now(CLOCK_MONOTONIC);

#ifdef HAVE_MALLINFO
#ifdef HAVE_MALLINFO2
after_mallinfo = mallinfo2();
#elif HAVE_MALLINFO
after_mallinfo = mallinfo();
#endif

#if defined(HAVE_MALLINFO)|defined(HAVE_MALLINFO2)
l = after_mallinfo.uordblks > before_mallinfo.uordblks ? after_mallinfo.uordblks - before_mallinfo.uordblks : 0;

log_debug("Successfully loaded SELinux database in %s, size on heap is %iK.",
Expand Down

0 comments on commit acbbfa8

Please sign in to comment.