selinux: avoid probing memory status if debug logs are not enabled
Given we are optimizing the selinux paths, avoid doing these operations unless the result is actually used
This commit is contained in:
+20
-12
@@ -104,28 +104,36 @@ void mac_selinux_retest(void) {
|
||||
#if HAVE_SELINUX
|
||||
static int open_label_db(void) {
|
||||
struct selabel_handle *hnd;
|
||||
usec_t before_timestamp, after_timestamp;
|
||||
|
||||
/* Avoid maybe-uninitialized false positives */
|
||||
usec_t before_timestamp = USEC_INFINITY, after_timestamp = USEC_INFINITY;
|
||||
# if HAVE_GENERIC_MALLINFO
|
||||
generic_mallinfo before_mallinfo = generic_mallinfo_get();
|
||||
generic_mallinfo before_mallinfo = {};
|
||||
# endif
|
||||
before_timestamp = now(CLOCK_MONOTONIC);
|
||||
|
||||
if (DEBUG_LOGGING) {
|
||||
# if HAVE_GENERIC_MALLINFO
|
||||
before_mallinfo = generic_mallinfo_get();
|
||||
# endif
|
||||
before_timestamp = now(CLOCK_MONOTONIC);
|
||||
}
|
||||
|
||||
hnd = selabel_open(SELABEL_CTX_FILE, NULL, 0);
|
||||
if (!hnd)
|
||||
return log_enforcing_errno(errno, "Failed to initialize SELinux labeling handle: %m");
|
||||
|
||||
after_timestamp = now(CLOCK_MONOTONIC);
|
||||
if (DEBUG_LOGGING) {
|
||||
after_timestamp = now(CLOCK_MONOTONIC);
|
||||
# if HAVE_GENERIC_MALLINFO
|
||||
generic_mallinfo after_mallinfo = generic_mallinfo_get();
|
||||
size_t l = LESS_BY((size_t) after_mallinfo.uordblks, (size_t) before_mallinfo.uordblks);
|
||||
log_debug("Successfully loaded SELinux database in %s, size on heap is %zuK.",
|
||||
FORMAT_TIMESPAN(after_timestamp - before_timestamp, 0),
|
||||
DIV_ROUND_UP(l, 1024));
|
||||
generic_mallinfo after_mallinfo = generic_mallinfo_get();
|
||||
size_t l = LESS_BY((size_t) after_mallinfo.uordblks, (size_t) before_mallinfo.uordblks);
|
||||
log_debug("Successfully loaded SELinux database in %s, size on heap is %zuK.",
|
||||
FORMAT_TIMESPAN(after_timestamp - before_timestamp, 0),
|
||||
DIV_ROUND_UP(l, 1024));
|
||||
# else
|
||||
log_debug("Successfully loaded SELinux database in %s.",
|
||||
FORMAT_TIMESPAN(after_timestamp - before_timestamp, 0));
|
||||
log_debug("Successfully loaded SELinux database in %s.",
|
||||
FORMAT_TIMESPAN(after_timestamp - before_timestamp, 0));
|
||||
# endif
|
||||
}
|
||||
|
||||
/* release memory after measurement */
|
||||
if (label_hnd)
|
||||
|
||||
Reference in New Issue
Block a user