chiark / gitweb /
tree-wide: when %m is used in log_*, always specify errno explicitly
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 13 May 2017 15:26:55 +0000 (11:26 -0400)
committerSven Eden <yamakuzure@gmx.net>
Tue, 25 Jul 2017 07:46:52 +0000 (09:46 +0200)
All those uses were correct, but I think it's better to be explicit.
Using implicit errno is too error prone, and with this change we can require
(in the sense of a style guideline) that the code is always specified.

Helpful query: git grep -n -P 'log_[^s][a-z]+\(.*%m'

src/basic/selinux-util.c
src/core/cgroup.c

index 79ce6a856fd6e8eb1fdfd16076d2fd9ffe1a3db3..41c8297f9b53e6aa9a54b60b6a9ebd65988bad2a 100644 (file)
@@ -50,10 +50,10 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(context_t, context_free);
 static int cached_use = -1;
 static struct selabel_handle *label_hnd = NULL;
 
 static int cached_use = -1;
 static struct selabel_handle *label_hnd = NULL;
 
-#define log_enforcing(...) log_full(security_getenforce() == 1 ? LOG_ERR : LOG_DEBUG, __VA_ARGS__)
+#define log_enforcing(...) log_full_errno(security_getenforce() == 1 ? LOG_ERR : LOG_DEBUG, errno, __VA_ARGS__)
 #endif
 
 #endif
 
-bool mac_selinux_use(void) {
+bool mac_selinux_have(void) {
 #ifdef HAVE_SELINUX
         if (cached_use < 0)
                 cached_use = is_selinux_enabled() > 0;
 #ifdef HAVE_SELINUX
         if (cached_use < 0)
                 cached_use = is_selinux_enabled() > 0;
@@ -64,6 +64,16 @@ bool mac_selinux_use(void) {
 #endif
 }
 
 #endif
 }
 
+bool mac_selinux_use(void) {
+        if (!mac_selinux_have())
+                return false;
+
+        /* Never try to configure SELinux features if we aren't
+         * root */
+
+        return getuid() == 0;
+}
+
 void mac_selinux_retest(void) {
 #ifdef HAVE_SELINUX
         cached_use = -1;
 void mac_selinux_retest(void) {
 #ifdef HAVE_SELINUX
         cached_use = -1;
@@ -196,7 +206,7 @@ int mac_selinux_get_create_label_from_exe(const char *exe, char **label) {
         assert(exe);
         assert(label);
 
         assert(exe);
         assert(label);
 
-        if (!mac_selinux_use())
+        if (!mac_selinux_have())
                 return -EOPNOTSUPP;
 
         r = getcon_raw(&mycon);
                 return -EOPNOTSUPP;
 
         r = getcon_raw(&mycon);
@@ -222,7 +232,7 @@ int mac_selinux_get_our_label(char **label) {
         assert(label);
 
 #ifdef HAVE_SELINUX
         assert(label);
 
 #ifdef HAVE_SELINUX
-        if (!mac_selinux_use())
+        if (!mac_selinux_have())
                 return -EOPNOTSUPP;
 
         r = getcon_raw(label);
                 return -EOPNOTSUPP;
 
         r = getcon_raw(label);
@@ -246,7 +256,7 @@ int mac_selinux_get_child_mls_label(int socket_fd, const char *exe, const char *
         assert(exe);
         assert(label);
 
         assert(exe);
         assert(label);
 
-        if (!mac_selinux_use())
+        if (!mac_selinux_have())
                 return -EOPNOTSUPP;
 
         r = getcon_raw(&mycon);
                 return -EOPNOTSUPP;
 
         r = getcon_raw(&mycon);
@@ -301,7 +311,7 @@ char* mac_selinux_free(char *label) {
         if (!label)
                 return NULL;
 
         if (!label)
                 return NULL;
 
-        if (!mac_selinux_use())
+        if (!mac_selinux_have())
                 return NULL;
 
 
                 return NULL;
 
 
index bda1d53499ddde46fa83820222484f9ed3635e88..9fa81eaaa811e907f9ac67b47ae319a22be496cc 100644 (file)
@@ -399,8 +399,7 @@ static int whitelist_major(const char *path, const char *name, char type, const
         return 0;
 
 fail:
         return 0;
 
 fail:
-        log_warning_errno(errno, "Failed to read /proc/devices: %m");
-        return -errno;
+        return log_warning_errno(errno, "Failed to read /proc/devices: %m");
 }
 
 static bool cgroup_context_has_cpu_weight(CGroupContext *c) {
 }
 
 static bool cgroup_context_has_cpu_weight(CGroupContext *c) {