chiark / gitweb /
nspawn: make -U a tiny bit smarter
authorLennart Poettering <lennart@poettering.net>
Fri, 22 Apr 2016 12:10:09 +0000 (14:10 +0200)
committerSven Eden <yamakuzure@gmx.net>
Fri, 16 Jun 2017 08:12:58 +0000 (10:12 +0200)
With this change -U will turn on user namespacing only if the kernel actually
supports it and otherwise gracefully degrade to non-userns mode.

src/basic/user-util.h

index 8e652584d206e27e5c1a03d4b6455128bdc3899b..d010b2bf505606e0b1f1613bb743600279773fce 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <stdbool.h>
 #include <sys/types.h>
+#include <unistd.h>
 
 bool uid_is_valid(uid_t uid);
 
@@ -69,3 +70,7 @@ int take_etc_passwd_lock(const char *root);
 
 #define PTR_TO_GID(p) ((gid_t) (((uintptr_t) (p))-1))
 #define GID_TO_PTR(u) ((void*) (((uintptr_t) (u))+1))
+
+static inline bool userns_supported(void) {
+        return access("/proc/self/uid_map", F_OK) >= 0;
+}