diff options
Diffstat (limited to 'src/basic/namespace-util.c')
-rw-r--r-- | src/basic/namespace-util.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/basic/namespace-util.c b/src/basic/namespace-util.c index 53633c7e8f..0e54a1e235 100644 --- a/src/basic/namespace-util.c +++ b/src/basic/namespace-util.c @@ -426,3 +426,19 @@ int parse_userns_uid_range(const char *s, uid_t *ret_uid_shift, uid_t *ret_uid_r return 0; } + +int namespace_open_by_type(NamespaceType type) { + const char *p; + int fd; + + assert(type >= 0); + assert(type < _NAMESPACE_TYPE_MAX); + + p = pid_namespace_path(0, type); + + fd = RET_NERRNO(open(p, O_RDONLY|O_NOCTTY|O_CLOEXEC)); + if (fd == -ENOENT && proc_mounted() == 0) + return -ENOSYS; + + return fd; +} |