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
345a035c
Unverified
Commit
345a035c
authored
Feb 19, 2018
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
start: lxc_init()
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
bba8123b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
29 deletions
+58
-29
start.c
src/lxc/start.c
+58
-29
No files found.
src/lxc/start.c
View file @
345a035c
...
...
@@ -719,55 +719,84 @@ int lxc_init(const char *name, struct lxc_handler *handler)
struct
lxc_conf
*
conf
=
handler
->
conf
;
lsm_init
();
TRACE
(
"
i
nitialized LSM"
);
TRACE
(
"
I
nitialized LSM"
);
if
(
lxc_read_seccomp_config
(
conf
)
!=
0
)
{
ERROR
(
"Failed loading seccomp policy."
);
ret
=
lxc_read_seccomp_config
(
conf
);
if
(
ret
<
0
)
{
ERROR
(
"Failed loading seccomp policy"
);
goto
out_close_maincmd_fd
;
}
TRACE
(
"
r
ead seccomp policy"
);
TRACE
(
"
R
ead seccomp policy"
);
/* Begin by setting the state to STARTING. */
if
(
lxc_set_state
(
name
,
handler
,
STARTING
))
{
ERROR
(
"Failed to set state for container
\"
%s
\"
to
\"
%s
\"
."
,
name
,
lxc_state2str
(
STARTING
));
ret
=
lxc_set_state
(
name
,
handler
,
STARTING
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to set state to
\"
%s
\"
"
,
lxc_state2str
(
STARTING
));
goto
out_close_maincmd_fd
;
}
TRACE
(
"set container state to
\"
STARTING
\"
"
);
/* Start of environment variable setup for hooks. */
if
(
name
&&
setenv
(
"LXC_NAME"
,
name
,
1
))
SYSERROR
(
"Failed to set environment variable: LXC_NAME=%s."
,
name
);
if
(
name
)
{
ret
=
setenv
(
"LXC_NAME"
,
name
,
1
);
if
(
ret
<
0
)
SYSERROR
(
"Failed to set environment variable: LXC_NAME=%s"
,
name
);
}
if
(
conf
->
rcfile
&&
setenv
(
"LXC_CONFIG_FILE"
,
conf
->
rcfile
,
1
))
SYSERROR
(
"Failed to set environment variable: LXC_CONFIG_FILE=%s."
,
conf
->
rcfile
);
if
(
conf
->
rcfile
)
{
ret
=
setenv
(
"LXC_CONFIG_FILE"
,
conf
->
rcfile
,
1
);
if
(
ret
<
0
)
SYSERROR
(
"Failed to set environment variable: "
"LXC_CONFIG_FILE=%s"
,
conf
->
rcfile
);
}
if
(
conf
->
rootfs
.
mount
&&
setenv
(
"LXC_ROOTFS_MOUNT"
,
conf
->
rootfs
.
mount
,
1
))
SYSERROR
(
"Failed to set environment variable: LXC_ROOTFS_MOUNT=%s."
,
conf
->
rootfs
.
mount
);
if
(
conf
->
rootfs
.
mount
)
{
ret
=
setenv
(
"LXC_ROOTFS_MOUNT"
,
conf
->
rootfs
.
mount
,
1
);
if
(
ret
<
0
)
SYSERROR
(
"Failed to set environment variable: "
"LXC_ROOTFS_MOUNT=%s"
,
conf
->
rootfs
.
mount
);
}
if
(
conf
->
rootfs
.
path
&&
setenv
(
"LXC_ROOTFS_PATH"
,
conf
->
rootfs
.
path
,
1
))
SYSERROR
(
"Failed to set environment variable: LXC_ROOTFS_PATH=%s."
,
conf
->
rootfs
.
path
);
if
(
conf
->
rootfs
.
path
)
{
ret
=
setenv
(
"LXC_ROOTFS_PATH"
,
conf
->
rootfs
.
path
,
1
);
if
(
ret
<
0
)
SYSERROR
(
"Failed to set environment variable: "
"LXC_ROOTFS_PATH=%s"
,
conf
->
rootfs
.
path
);
}
if
(
conf
->
console
.
path
&&
setenv
(
"LXC_CONSOLE"
,
conf
->
console
.
path
,
1
))
SYSERROR
(
"Failed to set environment variable: LXC_CONSOLE=%s."
,
conf
->
console
.
path
);
if
(
conf
->
console
.
path
)
{
ret
=
setenv
(
"LXC_CONSOLE"
,
conf
->
console
.
path
,
1
);
if
(
ret
<
0
)
SYSERROR
(
"Failed to set environment variable: "
"LXC_CONSOLE=%s"
,
conf
->
console
.
path
);
}
if
(
conf
->
console
.
log_path
&&
setenv
(
"LXC_CONSOLE_LOGPATH"
,
conf
->
console
.
log_path
,
1
))
SYSERROR
(
"Failed to set environment variable: LXC_CONSOLE_LOGPATH=%s."
,
conf
->
console
.
log_path
);
if
(
conf
->
console
.
log_path
)
{
ret
=
setenv
(
"LXC_CONSOLE_LOGPATH"
,
conf
->
console
.
log_path
,
1
);
if
(
ret
<
0
)
SYSERROR
(
"Failed to set environment variable: "
"LXC_CONSOLE_LOGPATH=%s"
,
conf
->
console
.
log_path
);
}
if
(
setenv
(
"LXC_CGNS_AWARE"
,
"1"
,
1
))
SYSERROR
(
"Failed to set environment variable LXC_CGNS_AWARE=1."
);
if
(
cgns_supported
())
{
ret
=
setenv
(
"LXC_CGNS_AWARE"
,
"1"
,
1
);
if
(
ret
<
0
)
SYSERROR
(
"Failed to set environment variable "
"LXC_CGNS_AWARE=1"
);
}
loglevel
=
lxc_log_priority_to_string
(
lxc_log_get_level
());
if
(
setenv
(
"LXC_LOG_LEVEL"
,
loglevel
,
1
))
SYSERROR
(
"Failed to set environment variable LXC_LOG_LEVEL=%s"
,
loglevel
);
/* End of environment variable setup for hooks. */
TRACE
(
"
s
et environment variables"
);
TRACE
(
"
S
et environment variables"
);
if
(
run_lxc_hooks
(
name
,
"pre-start"
,
conf
,
handler
->
lxcpath
,
NULL
))
{
ERROR
(
"Failed to run lxc.hook.pre-start for container
\"
%s
\"
."
,
name
);
ret
=
run_lxc_hooks
(
name
,
"pre-start"
,
conf
,
handler
->
lxcpath
,
NULL
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to run lxc.hook.pre-start for container
\"
%s
\"
"
,
name
);
goto
out_aborting
;
}
TRACE
(
"
r
an pre-start hooks"
);
TRACE
(
"
R
an pre-start hooks"
);
/* The signal fd has to be created before forking otherwise if the child
* process exits before we setup the signal fd, the event will be lost
...
...
@@ -778,7 +807,7 @@ int lxc_init(const char *name, struct lxc_handler *handler)
ERROR
(
"Failed to setup SIGCHLD fd handler."
);
goto
out_delete_tty
;
}
TRACE
(
"
s
et up signal fd"
);
TRACE
(
"
S
et up signal fd"
);
/* Do this after setting up signals since it might unblock SIGWINCH. */
ret
=
lxc_console_create
(
conf
);
...
...
@@ -790,12 +819,12 @@ int lxc_init(const char *name, struct lxc_handler *handler)
ret
=
lxc_pty_map_ids
(
conf
,
&
conf
->
console
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to
shift tty into container.
"
);
ERROR
(
"Failed to
chown console
"
);
goto
out_restore_sigmask
;
}
TRACE
(
"
shifted tty ids
"
);
TRACE
(
"
Chowned console
"
);
INFO
(
"
c
ontainer
\"
%s
\"
is initialized"
,
name
);
INFO
(
"
C
ontainer
\"
%s
\"
is initialized"
,
name
);
return
0
;
out_restore_sigmask:
...
...
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