kmod: conditionalize kmod setup on CAP_SYS_MODULE, not whether we run in a container
authorLennart Poettering <lennart@poettering.net>
Tue, 17 Jun 2014 01:23:23 +0000 (03:23 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 17 Jun 2014 01:26:40 +0000 (03:26 +0200)
It's generally preferrable to conditionalize on the actual ability to do
something then the context we run in.

src/core/kmod-setup.c
src/core/main.c

index 0791ae8..2f3f608 100644 (file)
@@ -27,7 +27,7 @@
 
 #include "macro.h"
 #include "execute.h"
-
+#include "capability.h"
 #include "kmod-setup.h"
 
 static void systemd_kmod_log(
@@ -54,6 +54,7 @@ static bool cmdline_check_kdbus(void) {
 }
 
 int kmod_setup(void) {
+
         static const struct {
                 const char *module;
                 const char *path;
@@ -76,6 +77,9 @@ int kmod_setup(void) {
         unsigned int i;
         int r;
 
+        if (have_effective_cap(CAP_SYS_MODULE) == 0)
+                return 0;
+
         for (i = 0; i < ELEMENTSOF(kmod_table); i++) {
                 struct kmod_module *mod;
 
index 4ad3bc2..899233b 100644 (file)
@@ -1589,8 +1589,7 @@ int main(int argc, char *argv[]) {
                         status_welcome();
 
 #ifdef HAVE_KMOD
-                if (detect_container(NULL) <= 0)
-                        kmod_setup();
+                kmod_setup();
 #endif
                 hostname_setup();
                 machine_id_setup("");