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
3c708282
Unverified
Commit
3c708282
authored
Jun 20, 2019
by
Rachid Koucha
Committed by
Christian Brauner
Dec 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use file/directory names from macro.h
To make the file/directory names, use the defines from macro.h Signed-off-by:
Rachid Koucha
<
rachid.koucha@gmail.com
>
parent
813e65ae
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
21 deletions
+24
-21
lxccontainer.c
src/lxc/lxccontainer.c
+24
-21
No files found.
src/lxc/lxccontainer.c
View file @
3c708282
...
...
@@ -45,6 +45,7 @@
#include "af_unix.h"
#include "attach.h"
#include "cgroup.h"
#include "macro.h"
#include "commands.h"
#include "commands_utils.h"
#include "conf.h"
...
...
@@ -127,9 +128,9 @@ static bool config_file_exists(const char *lxcpath, const char *cname)
size_t
len
;
/* $lxcpath + '/' + $cname + '/config' + \0 */
len
=
strlen
(
lxcpath
)
+
strlen
(
cname
)
+
9
;
len
=
strlen
(
lxcpath
)
+
1
+
strlen
(
cname
)
+
1
+
strlen
(
LXC_CONFIG_FNAME
)
+
1
;
fname
=
must_realloc
(
NULL
,
len
);
ret
=
snprintf
(
fname
,
len
,
"%s/%s/
config"
,
lxcpath
,
cname
);
ret
=
snprintf
(
fname
,
len
,
"%s/%s/
%s"
,
lxcpath
,
cname
,
LXC_CONFIG_FNAME
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
len
)
return
false
;
...
...
@@ -160,9 +161,9 @@ static int ongoing_create(struct lxc_container *c)
int
ret
;
size_t
len
;
len
=
strlen
(
c
->
config_path
)
+
strlen
(
c
->
name
)
+
10
;
len
=
strlen
(
c
->
config_path
)
+
1
+
strlen
(
c
->
name
)
+
1
+
strlen
(
LXC_PARTIAL_FNAME
)
+
1
;
path
=
must_realloc
(
NULL
,
len
);
ret
=
snprintf
(
path
,
len
,
"%s/%s/
partial"
,
c
->
config_path
,
c
->
name
);
ret
=
snprintf
(
path
,
len
,
"%s/%s/
%s"
,
c
->
config_path
,
c
->
name
,
LXC_PARTIAL_FNAME
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
len
)
return
LXC_CREATE_FAILED
;
...
...
@@ -206,9 +207,9 @@ static int create_partial(struct lxc_container *c)
struct
flock
lk
=
{
0
};
/* $lxcpath + '/' + $name + '/partial' + \0 */
len
=
strlen
(
c
->
config_path
)
+
strlen
(
c
->
name
)
+
10
;
len
=
strlen
(
c
->
config_path
)
+
1
+
strlen
(
c
->
name
)
+
1
+
strlen
(
LXC_PARTIAL_FNAME
)
+
1
;
path
=
must_realloc
(
NULL
,
len
);
ret
=
snprintf
(
path
,
len
,
"%s/%s/
partial"
,
c
->
config_path
,
c
->
name
);
ret
=
snprintf
(
path
,
len
,
"%s/%s/
%s"
,
c
->
config_path
,
c
->
name
,
LXC_PARTIAL_FNAME
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
len
)
return
-
1
;
...
...
@@ -244,9 +245,9 @@ static void remove_partial(struct lxc_container *c, int fd)
close
(
fd
);
/* $lxcpath + '/' + $name + '/partial' + \0 */
len
=
strlen
(
c
->
config_path
)
+
strlen
(
c
->
name
)
+
10
;
len
=
strlen
(
c
->
config_path
)
+
1
+
strlen
(
c
->
name
)
+
1
+
strlen
(
LXC_PARTIAL_FNAME
)
+
1
;
path
=
must_realloc
(
NULL
,
len
);
ret
=
snprintf
(
path
,
len
,
"%s/%s/
partial"
,
c
->
config_path
,
c
->
name
);
ret
=
snprintf
(
path
,
len
,
"%s/%s/
%s"
,
c
->
config_path
,
c
->
name
,
LXC_PARTIAL_FNAME
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
len
)
return
;
...
...
@@ -1267,9 +1268,9 @@ static struct lxc_storage *do_storage_create(struct lxc_container *c,
ret
=
snprintf
(
dest
,
len
,
"%s"
,
rpath
);
}
else
{
const
char
*
lxcpath
=
do_lxcapi_get_config_path
(
c
);
len
=
strlen
(
c
->
name
)
+
strlen
(
lxcpath
)
+
9
;
len
=
strlen
(
c
->
name
)
+
1
+
strlen
(
lxcpath
)
+
1
+
strlen
(
LXC_ROOTFS_DNAME
)
+
1
;
dest
=
must_realloc
(
NULL
,
len
);
ret
=
snprintf
(
dest
,
len
,
"%s/%s/
rootfs"
,
lxcpath
,
c
->
name
);
ret
=
snprintf
(
dest
,
len
,
"%s/%s/
%s"
,
lxcpath
,
c
->
name
,
LXC_ROOTFS_DNAME
);
}
if
(
ret
<
0
||
(
size_t
)
ret
>=
len
)
return
NULL
;
...
...
@@ -3004,7 +3005,7 @@ static bool container_destroy(struct lxc_container *c,
* +
* \0
*/
len
=
strlen
(
p1
)
+
1
+
strlen
(
c
->
name
)
+
1
+
6
+
1
;
len
=
strlen
(
p1
)
+
1
+
strlen
(
c
->
name
)
+
1
+
strlen
(
LXC_CONFIG_FNAME
)
+
1
;
path
=
malloc
(
len
);
if
(
!
path
)
{
ERROR
(
"Failed to allocate memory"
);
...
...
@@ -3017,7 +3018,7 @@ static bool container_destroy(struct lxc_container *c,
if
(
storage
&&
(
!
strcmp
(
storage
->
type
,
"overlay"
)
||
!
strcmp
(
storage
->
type
,
"overlayfs"
))
&&
(
storage
->
flags
&
LXC_STORAGE_INTERNAL_OVERLAY_RESTORE
))
{
ret
=
snprintf
(
path
,
len
,
"%s/%s/
config"
,
p1
,
c
->
name
);
ret
=
snprintf
(
path
,
len
,
"%s/%s/
%s"
,
p1
,
c
->
name
,
LXC_CONFIG_FNAME
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
len
)
goto
out
;
...
...
@@ -3190,12 +3191,12 @@ static bool set_config_filename(struct lxc_container *c)
return
false
;
/* $lxc_path + "/" + c->name + "/" + "config" + '\0' */
len
=
strlen
(
c
->
config_path
)
+
strlen
(
c
->
name
)
+
strlen
(
"config"
)
+
3
;
len
=
strlen
(
c
->
config_path
)
+
1
+
strlen
(
c
->
name
)
+
1
+
strlen
(
LXC_CONFIG_FNAME
)
+
1
;
newpath
=
malloc
(
len
);
if
(
!
newpath
)
return
false
;
ret
=
snprintf
(
newpath
,
len
,
"%s/%s/
config"
,
c
->
config_path
,
c
->
name
);
ret
=
snprintf
(
newpath
,
len
,
"%s/%s/
%s"
,
c
->
config_path
,
c
->
name
,
LXC_CONFIG_FNAME
);
if
(
ret
<
0
||
ret
>=
len
)
{
fprintf
(
stderr
,
"Error printing out config file name
\n
"
);
free
(
newpath
);
...
...
@@ -3795,7 +3796,7 @@ static struct lxc_container *do_lxcapi_clone(struct lxc_container *c, const char
if
(
!
lxcpath
)
lxcpath
=
do_lxcapi_get_config_path
(
c
);
ret
=
snprintf
(
newpath
,
PATH_MAX
,
"%s/%s/
config"
,
lxcpath
,
newname
);
ret
=
snprintf
(
newpath
,
PATH_MAX
,
"%s/%s/
%s"
,
lxcpath
,
newname
,
LXC_CONFIG_FNAME
);
if
(
ret
<
0
||
ret
>=
PATH_MAX
)
{
SYSERROR
(
"clone: failed making config pathname"
);
goto
out
;
...
...
@@ -3844,7 +3845,7 @@ static struct lxc_container *do_lxcapi_clone(struct lxc_container *c, const char
saved_unexp_conf
=
NULL
;
c
->
lxc_conf
->
unexpanded_len
=
saved_unexp_len
;
ret
=
snprintf
(
newpath
,
PATH_MAX
,
"%s/%s/
rootfs"
,
lxcpath
,
newname
);
ret
=
snprintf
(
newpath
,
PATH_MAX
,
"%s/%s/
%s"
,
lxcpath
,
newname
,
LXC_ROOTFS_DNAME
);
if
(
ret
<
0
||
ret
>=
PATH_MAX
)
{
SYSERROR
(
"clone: failed making rootfs pathname"
);
goto
out
;
...
...
@@ -4126,6 +4127,7 @@ static bool get_snappath_dir(struct lxc_container *c, char *snappath)
static
int
do_lxcapi_snapshot
(
struct
lxc_container
*
c
,
const
char
*
commentfile
)
{
__do_free
char
*
dfnam
=
NULL
;
int
len
;
int
i
,
flags
,
ret
;
time_t
timer
;
struct
tm
tm_info
;
...
...
@@ -4189,8 +4191,9 @@ static int do_lxcapi_snapshot(struct lxc_container *c, const char *commentfile)
strftime
(
buffer
,
25
,
"%Y:%m:%d %H:%M:%S"
,
&
tm_info
);
dfnam
=
must_realloc
(
NULL
,
strlen
(
snappath
)
+
strlen
(
newname
)
+
5
);
sprintf
(
dfnam
,
"%s/%s/ts"
,
snappath
,
newname
);
len
=
strlen
(
snappath
)
+
1
+
strlen
(
newname
)
+
1
+
strlen
(
LXC_TIMESTAMP_FNAME
)
+
1
;
dfnam
=
must_realloc
(
NULL
,
len
);
snprintf
(
dfnam
,
len
,
"%s/%s/%s"
,
snappath
,
newname
,
LXC_TIMESTAMP_FNAME
);
f
=
fopen
(
dfnam
,
"w"
);
if
(
!
f
)
{
ERROR
(
"Failed to open %s"
,
dfnam
);
...
...
@@ -4212,10 +4215,10 @@ static int do_lxcapi_snapshot(struct lxc_container *c, const char *commentfile)
if
(
commentfile
)
{
__do_free
char
*
path
=
NULL
;
/* $p / $name / comment \0 */
int
len
=
strlen
(
snappath
)
+
strlen
(
newname
)
+
10
;
len
=
strlen
(
snappath
)
+
1
+
strlen
(
newname
)
+
1
+
strlen
(
LXC_COMMENT_FNAME
)
+
1
;
path
=
must_realloc
(
NULL
,
len
);
s
printf
(
path
,
"%s/%s/comment"
,
snappath
,
newname
);
s
nprintf
(
path
,
len
,
"%s/%s/%s"
,
snappath
,
newname
,
LXC_COMMENT_FNAME
);
return
copy_file
(
commentfile
,
path
)
<
0
?
-
1
:
i
;
}
...
...
@@ -4311,7 +4314,7 @@ static int do_lxcapi_snapshot_list(struct lxc_container *c, struct lxc_snapshot
if
(
!
strcmp
(
direntp
->
d_name
,
".."
))
continue
;
ret
=
snprintf
(
path2
,
PATH_MAX
,
"%s/%s/
config"
,
snappath
,
direntp
->
d_name
);
ret
=
snprintf
(
path2
,
PATH_MAX
,
"%s/%s/
%s"
,
snappath
,
direntp
->
d_name
,
LXC_CONFIG_FNAME
);
if
(
ret
<
0
||
ret
>=
PATH_MAX
)
{
ERROR
(
"pathname too long"
);
goto
out_free
;
...
...
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