Skip to content

Commit

Permalink
build-sys: check for mallinfo
Browse files Browse the repository at this point in the history
mallinfo is not specified by POSIX or the C standards, therefore
it's not available for all libc libraries (musl).

Add the ability to disable mallinfo statistics.

Fixes:
selinux-util.c: In function ‘mac_selinux_init’:
selinux-util.c:70:25: error: storage size of ‘before_mallinfo’ isn’t known
         struct mallinfo before_mallinfo, after_mallinfo;

Signed-off-by: Romain Naour <romain.naour@openwide.fr>
  • Loading branch information
RomainNaour committed Jul 31, 2015
1 parent 019c458 commit 24ccb6e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions configure.ac
Expand Up @@ -223,6 +223,9 @@ else
fi
AC_SUBST(sushell)

# selinux-util.c uses struct mallinfo which is not available for all C libraries (musl).
AC_CHECK_FUNCS([mallinfo])

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

AC_CHECK_DECL([unshare],
Expand Down
15 changes: 15 additions & 0 deletions src/shared/selinux-util.c
Expand Up @@ -67,15 +67,21 @@ int mac_selinux_init(const char *prefix) {

#ifdef HAVE_SELINUX
usec_t before_timestamp, after_timestamp;

#ifdef HAVE_MALLINFO
struct mallinfo before_mallinfo, after_mallinfo;
#endif

if (!mac_selinux_use())
return 0;

if (label_hnd)
return 0;

#ifdef HAVE_MALLINFO
before_mallinfo = mallinfo();
#endif

before_timestamp = now(CLOCK_MONOTONIC);

if (prefix) {
Expand All @@ -92,16 +98,25 @@ int mac_selinux_init(const char *prefix) {
r = security_getenforce() == 1 ? -errno : 0;
} else {
char timespan[FORMAT_TIMESPAN_MAX];

#ifdef HAVE_MALLINFO
int l;
#endif

after_timestamp = now(CLOCK_MONOTONIC);

#ifdef HAVE_MALLINFO
after_mallinfo = mallinfo();

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.",
format_timespan(timespan, sizeof(timespan), after_timestamp - before_timestamp, 0),
(l+1023)/1024);
#else
log_debug("Successfully loaded SELinux database in %s",
format_timespan(timespan, sizeof(timespan), after_timestamp - before_timestamp, 0));
#endif
}
#endif

Expand Down

0 comments on commit 24ccb6e

Please sign in to comment.