diff --git a/include/namespaces.h b/include/namespaces.h index 73af5202e..7e0f97fa3 100644 --- a/include/namespaces.h +++ b/include/namespaces.h @@ -9,9 +9,18 @@ struct cr_options; struct ns_desc { unsigned int cflag; char *str; + size_t len; }; +#define NS_DESC_ENTRY(_cflag, _str) \ + { \ + .cflag = _cflag, \ + .str = _str, \ + .len = sizeof(_str) - 1, \ + } + extern struct ns_desc pid_ns_desc; +extern struct ns_desc user_ns_desc; extern unsigned long current_ns_mask; int dump_namespaces(struct pid *pid, unsigned int ns_flags); diff --git a/ipc_ns.c b/ipc_ns.c index 8511fb801..0fd531189 100644 --- a/ipc_ns.c +++ b/ipc_ns.c @@ -938,7 +938,4 @@ int prepare_ipc_ns(int pid) return 0; } -struct ns_desc ipc_ns_desc = { - .cflag = CLONE_NEWIPC, - .str = "ipc", -}; +struct ns_desc ipc_ns_desc = NS_DESC_ENTRY(CLONE_NEWIPC, "ipc"); diff --git a/mount.c b/mount.c index 66e263c1f..5c40b0334 100644 --- a/mount.c +++ b/mount.c @@ -812,7 +812,4 @@ int mntns_collect_root(pid_t pid) return 0; } -struct ns_desc mnt_ns_desc = { - .cflag = CLONE_NEWNS, - .str = "mnt", -}; +struct ns_desc mnt_ns_desc = NS_DESC_ENTRY(CLONE_NEWNS, "mnt"); diff --git a/namespaces.c b/namespaces.c index a182d4087..5b1b57536 100644 --- a/namespaces.c +++ b/namespaces.c @@ -313,7 +313,5 @@ int try_show_namespaces(int ns_pid, struct cr_options *o) return 0; } -struct ns_desc pid_ns_desc = { - .cflag = CLONE_NEWPID, - .str = "pid", -}; +struct ns_desc pid_ns_desc = NS_DESC_ENTRY(CLONE_NEWPID, "pid"); +struct ns_desc user_ns_desc = NS_DESC_ENTRY(CLONE_NEWUSER, "user"); diff --git a/net.c b/net.c index 19c23f640..456f4bbfb 100644 --- a/net.c +++ b/net.c @@ -404,7 +404,4 @@ void network_unlock(void) run_scripts("network-unlock"); } -struct ns_desc net_ns_desc = { - .cflag = CLONE_NEWNET, - .str = "net", -}; +struct ns_desc net_ns_desc = NS_DESC_ENTRY(CLONE_NEWNET, "net"); diff --git a/uts_ns.c b/uts_ns.c index dec80e885..985c6442b 100644 --- a/uts_ns.c +++ b/uts_ns.c @@ -70,7 +70,4 @@ void show_utsns(int fd) pb_show_vertical(fd, PB_UTSNS); } -struct ns_desc uts_ns_desc = { - .cflag = CLONE_NEWUTS, - .str = "uts", -}; +struct ns_desc uts_ns_desc = NS_DESC_ENTRY(CLONE_NEWUTS, "uts");