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
f5849fd7
Unverified
Commit
f5849fd7
authored
Feb 05, 2019
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lxccontainer: remove stack allocations
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
f01d0358
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
31 deletions
+29
-31
lxccontainer.c
src/lxc/lxccontainer.c
+29
-31
No files found.
src/lxc/lxccontainer.c
View file @
f5849fd7
...
@@ -61,6 +61,7 @@
...
@@ -61,6 +61,7 @@
#include "lxc.h"
#include "lxc.h"
#include "lxccontainer.h"
#include "lxccontainer.h"
#include "lxclock.h"
#include "lxclock.h"
#include "memory_utils.h"
#include "monitor.h"
#include "monitor.h"
#include "namespace.h"
#include "namespace.h"
#include "network.h"
#include "network.h"
...
@@ -120,13 +121,13 @@ static bool do_lxcapi_save_config(struct lxc_container *c, const char *alt_file)
...
@@ -120,13 +121,13 @@ static bool do_lxcapi_save_config(struct lxc_container *c, const char *alt_file)
static
bool
config_file_exists
(
const
char
*
lxcpath
,
const
char
*
cname
)
static
bool
config_file_exists
(
const
char
*
lxcpath
,
const
char
*
cname
)
{
{
__do_free
char
*
fname
;
int
ret
;
int
ret
;
size_t
len
;
size_t
len
;
char
*
fname
;
/* $lxcpath + '/' + $cname + '/config' + \0 */
/* $lxcpath + '/' + $cname + '/config' + \0 */
len
=
strlen
(
lxcpath
)
+
strlen
(
cname
)
+
9
;
len
=
strlen
(
lxcpath
)
+
strlen
(
cname
)
+
9
;
fname
=
alloca
(
len
);
fname
=
must_realloc
(
NULL
,
len
);
ret
=
snprintf
(
fname
,
len
,
"%s/%s/config"
,
lxcpath
,
cname
);
ret
=
snprintf
(
fname
,
len
,
"%s/%s/config"
,
lxcpath
,
cname
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
len
)
if
(
ret
<
0
||
(
size_t
)
ret
>=
len
)
return
false
;
return
false
;
...
@@ -144,13 +145,13 @@ static bool config_file_exists(const char *lxcpath, const char *cname)
...
@@ -144,13 +145,13 @@ static bool config_file_exists(const char *lxcpath, const char *cname)
*/
*/
static
int
ongoing_create
(
struct
lxc_container
*
c
)
static
int
ongoing_create
(
struct
lxc_container
*
c
)
{
{
__do_free
char
*
path
;
int
fd
,
ret
;
int
fd
,
ret
;
size_t
len
;
size_t
len
;
char
*
path
;
struct
flock
lk
=
{
0
};
struct
flock
lk
=
{
0
};
len
=
strlen
(
c
->
config_path
)
+
strlen
(
c
->
name
)
+
10
;
len
=
strlen
(
c
->
config_path
)
+
strlen
(
c
->
name
)
+
10
;
path
=
alloca
(
len
);
path
=
must_realloc
(
NULL
,
len
);
ret
=
snprintf
(
path
,
len
,
"%s/%s/partial"
,
c
->
config_path
,
c
->
name
);
ret
=
snprintf
(
path
,
len
,
"%s/%s/partial"
,
c
->
config_path
,
c
->
name
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
len
)
if
(
ret
<
0
||
(
size_t
)
ret
>=
len
)
return
-
1
;
return
-
1
;
...
@@ -190,14 +191,14 @@ static int ongoing_create(struct lxc_container *c)
...
@@ -190,14 +191,14 @@ static int ongoing_create(struct lxc_container *c)
static
int
create_partial
(
struct
lxc_container
*
c
)
static
int
create_partial
(
struct
lxc_container
*
c
)
{
{
__do_free
char
*
path
;
int
fd
,
ret
;
int
fd
,
ret
;
size_t
len
;
size_t
len
;
char
*
path
;
struct
flock
lk
=
{
0
};
struct
flock
lk
=
{
0
};
/* $lxcpath + '/' + $name + '/partial' + \0 */
/* $lxcpath + '/' + $name + '/partial' + \0 */
len
=
strlen
(
c
->
config_path
)
+
strlen
(
c
->
name
)
+
10
;
len
=
strlen
(
c
->
config_path
)
+
strlen
(
c
->
name
)
+
10
;
path
=
alloca
(
len
);
path
=
must_realloc
(
NULL
,
len
);
ret
=
snprintf
(
path
,
len
,
"%s/%s/partial"
,
c
->
config_path
,
c
->
name
);
ret
=
snprintf
(
path
,
len
,
"%s/%s/partial"
,
c
->
config_path
,
c
->
name
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
len
)
if
(
ret
<
0
||
(
size_t
)
ret
>=
len
)
return
-
1
;
return
-
1
;
...
@@ -227,15 +228,15 @@ static int create_partial(struct lxc_container *c)
...
@@ -227,15 +228,15 @@ static int create_partial(struct lxc_container *c)
static
void
remove_partial
(
struct
lxc_container
*
c
,
int
fd
)
static
void
remove_partial
(
struct
lxc_container
*
c
,
int
fd
)
{
{
__do_free
char
*
path
;
int
ret
;
int
ret
;
size_t
len
;
size_t
len
;
char
*
path
;
close
(
fd
);
close
(
fd
);
/* $lxcpath + '/' + $name + '/partial' + \0 */
/* $lxcpath + '/' + $name + '/partial' + \0 */
len
=
strlen
(
c
->
config_path
)
+
strlen
(
c
->
name
)
+
10
;
len
=
strlen
(
c
->
config_path
)
+
strlen
(
c
->
name
)
+
10
;
path
=
alloca
(
len
);
path
=
must_realloc
(
NULL
,
len
);
ret
=
snprintf
(
path
,
len
,
"%s/%s/partial"
,
c
->
config_path
,
c
->
name
);
ret
=
snprintf
(
path
,
len
,
"%s/%s/partial"
,
c
->
config_path
,
c
->
name
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
len
)
if
(
ret
<
0
||
(
size_t
)
ret
>=
len
)
return
;
return
;
...
@@ -768,26 +769,22 @@ static void push_arg(char ***argp, char *arg, int *nargs)
...
@@ -768,26 +769,22 @@ static void push_arg(char ***argp, char *arg, int *nargs)
static
char
**
split_init_cmd
(
const
char
*
incmd
)
static
char
**
split_init_cmd
(
const
char
*
incmd
)
{
{
size_t
len
,
retlen
;
__do_free
char
*
copy
=
NULL
;
char
*
copy
,
*
p
;
char
*
p
;
char
**
argv
;
char
**
argv
;
int
nargs
=
0
;
int
nargs
=
0
;
if
(
!
incmd
)
if
(
!
incmd
)
return
NULL
;
return
NULL
;
len
=
strlen
(
incmd
)
+
1
;
copy
=
must_copy_string
(
incmd
);
copy
=
alloca
(
len
);
retlen
=
strlcpy
(
copy
,
incmd
,
len
);
if
(
retlen
>=
len
)
return
NULL
;
do
{
do
{
argv
=
malloc
(
sizeof
(
char
*
));
argv
=
malloc
(
sizeof
(
char
*
));
}
while
(
!
argv
);
}
while
(
!
argv
);
argv
[
0
]
=
NULL
;
argv
[
0
]
=
NULL
;
lxc_iterate_parts
(
p
,
copy
,
" "
)
lxc_iterate_parts
(
p
,
copy
,
" "
)
push_arg
(
&
argv
,
p
,
&
nargs
);
push_arg
(
&
argv
,
p
,
&
nargs
);
if
(
nargs
==
0
)
{
if
(
nargs
==
0
)
{
...
@@ -1209,9 +1206,9 @@ WRAP_API(bool, lxcapi_stop)
...
@@ -1209,9 +1206,9 @@ WRAP_API(bool, lxcapi_stop)
static
int
do_create_container_dir
(
const
char
*
path
,
struct
lxc_conf
*
conf
)
static
int
do_create_container_dir
(
const
char
*
path
,
struct
lxc_conf
*
conf
)
{
{
__do_free
char
*
p
=
NULL
;
int
lasterr
;
int
lasterr
;
size_t
len
;
size_t
len
;
char
*
p
;
int
ret
=
-
1
;
int
ret
=
-
1
;
mode_t
mask
=
umask
(
0002
);
mode_t
mask
=
umask
(
0002
);
...
@@ -1226,9 +1223,7 @@ static int do_create_container_dir(const char *path, struct lxc_conf *conf)
...
@@ -1226,9 +1223,7 @@ static int do_create_container_dir(const char *path, struct lxc_conf *conf)
ret
=
0
;
ret
=
0
;
}
}
len
=
strlen
(
path
);
p
=
must_copy_string
(
path
);
p
=
alloca
(
len
+
1
);
(
void
)
strlcpy
(
p
,
path
,
len
+
1
);
if
(
!
lxc_list_empty
(
&
conf
->
id_map
))
{
if
(
!
lxc_list_empty
(
&
conf
->
id_map
))
{
ret
=
chown_mapped_root
(
p
,
conf
);
ret
=
chown_mapped_root
(
p
,
conf
);
...
@@ -1270,9 +1265,9 @@ static struct lxc_storage *do_storage_create(struct lxc_container *c,
...
@@ -1270,9 +1265,9 @@ static struct lxc_storage *do_storage_create(struct lxc_container *c,
const
char
*
type
,
const
char
*
type
,
struct
bdev_specs
*
specs
)
struct
bdev_specs
*
specs
)
{
{
__do_free
char
*
dest
;
int
ret
;
int
ret
;
size_t
len
;
size_t
len
;
char
*
dest
;
struct
lxc_storage
*
bdev
;
struct
lxc_storage
*
bdev
;
/* rootfs.path or lxcpath/lxcname/rootfs */
/* rootfs.path or lxcpath/lxcname/rootfs */
...
@@ -1280,12 +1275,12 @@ static struct lxc_storage *do_storage_create(struct lxc_container *c,
...
@@ -1280,12 +1275,12 @@ static struct lxc_storage *do_storage_create(struct lxc_container *c,
(
access
(
c
->
lxc_conf
->
rootfs
.
path
,
F_OK
)
==
0
))
{
(
access
(
c
->
lxc_conf
->
rootfs
.
path
,
F_OK
)
==
0
))
{
const
char
*
rpath
=
c
->
lxc_conf
->
rootfs
.
path
;
const
char
*
rpath
=
c
->
lxc_conf
->
rootfs
.
path
;
len
=
strlen
(
rpath
)
+
1
;
len
=
strlen
(
rpath
)
+
1
;
dest
=
alloca
(
len
);
dest
=
must_realloc
(
NULL
,
len
);
ret
=
snprintf
(
dest
,
len
,
"%s"
,
rpath
);
ret
=
snprintf
(
dest
,
len
,
"%s"
,
rpath
);
}
else
{
}
else
{
const
char
*
lxcpath
=
do_lxcapi_get_config_path
(
c
);
const
char
*
lxcpath
=
do_lxcapi_get_config_path
(
c
);
len
=
strlen
(
c
->
name
)
+
strlen
(
lxcpath
)
+
9
;
len
=
strlen
(
c
->
name
)
+
strlen
(
lxcpath
)
+
9
;
dest
=
alloca
(
len
);
dest
=
must_realloc
(
NULL
,
len
);
ret
=
snprintf
(
dest
,
len
,
"%s/%s/rootfs"
,
lxcpath
,
c
->
name
);
ret
=
snprintf
(
dest
,
len
,
"%s/%s/rootfs"
,
lxcpath
,
c
->
name
);
}
}
if
(
ret
<
0
||
(
size_t
)
ret
>=
len
)
if
(
ret
<
0
||
(
size_t
)
ret
>=
len
)
...
@@ -3407,12 +3402,12 @@ err:
...
@@ -3407,12 +3402,12 @@ err:
static
int
copyhooks
(
struct
lxc_container
*
oldc
,
struct
lxc_container
*
c
)
static
int
copyhooks
(
struct
lxc_container
*
oldc
,
struct
lxc_container
*
c
)
{
{
__do_free
char
*
cpath
;
int
i
,
len
,
ret
;
int
i
,
len
,
ret
;
struct
lxc_list
*
it
;
struct
lxc_list
*
it
;
char
*
cpath
;
len
=
strlen
(
oldc
->
config_path
)
+
strlen
(
oldc
->
name
)
+
3
;
len
=
strlen
(
oldc
->
config_path
)
+
strlen
(
oldc
->
name
)
+
3
;
cpath
=
alloca
(
len
);
cpath
=
must_realloc
(
NULL
,
len
);
ret
=
snprintf
(
cpath
,
len
,
"%s/%s/"
,
oldc
->
config_path
,
oldc
->
name
);
ret
=
snprintf
(
cpath
,
len
,
"%s/%s/"
,
oldc
->
config_path
,
oldc
->
name
);
if
(
ret
<
0
||
ret
>=
len
)
if
(
ret
<
0
||
ret
>=
len
)
return
-
1
;
return
-
1
;
...
@@ -3570,13 +3565,14 @@ static bool add_rdepends(struct lxc_container *c, struct lxc_container *c0)
...
@@ -3570,13 +3565,14 @@ static bool add_rdepends(struct lxc_container *c, struct lxc_container *c0)
bool
should_default_to_snapshot
(
struct
lxc_container
*
c0
,
bool
should_default_to_snapshot
(
struct
lxc_container
*
c0
,
struct
lxc_container
*
c1
)
struct
lxc_container
*
c1
)
{
{
__do_free
char
*
p0
,
*
p1
;
int
ret
;
int
ret
;
size_t
l0
=
strlen
(
c0
->
config_path
)
+
strlen
(
c0
->
name
)
+
2
;
size_t
l0
=
strlen
(
c0
->
config_path
)
+
strlen
(
c0
->
name
)
+
2
;
size_t
l1
=
strlen
(
c1
->
config_path
)
+
strlen
(
c1
->
name
)
+
2
;
size_t
l1
=
strlen
(
c1
->
config_path
)
+
strlen
(
c1
->
name
)
+
2
;
char
*
p0
=
alloca
(
l0
+
1
);
char
*
p1
=
alloca
(
l1
+
1
);
char
*
rootfs
=
c0
->
lxc_conf
->
rootfs
.
path
;
char
*
rootfs
=
c0
->
lxc_conf
->
rootfs
.
path
;
p0
=
must_realloc
(
NULL
,
l0
+
1
);
p1
=
must_realloc
(
NULL
,
l1
+
1
);
ret
=
snprintf
(
p0
,
l0
,
"%s/%s"
,
c0
->
config_path
,
c0
->
name
);
ret
=
snprintf
(
p0
,
l0
,
"%s/%s"
,
c0
->
config_path
,
c0
->
name
);
if
(
ret
<
0
||
ret
>=
l0
)
if
(
ret
<
0
||
ret
>=
l0
)
return
false
;
return
false
;
...
@@ -4098,11 +4094,11 @@ static int lxcapi_attach_run_wait(struct lxc_container *c, lxc_attach_options_t
...
@@ -4098,11 +4094,11 @@ static int lxcapi_attach_run_wait(struct lxc_container *c, lxc_attach_options_t
static
int
get_next_index
(
const
char
*
lxcpath
,
char
*
cname
)
static
int
get_next_index
(
const
char
*
lxcpath
,
char
*
cname
)
{
{
char
*
fname
;
__do_free
char
*
fname
;
struct
stat
sb
;
struct
stat
sb
;
int
i
=
0
,
ret
;
int
i
=
0
,
ret
;
fname
=
alloca
(
strlen
(
lxcpath
)
+
20
);
fname
=
must_realloc
(
NULL
,
strlen
(
lxcpath
)
+
20
);
while
(
1
)
{
while
(
1
)
{
sprintf
(
fname
,
"%s/snap%d"
,
lxcpath
,
i
);
sprintf
(
fname
,
"%s/snap%d"
,
lxcpath
,
i
);
...
@@ -4148,6 +4144,7 @@ static bool get_snappath_dir(struct lxc_container *c, char *snappath)
...
@@ -4148,6 +4144,7 @@ static bool get_snappath_dir(struct lxc_container *c, char *snappath)
static
int
do_lxcapi_snapshot
(
struct
lxc_container
*
c
,
const
char
*
commentfile
)
static
int
do_lxcapi_snapshot
(
struct
lxc_container
*
c
,
const
char
*
commentfile
)
{
{
__do_free
char
*
dfnam
=
NULL
;
int
i
,
flags
,
ret
;
int
i
,
flags
,
ret
;
time_t
timer
;
time_t
timer
;
struct
tm
tm_info
;
struct
tm
tm_info
;
...
@@ -4211,7 +4208,7 @@ static int do_lxcapi_snapshot(struct lxc_container *c, const char *commentfile)
...
@@ -4211,7 +4208,7 @@ static int do_lxcapi_snapshot(struct lxc_container *c, const char *commentfile)
strftime
(
buffer
,
25
,
"%Y:%m:%d %H:%M:%S"
,
&
tm_info
);
strftime
(
buffer
,
25
,
"%Y:%m:%d %H:%M:%S"
,
&
tm_info
);
char
*
dfnam
=
alloca
(
strlen
(
snappath
)
+
strlen
(
newname
)
+
5
);
dfnam
=
must_realloc
(
NULL
,
strlen
(
snappath
)
+
strlen
(
newname
)
+
5
);
sprintf
(
dfnam
,
"%s/%s/ts"
,
snappath
,
newname
);
sprintf
(
dfnam
,
"%s/%s/ts"
,
snappath
,
newname
);
f
=
fopen
(
dfnam
,
"w"
);
f
=
fopen
(
dfnam
,
"w"
);
if
(
!
f
)
{
if
(
!
f
)
{
...
@@ -4232,10 +4229,11 @@ static int do_lxcapi_snapshot(struct lxc_container *c, const char *commentfile)
...
@@ -4232,10 +4229,11 @@ static int do_lxcapi_snapshot(struct lxc_container *c, const char *commentfile)
}
}
if
(
commentfile
)
{
if
(
commentfile
)
{
__do_free
char
*
path
;
/* $p / $name / comment \0 */
/* $p / $name / comment \0 */
int
len
=
strlen
(
snappath
)
+
strlen
(
newname
)
+
10
;
int
len
=
strlen
(
snappath
)
+
strlen
(
newname
)
+
10
;
char
*
path
=
alloca
(
len
);
path
=
must_realloc
(
NULL
,
len
);
sprintf
(
path
,
"%s/%s/comment"
,
snappath
,
newname
);
sprintf
(
path
,
"%s/%s/comment"
,
snappath
,
newname
);
return
copy_file
(
commentfile
,
path
)
<
0
?
-
1
:
i
;
return
copy_file
(
commentfile
,
path
)
<
0
?
-
1
:
i
;
}
}
...
...
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