Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
18b3b9c1
Unverified
Commit
18b3b9c1
authored
Dec 10, 2017
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
start: pass namespaces as environment variables
Unblocks #2013. Unblocks #2015. Closes #1766. Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
3f60c2f7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
18 deletions
+52
-18
lxc.container.conf.sgml.in
doc/lxc.container.conf.sgml.in
+10
-0
namespace.c
src/lxc/namespace.c
+7
-7
namespace.h
src/lxc/namespace.h
+1
-0
start.c
src/lxc/start.c
+34
-11
No files found.
doc/lxc.container.conf.sgml.in
View file @
18b3b9c1
...
...
@@ -1674,6 +1674,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
used. </para></listitem>
<listitem><para> LXC_LOG_LEVEL: the container's log level. </para></listitem>
<listitem><para> LXC_NAME: is the container's name. </para></listitem>
<listitem><para> LXC_[NAMESPACE IDENTIFIER]_NS: path under
/proc/PID/fd/ to a file descriptor referring to the container's
namespace. For each preserved namespace type there will be a separate
environment variable. These environment variables will only be set if
<option>lxc.hook.version</option> is set to 1. </para></listitem>
<listitem><para> LXC_ROOTFS_MOUNT: the path to the mounted root filesystem. </para></listitem>
<listitem><para> LXC_ROOTFS_PATH: this is the lxc.rootfs.path entry
for the container. Note this is likely not where the mounted rootfs is
...
...
@@ -1705,6 +1710,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
independently of the value used for this config item.) The section
will be set in LXC_HOOK_SECTION and the hook type will be set in
LXC_HOOK_TYPE.
It also affects how the paths to file descriptors referring to the
container's namespaces are passed. If set to 1 then for each
namespace a separate environment variable LXC_[NAMESPACE
IDENTIFIER]_NS will be set. If set to 0 then the paths will be
passed as arguments to the stop hook.
</para>
</listitem>
</varlistentry>
...
...
src/lxc/namespace.c
View file @
18b3b9c1
...
...
@@ -87,13 +87,13 @@ pid_t lxc_clone(int (*fn)(void *), void *arg, int flags)
* linux/fs/namespace.c:mntns_install().
*/
const
struct
ns_info
ns_info
[
LXC_NS_MAX
]
=
{
[
LXC_NS_USER
]
=
{
"user"
,
CLONE_NEWUSER
,
"CLONE_NEWUSER"
},
[
LXC_NS_MNT
]
=
{
"mnt"
,
CLONE_NEWNS
,
"CLONE_NEWNS"
},
[
LXC_NS_PID
]
=
{
"pid"
,
CLONE_NEWPID
,
"CLONE_NEWPID"
},
[
LXC_NS_UTS
]
=
{
"uts"
,
CLONE_NEWUTS
,
"CLONE_NEWUTS"
},
[
LXC_NS_IPC
]
=
{
"ipc"
,
CLONE_NEWIPC
,
"CLONE_NEWIPC"
},
[
LXC_NS_NET
]
=
{
"net"
,
CLONE_NEWNET
,
"CLONE_NEWNET"
},
[
LXC_NS_CGROUP
]
=
{
"cgroup"
,
CLONE_NEWCGROUP
,
"CLONE_NEWCGROUP"
}
[
LXC_NS_USER
]
=
{
"user"
,
CLONE_NEWUSER
,
"CLONE_NEWUSER"
,
"LXC_USER_NS"
},
[
LXC_NS_MNT
]
=
{
"mnt"
,
CLONE_NEWNS
,
"CLONE_NEWNS"
,
"LXC_MNT_NS"
},
[
LXC_NS_PID
]
=
{
"pid"
,
CLONE_NEWPID
,
"CLONE_NEWPID"
,
"LXC_PID_NS"
},
[
LXC_NS_UTS
]
=
{
"uts"
,
CLONE_NEWUTS
,
"CLONE_NEWUTS"
,
"LXC_UTS_NS"
},
[
LXC_NS_IPC
]
=
{
"ipc"
,
CLONE_NEWIPC
,
"CLONE_NEWIPC"
,
"LXC_IPC_NS"
},
[
LXC_NS_NET
]
=
{
"net"
,
CLONE_NEWNET
,
"CLONE_NEWNET"
,
"LXC_NET_NS"
},
[
LXC_NS_CGROUP
]
=
{
"cgroup"
,
CLONE_NEWCGROUP
,
"CLONE_NEWCGROUP"
,
"LXC_CGROUP_NS"
}
};
int
lxc_namespace_2_cloneflag
(
const
char
*
namespace
)
...
...
src/lxc/namespace.h
View file @
18b3b9c1
...
...
@@ -68,6 +68,7 @@ extern const struct ns_info {
const
char
*
proc_name
;
int
clone_flag
;
const
char
*
flag_name
;
const
char
*
env_name
;
}
ns_info
[
LXC_NS_MAX
];
#if defined(__ia64__)
...
...
src/lxc/start.c
View file @
18b3b9c1
...
...
@@ -716,8 +716,8 @@ out_close_maincmd_fd:
void
lxc_fini
(
const
char
*
name
,
struct
lxc_handler
*
handler
)
{
int
i
,
rc
;
pid_t
self
;
struct
lxc_list
*
cur
,
*
next
;
pid_t
self
=
getpid
();
char
*
namespaces
[
LXC_NS_MAX
+
1
];
size_t
namespace_count
=
0
;
...
...
@@ -726,16 +726,37 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
*/
lxc_set_state
(
name
,
handler
,
STOPPING
);
self
=
getpid
();
for
(
i
=
0
;
i
<
LXC_NS_MAX
;
i
++
)
{
if
(
handler
->
nsfd
[
i
]
!=
-
1
)
{
rc
=
asprintf
(
&
namespaces
[
namespace_count
],
"%s:/proc/%d/fd/%d"
,
ns_info
[
i
].
proc_name
,
self
,
handler
->
nsfd
[
i
]);
if
(
rc
==
-
1
)
{
SYSERROR
(
"Failed to allocate memory."
);
break
;
}
++
namespace_count
;
if
(
handler
->
nsfd
[
i
]
<
0
)
continue
;
if
(
handler
->
conf
->
hooks_version
==
0
)
rc
=
asprintf
(
&
namespaces
[
namespace_count
],
"%s:/proc/%d/fd/%d"
,
ns_info
[
i
].
proc_name
,
self
,
handler
->
nsfd
[
i
]);
else
rc
=
asprintf
(
&
namespaces
[
namespace_count
],
"/proc/%d/fd/%d"
,
self
,
handler
->
nsfd
[
i
]);
if
(
rc
==
-
1
)
{
SYSERROR
(
"Failed to allocate memory."
);
break
;
}
if
(
handler
->
conf
->
hooks_version
==
0
)
{
namespace_count
++
;
continue
;
}
rc
=
setenv
(
ns_info
[
i
].
env_name
,
namespaces
[
namespace_count
],
1
);
if
(
rc
<
0
)
SYSERROR
(
"Failed to set environment variable %s=%s"
,
ns_info
[
i
].
env_name
,
namespaces
[
namespace_count
]);
else
TRACE
(
"Set environment variable %s=%s"
,
ns_info
[
i
].
env_name
,
namespaces
[
namespace_count
]);
namespace_count
++
;
}
namespaces
[
namespace_count
]
=
NULL
;
...
...
@@ -745,8 +766,10 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
if
(
!
handler
->
conf
->
reboot
&&
setenv
(
"LXC_TARGET"
,
"stop"
,
1
))
SYSERROR
(
"Failed to set environment variable: LXC_TARGET=stop."
);
if
(
run_lxc_hooks
(
name
,
"stop"
,
handler
->
conf
,
handler
->
lxcpath
,
namespaces
))
ERROR
(
"Failed to run lxc.hook.stop for container
\"
%s
\"
."
,
name
);
if
(
handler
->
conf
->
hooks_version
==
0
)
rc
=
run_lxc_hooks
(
name
,
"stop"
,
handler
->
conf
,
handler
->
lxcpath
,
namespaces
);
else
rc
=
run_lxc_hooks
(
name
,
"stop"
,
handler
->
conf
,
handler
->
lxcpath
,
NULL
);
while
(
namespace_count
--
)
free
(
namespaces
[
namespace_count
]);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment