Commit 3c93577b by Marek Majkowski

Create --share-ipc option

parent d4afa440
......@@ -58,6 +58,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
<arg choice="opt">-s KEY=VAL</arg>
<arg choice="opt">-C</arg>
<arg choice="opt">--share-net <replaceable>name|pid</replaceable></arg>
<arg choice="opt">--share-ipc <replaceable>name|pid</replaceable></arg>
<arg choice="opt">command</arg>
</cmdsynopsis>
</refsynopsisdiv>
......@@ -203,6 +204,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--share-ipc <replaceable>name|pid</replaceable></option>
</term>
<listitem>
<para>
Inherit an IPC namespace from
a <replaceable>name</replaceable> container or
a <replaceable>pid</replaceable>.
</para>
</listitem>
</varlistentry>
......
......@@ -55,6 +55,7 @@ struct lxc_arguments {
/* for lxc-start */
const char *share_net;
const char *share_ipc;
/* for lxc-checkpoint/restart */
const char *statefile;
......
......@@ -52,6 +52,7 @@
#include "arguments.h"
#define OPT_SHARE_NET OPT_USAGE+1
#define OPT_SHARE_IPC OPT_USAGE+2
lxc_log_define(lxc_start_ui, lxc_start);
......@@ -146,6 +147,7 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
case 's': return lxc_config_define_add(&defines, arg);
case 'p': args->pidfile = arg; break;
case OPT_SHARE_NET: args->share_net = arg; break;
case OPT_SHARE_IPC: args->share_ipc = arg; break;
}
return 0;
}
......@@ -159,6 +161,7 @@ static const struct option my_longopts[] = {
{"close-all-fds", no_argument, 0, 'C'},
{"pidfile", required_argument, 0, 'p'},
{"share-net", required_argument, 0, OPT_SHARE_NET},
{"share-ipc", required_argument, 0, OPT_SHARE_IPC},
LXC_COMMON_OPTIONS
};
......@@ -181,6 +184,7 @@ Options :\n\
Note: --daemon implies --close-all-fds\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\
",
.options = my_longopts,
.parser = my_parser,
......@@ -308,6 +312,17 @@ int main(int argc, char *argv[])
conf->inherit_ns_fd[LXC_NS_NET] = fd;
}
if (my_args.share_ipc != NULL) {
int pid = pid_from_lxcname(my_args.share_ipc, lxcpath);
if (pid < 1)
goto out;
int fd = open_ns(pid, "ipc");
if (fd < 0)
goto out;
conf->inherit_ns_fd[LXC_NS_IPC] = fd;
}
if (my_args.daemonize) {
c->want_daemonize(c);
}
......
......@@ -727,7 +727,7 @@ int lxc_spawn(struct lxc_handler *handler)
if (lxc_sync_init(handler))
return -1;
handler->clone_flags = CLONE_NEWUTS|CLONE_NEWPID|CLONE_NEWIPC|CLONE_NEWNS;
handler->clone_flags = CLONE_NEWUTS|CLONE_NEWPID|CLONE_NEWNS;
if (!lxc_list_empty(&handler->conf->id_map)) {
INFO("Cloning a new user namespace");
handler->clone_flags |= CLONE_NEWUSER;
......@@ -766,6 +766,12 @@ int lxc_spawn(struct lxc_handler *handler)
INFO("Inheriting a net namespace");
}
if (handler->conf->inherit_ns_fd[LXC_NS_IPC] == -1) {
handler->clone_flags |= CLONE_NEWIPC;
} else {
INFO("Inheriting an IPC namespace");
}
cgroup_meta = lxc_cgroup_load_meta();
if (!cgroup_meta) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment