chiark / gitweb /
logind: properly write user state files
[elogind.git] / src / label.c
index 09ded642fb1d51003230b09e41e484ae0dd48209..b7bb03322fbc49693d8d7069a66ba523833ec862 100644 (file)
@@ -22,6 +22,7 @@
 #include <errno.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <malloc.h>
 
 #include "label.h"
 #include "util.h"
@@ -47,6 +48,8 @@ int label_init(void) {
         int r = 0;
 
 #ifdef HAVE_SELINUX
+        usec_t n;
+        struct mallinfo before;
 
         if (!use_selinux())
                 return 0;
@@ -54,11 +57,27 @@ int label_init(void) {
         if (label_hnd)
                 return 0;
 
+        before = mallinfo();
+        n = now(CLOCK_MONOTONIC);
+
         label_hnd = selabel_open(SELABEL_CTX_FILE, NULL, 0);
         if (!label_hnd) {
                 log_full(security_getenforce() == 1 ? LOG_ERR : LOG_DEBUG,
                          "Failed to initialize SELinux context: %m");
                 r = security_getenforce() == 1 ? -errno : 0;
+        } else  {
+                char buf[FORMAT_TIMESPAN_MAX];
+                struct mallinfo after;
+                int l;
+
+                n = now(CLOCK_MONOTONIC) - n;
+                after = mallinfo();
+
+                l = after.uordblks > before.uordblks ? after.uordblks - before.uordblks : 0;
+
+                log_info("Successfully loaded SELinux database in %s, size on heap is %iK.",
+                         format_timespan(buf, sizeof(buf), n),
+                         l/1024);
         }
 #endif
 
@@ -90,14 +109,14 @@ int label_fix(const char *path, bool ignore_enoent) {
                         /* If the FS doesn't support labels, then exit without warning */
                         if (r < 0 && errno == ENOTSUP)
                                 return 0;
-
-                        /* Ignore ENOENT in some cases */
-                        if (r < 0 && ignore_enoent && errno == ENOENT)
-                                return 0;
                 }
         }
 
         if (r < 0) {
+                /* Ignore ENOENT in some cases */
+                if (ignore_enoent && errno == ENOENT)
+                        return 0;
+
                 log_full(security_getenforce() == 1 ? LOG_ERR : LOG_DEBUG,
                          "Unable to fix label of %s: %m", path);
                 r = security_getenforce() == 1 ? -errno : 0;