1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 #include "alloc-util.h"
6 #include "extract-word.h"
8 #include "string-util.h"
10 const struct namespace_flag_map namespace_flag_map[] = {
11 { CLONE_NEWCGROUP, "cgroup" },
12 { CLONE_NEWIPC, "ipc" },
13 { CLONE_NEWNET, "net" },
14 /* So, the mount namespace flag is called CLONE_NEWNS for historical reasons. Let's expose it here under a more
15 * explanatory name: "mnt". This is in-line with how the kernel exposes namespaces in /proc/$PID/ns. */
16 { CLONE_NEWNS, "mnt" },
17 { CLONE_NEWPID, "pid" },
18 { CLONE_NEWUSER, "user" },
19 { CLONE_NEWUTS, "uts" },
24 #if 0 /// UNNEEDED by elogind
25 int namespace_flags_from_string(const char *name, unsigned long *ret) {
26 unsigned long flags = 0;
32 _cleanup_free_ char *word = NULL;
36 r = extract_first_word(&name, &word, NULL, 0);
42 for (i = 0; namespace_flag_map[i].name; i++)
43 if (streq(word, namespace_flag_map[i].name)) {
44 f = namespace_flag_map[i].flag;
59 int namespace_flags_to_string(unsigned long flags, char **ret) {
60 _cleanup_free_ char *s = NULL;
63 for (i = 0; namespace_flag_map[i].name; i++) {
64 if ((flags & namespace_flag_map[i].flag) != namespace_flag_map[i].flag)
67 if (!strextend_with_separator(&s, " ", namespace_flag_map[i].name, NULL))