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
6010a416
Commit
6010a416
authored
Jan 28, 2015
by
Stéphane Graber
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix lxc-create -h with absolute template path
Close #421 Signed-off-by:
Stéphane Graber
<
stgraber@ubuntu.com
>
Acked-by:
Serge E. Hallyn
<
serge.hallyn@ubuntu.com
>
parent
393903d1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
41 deletions
+36
-41
lxc_create.c
src/lxc/lxc_create.c
+1
-7
lxccontainer.c
src/lxc/lxccontainer.c
+0
-34
utils.c
src/lxc/utils.c
+34
-0
utils.h
src/lxc/utils.h
+1
-0
No files found.
src/lxc/lxc_create.c
View file @
6010a416
...
@@ -101,8 +101,6 @@ static const struct option my_longopts[] = {
...
@@ -101,8 +101,6 @@ static const struct option my_longopts[] = {
static
void
create_helpfn
(
const
struct
lxc_arguments
*
args
)
{
static
void
create_helpfn
(
const
struct
lxc_arguments
*
args
)
{
char
*
argv
[
3
],
*
path
;
char
*
argv
[
3
],
*
path
;
size_t
len
;
int
ret
;
pid_t
pid
;
pid_t
pid
;
if
(
!
args
->
template
)
if
(
!
args
->
template
)
...
@@ -114,11 +112,7 @@ static void create_helpfn(const struct lxc_arguments *args) {
...
@@ -114,11 +112,7 @@ static void create_helpfn(const struct lxc_arguments *args) {
return
;
return
;
}
}
len
=
strlen
(
LXCTEMPLATEDIR
)
+
strlen
(
args
->
template
)
+
strlen
(
"/lxc-"
)
+
1
;
path
=
get_template_path
(
args
->
template
);
path
=
alloca
(
len
);
ret
=
snprintf
(
path
,
len
,
"%s/lxc-%s"
,
LXCTEMPLATEDIR
,
args
->
template
);
if
(
ret
<
0
||
ret
>=
len
)
return
;
argv
[
0
]
=
path
;
argv
[
0
]
=
path
;
argv
[
1
]
=
"-h"
;
argv
[
1
]
=
"-h"
;
...
...
src/lxc/lxccontainer.c
View file @
6010a416
...
@@ -841,40 +841,6 @@ static struct bdev *do_bdev_create(struct lxc_container *c, const char *type,
...
@@ -841,40 +841,6 @@ static struct bdev *do_bdev_create(struct lxc_container *c, const char *type,
return
bdev
;
return
bdev
;
}
}
/*
* Given the '-t' template option to lxc-create, figure out what to
* do. If the template is a full executable path, use that. If it
* is something like 'sshd', then return $templatepath/lxc-sshd.
* On success return the template, on error return NULL.
*/
static
char
*
get_template_path
(
const
char
*
t
)
{
int
ret
,
len
;
char
*
tpath
;
if
(
t
[
0
]
==
'/'
&&
access
(
t
,
X_OK
)
==
0
)
{
tpath
=
strdup
(
t
);
return
tpath
;
}
len
=
strlen
(
LXCTEMPLATEDIR
)
+
strlen
(
t
)
+
strlen
(
"/lxc-"
)
+
1
;
tpath
=
malloc
(
len
);
if
(
!
tpath
)
return
NULL
;
ret
=
snprintf
(
tpath
,
len
,
"%s/lxc-%s"
,
LXCTEMPLATEDIR
,
t
);
if
(
ret
<
0
||
ret
>=
len
)
{
free
(
tpath
);
return
NULL
;
}
if
(
access
(
tpath
,
X_OK
)
<
0
)
{
SYSERROR
(
"bad template: %s"
,
t
);
free
(
tpath
);
return
NULL
;
}
return
tpath
;
}
static
char
*
lxcbasename
(
char
*
path
)
static
char
*
lxcbasename
(
char
*
path
)
{
{
char
*
p
=
path
+
strlen
(
path
)
-
1
;
char
*
p
=
path
+
strlen
(
path
)
-
1
;
...
...
src/lxc/utils.c
View file @
6010a416
...
@@ -1506,3 +1506,37 @@ int is_dir(const char *path)
...
@@ -1506,3 +1506,37 @@ int is_dir(const char *path)
return
1
;
return
1
;
return
0
;
return
0
;
}
}
/*
* Given the '-t' template option to lxc-create, figure out what to
* do. If the template is a full executable path, use that. If it
* is something like 'sshd', then return $templatepath/lxc-sshd.
* On success return the template, on error return NULL.
*/
char
*
get_template_path
(
const
char
*
t
)
{
int
ret
,
len
;
char
*
tpath
;
if
(
t
[
0
]
==
'/'
&&
access
(
t
,
X_OK
)
==
0
)
{
tpath
=
strdup
(
t
);
return
tpath
;
}
len
=
strlen
(
LXCTEMPLATEDIR
)
+
strlen
(
t
)
+
strlen
(
"/lxc-"
)
+
1
;
tpath
=
malloc
(
len
);
if
(
!
tpath
)
return
NULL
;
ret
=
snprintf
(
tpath
,
len
,
"%s/lxc-%s"
,
LXCTEMPLATEDIR
,
t
);
if
(
ret
<
0
||
ret
>=
len
)
{
free
(
tpath
);
return
NULL
;
}
if
(
access
(
tpath
,
X_OK
)
<
0
)
{
SYSERROR
(
"bad template: %s"
,
t
);
free
(
tpath
);
return
NULL
;
}
return
tpath
;
}
src/lxc/utils.h
View file @
6010a416
...
@@ -285,3 +285,4 @@ char *choose_init(const char *rootfs);
...
@@ -285,3 +285,4 @@ char *choose_init(const char *rootfs);
int
print_to_file
(
const
char
*
file
,
const
char
*
content
);
int
print_to_file
(
const
char
*
file
,
const
char
*
content
);
bool
switch_to_ns
(
pid_t
pid
,
const
char
*
ns
);
bool
switch_to_ns
(
pid_t
pid
,
const
char
*
ns
);
int
is_dir
(
const
char
*
path
);
int
is_dir
(
const
char
*
path
);
char
*
get_template_path
(
const
char
*
t
);
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