mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-07-27 10:51:24 +00:00
Make it possible to share UTS namespace
This commit is contained in:
parent
4692616518
commit
6c544cb300
@ -217,6 +217,21 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term>
|
||||||
|
<option>--share-uts <replaceable>name|pid</replaceable></option>
|
||||||
|
</term>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Inherit a UTS namespace from
|
||||||
|
a <replaceable>name</replaceable> container or
|
||||||
|
a <replaceable>pid</replaceable>. The starting LXC will
|
||||||
|
not set the hostname, but the container OS may do it
|
||||||
|
anyway.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
</variablelist>
|
</variablelist>
|
||||||
|
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
@ -3141,9 +3141,11 @@ int ttys_shift_ids(struct lxc_conf *c)
|
|||||||
|
|
||||||
int lxc_setup(const char *name, struct lxc_conf *lxc_conf, const char *lxcpath, struct cgroup_process_info *cgroup_info)
|
int lxc_setup(const char *name, struct lxc_conf *lxc_conf, const char *lxcpath, struct cgroup_process_info *cgroup_info)
|
||||||
{
|
{
|
||||||
if (setup_utsname(lxc_conf->utsname)) {
|
if (lxc_conf->inherit_ns_fd[LXC_NS_UTS] == -1) {
|
||||||
ERROR("failed to setup the utsname for '%s'", name);
|
if (setup_utsname(lxc_conf->utsname)) {
|
||||||
return -1;
|
ERROR("failed to setup the utsname for '%s'", name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setup_network(&lxc_conf->network)) {
|
if (setup_network(&lxc_conf->network)) {
|
||||||
|
@ -53,6 +53,7 @@
|
|||||||
|
|
||||||
#define OPT_SHARE_NET OPT_USAGE+1
|
#define OPT_SHARE_NET OPT_USAGE+1
|
||||||
#define OPT_SHARE_IPC OPT_USAGE+2
|
#define OPT_SHARE_IPC OPT_USAGE+2
|
||||||
|
#define OPT_SHARE_UTS OPT_USAGE+3
|
||||||
|
|
||||||
lxc_log_define(lxc_start_ui, lxc_start);
|
lxc_log_define(lxc_start_ui, lxc_start);
|
||||||
|
|
||||||
@ -153,6 +154,7 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
|
|||||||
case 'p': args->pidfile = arg; break;
|
case 'p': args->pidfile = arg; break;
|
||||||
case OPT_SHARE_NET: args->share_ns[LXC_NS_NET] = arg; break;
|
case OPT_SHARE_NET: args->share_ns[LXC_NS_NET] = arg; break;
|
||||||
case OPT_SHARE_IPC: args->share_ns[LXC_NS_IPC] = arg; break;
|
case OPT_SHARE_IPC: args->share_ns[LXC_NS_IPC] = arg; break;
|
||||||
|
case OPT_SHARE_UTS: args->share_ns[LXC_NS_UTS] = arg; break;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -167,6 +169,7 @@ static const struct option my_longopts[] = {
|
|||||||
{"pidfile", required_argument, 0, 'p'},
|
{"pidfile", required_argument, 0, 'p'},
|
||||||
{"share-net", required_argument, 0, OPT_SHARE_NET},
|
{"share-net", required_argument, 0, OPT_SHARE_NET},
|
||||||
{"share-ipc", required_argument, 0, OPT_SHARE_IPC},
|
{"share-ipc", required_argument, 0, OPT_SHARE_IPC},
|
||||||
|
{"share-uts", required_argument, 0, OPT_SHARE_UTS},
|
||||||
LXC_COMMON_OPTIONS
|
LXC_COMMON_OPTIONS
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -190,6 +193,7 @@ Options :\n\
|
|||||||
-s, --define KEY=VAL Assign VAL to configuration variable KEY\n\
|
-s, --define KEY=VAL Assign VAL to configuration variable KEY\n\
|
||||||
--share-net=NAME Share a network namespace with another container or pid\n\
|
--share-net=NAME Share a network namespace with another container or pid\n\
|
||||||
--share-ipc=NAME Share an IPC namespace with another container or pid\n\
|
--share-ipc=NAME Share an IPC namespace with another container or pid\n\
|
||||||
|
--share-uts=NAME Share a UTS namespace with another container or pid\n\
|
||||||
",
|
",
|
||||||
.options = my_longopts,
|
.options = my_longopts,
|
||||||
.parser = my_parser,
|
.parser = my_parser,
|
||||||
|
@ -721,13 +721,13 @@ int lxc_spawn(struct lxc_handler *handler)
|
|||||||
int preserve_mask = 0, i;
|
int preserve_mask = 0, i;
|
||||||
|
|
||||||
for (i = 0; i < LXC_NS_MAX; i++)
|
for (i = 0; i < LXC_NS_MAX; i++)
|
||||||
if (handler->conf->inherit_ns_fd[i] > -1)
|
if (handler->conf->inherit_ns_fd[i] != -1)
|
||||||
preserve_mask |= ns_info[i].clone_flag;
|
preserve_mask |= ns_info[i].clone_flag;
|
||||||
|
|
||||||
if (lxc_sync_init(handler))
|
if (lxc_sync_init(handler))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
handler->clone_flags = CLONE_NEWUTS|CLONE_NEWPID|CLONE_NEWNS;
|
handler->clone_flags = CLONE_NEWPID|CLONE_NEWNS;
|
||||||
if (!lxc_list_empty(&handler->conf->id_map)) {
|
if (!lxc_list_empty(&handler->conf->id_map)) {
|
||||||
INFO("Cloning a new user namespace");
|
INFO("Cloning a new user namespace");
|
||||||
handler->clone_flags |= CLONE_NEWUSER;
|
handler->clone_flags |= CLONE_NEWUSER;
|
||||||
@ -772,6 +772,12 @@ int lxc_spawn(struct lxc_handler *handler)
|
|||||||
INFO("Inheriting an IPC namespace");
|
INFO("Inheriting an IPC namespace");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (handler->conf->inherit_ns_fd[LXC_NS_UTS] == -1) {
|
||||||
|
handler->clone_flags |= CLONE_NEWUTS;
|
||||||
|
} else {
|
||||||
|
INFO("Inheriting a UTS namespace");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
cgroup_meta = lxc_cgroup_load_meta();
|
cgroup_meta = lxc_cgroup_load_meta();
|
||||||
if (!cgroup_meta) {
|
if (!cgroup_meta) {
|
||||||
|
Loading…
Reference in New Issue
Block a user