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
190f83db
Unverified
Commit
190f83db
authored
Apr 14, 2021
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lxccontainer: fix container creation error paths
Fixes: #3782 Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
c4142ec2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
25 deletions
+15
-25
lxccontainer.c
src/lxc/lxccontainer.c
+15
-25
No files found.
src/lxc/lxccontainer.c
View file @
190f83db
...
@@ -1775,21 +1775,19 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t,
...
@@ -1775,21 +1775,19 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t,
const
char
*
bdevtype
,
struct
bdev_specs
*
specs
,
const
char
*
bdevtype
,
struct
bdev_specs
*
specs
,
int
flags
,
char
*
const
argv
[])
int
flags
,
char
*
const
argv
[])
{
{
__do_free
char
*
path_template
=
NULL
;
int
partial_fd
;
int
partial_fd
;
mode_t
mask
;
mode_t
mask
;
pid_t
pid
;
pid_t
pid
;
bool
ret
=
false
,
rootfs_managed
=
true
;
bool
ret
=
false
,
rootfs_managed
=
true
;
char
*
tpath
=
NULL
;
if
(
!
c
)
if
(
!
c
)
return
false
;
return
false
;
if
(
t
)
{
if
(
t
)
{
tpath
=
get_template_path
(
t
);
path_template
=
get_template_path
(
t
);
if
(
!
tpath
)
{
if
(
!
path_template
)
ERROR
(
"Unknown template
\"
%s
\"
"
,
t
);
return
syserror_set
(
ENOENT
,
"Template
\"
%s
\"
not found"
,
t
);
goto
out
;
}
}
}
/* If a template is passed in, and the rootfs already is defined in the
/* If a template is passed in, and the rootfs already is defined in the
...
@@ -1797,22 +1795,16 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t,
...
@@ -1797,22 +1795,16 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t,
* existing container. Return an error, but do NOT delete the container.
* existing container. Return an error, but do NOT delete the container.
*/
*/
if
(
do_lxcapi_is_defined
(
c
)
&&
c
->
lxc_conf
&&
c
->
lxc_conf
->
rootfs
.
path
&&
if
(
do_lxcapi_is_defined
(
c
)
&&
c
->
lxc_conf
&&
c
->
lxc_conf
->
rootfs
.
path
&&
access
(
c
->
lxc_conf
->
rootfs
.
path
,
F_OK
)
==
0
&&
tpath
)
{
access
(
c
->
lxc_conf
->
rootfs
.
path
,
F_OK
)
==
0
&&
path_template
)
ERROR
(
"Container
\"
%s
\"
already exists in
\"
%s
\"
"
,
c
->
name
,
return
syserror_set
(
EEXIST
,
"Container
\"
%s
\"
already exists in
\"
%s
\"
"
,
c
->
name
,
c
->
config_path
);
c
->
config_path
);
goto
free_tpath
;
}
if
(
!
c
->
lxc_conf
)
{
if
(
!
c
->
lxc_conf
&&
if
(
!
do_lxcapi_load_config
(
c
,
lxc_global_config_value
(
"lxc.default_config"
)))
{
!
do_lxcapi_load_config
(
c
,
lxc_global_config_value
(
"lxc.default_config"
)))
ERROR
(
"Error loading default configuration file %s"
,
return
syserror_set
(
EINVAL
,
"Failed to load default configuration file %s"
,
lxc_global_config_value
(
"lxc.default_config"
));
lxc_global_config_value
(
"lxc.default_config"
));
goto
free_tpath
;
}
}
if
(
!
create_container_dir
(
c
))
if
(
!
create_container_dir
(
c
))
goto
free_tpath
;
return
syserror_set
(
EINVAL
,
"Failed to create container %s"
,
c
->
name
)
;
if
(
c
->
lxc_conf
->
rootfs
.
path
)
if
(
c
->
lxc_conf
->
rootfs
.
path
)
rootfs_managed
=
false
;
rootfs_managed
=
false
;
...
@@ -1821,7 +1813,7 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t,
...
@@ -1821,7 +1813,7 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t,
* rootfs.path. The container is already created if we have a config and
* rootfs.path. The container is already created if we have a config and
* rootfs.path is accessible
* rootfs.path is accessible
*/
*/
if
(
!
c
->
lxc_conf
->
rootfs
.
path
&&
!
tpath
)
{
if
(
!
c
->
lxc_conf
->
rootfs
.
path
&&
!
path_template
)
{
/* No template passed in and rootfs does not exist. */
/* No template passed in and rootfs does not exist. */
if
(
!
c
->
save_config
(
c
,
NULL
))
{
if
(
!
c
->
save_config
(
c
,
NULL
))
{
ERROR
(
"Failed to save initial config for
\"
%s
\"
"
,
c
->
name
);
ERROR
(
"Failed to save initial config for
\"
%s
\"
"
,
c
->
name
);
...
@@ -1835,7 +1827,7 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t,
...
@@ -1835,7 +1827,7 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t,
if
(
c
->
lxc_conf
->
rootfs
.
path
&&
access
(
c
->
lxc_conf
->
rootfs
.
path
,
F_OK
)
!=
0
)
if
(
c
->
lxc_conf
->
rootfs
.
path
&&
access
(
c
->
lxc_conf
->
rootfs
.
path
,
F_OK
)
!=
0
)
goto
out
;
goto
out
;
if
(
do_lxcapi_is_defined
(
c
)
&&
c
->
lxc_conf
->
rootfs
.
path
&&
!
tpath
)
{
if
(
do_lxcapi_is_defined
(
c
)
&&
c
->
lxc_conf
->
rootfs
.
path
&&
!
path_template
)
{
/* Rootfs already existed, user just wanted to save the loaded
/* Rootfs already existed, user just wanted to save the loaded
* configuration.
* configuration.
*/
*/
...
@@ -1901,7 +1893,7 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t,
...
@@ -1901,7 +1893,7 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t,
if
(
!
load_config_locked
(
c
,
c
->
configfile
))
if
(
!
load_config_locked
(
c
,
c
->
configfile
))
goto
out_unlock
;
goto
out_unlock
;
if
(
!
create_run_template
(
c
,
tpath
,
!!
(
flags
&
LXC_CREATE_QUIET
),
argv
))
if
(
!
create_run_template
(
c
,
path_template
,
!!
(
flags
&
LXC_CREATE_QUIET
),
argv
))
goto
out_unlock
;
goto
out_unlock
;
/* Now clear out the lxc_conf we have, reload from the created
/* Now clear out the lxc_conf we have, reload from the created
...
@@ -1910,7 +1902,7 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t,
...
@@ -1910,7 +1902,7 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t,
do_lxcapi_clear_config
(
c
);
do_lxcapi_clear_config
(
c
);
if
(
t
)
{
if
(
t
)
{
if
(
!
prepend_lxc_header
(
c
->
configfile
,
tpath
,
argv
))
{
if
(
!
prepend_lxc_header
(
c
->
configfile
,
path_template
,
argv
))
{
ERROR
(
"Failed to prepend header to config file"
);
ERROR
(
"Failed to prepend header to config file"
);
goto
out_unlock
;
goto
out_unlock
;
}
}
...
@@ -1936,8 +1928,6 @@ out:
...
@@ -1936,8 +1928,6 @@ out:
c
->
lxc_conf
->
rootfs
.
managed
=
reset_managed
;
c
->
lxc_conf
->
rootfs
.
managed
=
reset_managed
;
}
}
free_tpath
:
free
(
tpath
);
return
ret
;
return
ret
;
}
}
...
...
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