mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-07-27 06:21:08 +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>
|
||||
</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>
|
||||
|
||||
</refsect1>
|
||||
|
@ -3141,10 +3141,12 @@ 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)
|
||||
{
|
||||
if (lxc_conf->inherit_ns_fd[LXC_NS_UTS] == -1) {
|
||||
if (setup_utsname(lxc_conf->utsname)) {
|
||||
ERROR("failed to setup the utsname for '%s'", name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (setup_network(&lxc_conf->network)) {
|
||||
ERROR("failed to setup the network for '%s'", name);
|
||||
|
@ -53,6 +53,7 @@
|
||||
|
||||
#define OPT_SHARE_NET OPT_USAGE+1
|
||||
#define OPT_SHARE_IPC OPT_USAGE+2
|
||||
#define OPT_SHARE_UTS OPT_USAGE+3
|
||||
|
||||
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 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_UTS: args->share_ns[LXC_NS_UTS] = arg; break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -167,6 +169,7 @@ static const struct option my_longopts[] = {
|
||||
{"pidfile", required_argument, 0, 'p'},
|
||||
{"share-net", required_argument, 0, OPT_SHARE_NET},
|
||||
{"share-ipc", required_argument, 0, OPT_SHARE_IPC},
|
||||
{"share-uts", required_argument, 0, OPT_SHARE_UTS},
|
||||
LXC_COMMON_OPTIONS
|
||||
};
|
||||
|
||||
@ -190,6 +193,7 @@ Options :\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-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,
|
||||
.parser = my_parser,
|
||||
|
@ -721,13 +721,13 @@ int lxc_spawn(struct lxc_handler *handler)
|
||||
int preserve_mask = 0, 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;
|
||||
|
||||
if (lxc_sync_init(handler))
|
||||
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)) {
|
||||
INFO("Cloning a new user namespace");
|
||||
handler->clone_flags |= CLONE_NEWUSER;
|
||||
@ -772,6 +772,12 @@ int lxc_spawn(struct lxc_handler *handler)
|
||||
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();
|
||||
if (!cgroup_meta) {
|
||||
|
Loading…
Reference in New Issue
Block a user