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
e6294545
Unverified
Commit
e6294545
authored
Jan 12, 2018
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools: move lxc-create to API symbols only
Closes #2073. Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
0cb3e3a6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
8 deletions
+82
-8
lxc_create.c
src/lxc/tools/lxc_create.c
+22
-8
tool_utils.c
src/lxc/tools/tool_utils.c
+57
-0
tool_utils.h
src/lxc/tools/tool_utils.h
+3
-0
No files found.
src/lxc/tools/lxc_create.c
View file @
e6294545
...
@@ -22,16 +22,14 @@
...
@@ -22,16 +22,14 @@
#include <libgen.h>
#include <libgen.h>
#include <stdint.h>
#include <stdint.h>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <unistd.h>
#include <lxc/lxccontainer.h>
#include <sys/types.h>
#include <sys/types.h>
#include <lxc/lxccontainer.h>
#include "arguments.h"
#include "arguments.h"
#include "log.h"
#include "tool_utils.h"
#include "lxc.h"
#include "storage.h"
#include "storage_utils.h"
#include "utils.h"
static
uint64_t
get_fssize
(
char
*
s
)
static
uint64_t
get_fssize
(
char
*
s
)
{
{
...
@@ -203,6 +201,23 @@ static bool validate_bdev_args(struct lxc_arguments *a)
...
@@ -203,6 +201,23 @@ static bool validate_bdev_args(struct lxc_arguments *a)
return
true
;
return
true
;
}
}
static
bool
is_valid_storage_type
(
const
char
*
type
)
{
if
(
strcmp
(
type
,
"dir"
)
==
0
||
strcmp
(
type
,
"btrfs"
)
==
0
||
strcmp
(
type
,
"aufs"
)
==
0
||
strcmp
(
type
,
"loop"
)
==
0
||
strcmp
(
type
,
"lvm"
)
==
0
||
strcmp
(
type
,
"nbd"
)
==
0
||
strcmp
(
type
,
"overlay"
)
==
0
||
strcmp
(
type
,
"overlayfs"
)
==
0
||
strcmp
(
type
,
"rbd"
)
==
0
||
strcmp
(
type
,
"zfs"
)
==
0
)
return
true
;
return
false
;
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
struct
lxc_container
*
c
;
struct
lxc_container
*
c
;
...
@@ -225,7 +240,6 @@ int main(int argc, char *argv[])
...
@@ -225,7 +240,6 @@ int main(int argc, char *argv[])
if
(
lxc_log_init
(
&
log
))
if
(
lxc_log_init
(
&
log
))
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
lxc_log_options_no_override
();
/* REMOVE IN LXC 3.0 */
/* REMOVE IN LXC 3.0 */
setenv
(
"LXC_UPDATE_CONFIG_FORMAT"
,
"1"
,
0
);
setenv
(
"LXC_UPDATE_CONFIG_FORMAT"
,
"1"
,
0
);
...
@@ -286,7 +300,7 @@ int main(int argc, char *argv[])
...
@@ -286,7 +300,7 @@ int main(int argc, char *argv[])
if
(
my_args
.
configfile
)
if
(
my_args
.
configfile
)
c
->
load_config
(
c
,
my_args
.
configfile
);
c
->
load_config
(
c
,
my_args
.
configfile
);
else
else
c
->
load_config
(
c
,
lxc_g
lobal_config_value
(
"lxc.default_config"
));
c
->
load_config
(
c
,
lxc_g
et_global_config_item
(
"lxc.default_config"
));
if
(
my_args
.
fstype
)
if
(
my_args
.
fstype
)
spec
.
fstype
=
my_args
.
fstype
;
spec
.
fstype
=
my_args
.
fstype
;
...
...
src/lxc/tools/tool_utils.c
View file @
e6294545
...
@@ -539,3 +539,60 @@ size_t lxc_array_len(void **array)
...
@@ -539,3 +539,60 @@ size_t lxc_array_len(void **array)
return
result
;
return
result
;
}
}
/*
* 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
)
{
fprintf
(
stderr
,
"Bad template: %s
\n
"
,
t
);
free
(
tpath
);
return
NULL
;
}
return
tpath
;
}
int
mkdir_p
(
const
char
*
dir
,
mode_t
mode
)
{
const
char
*
tmp
=
dir
;
const
char
*
orig
=
dir
;
char
*
makeme
;
do
{
dir
=
tmp
+
strspn
(
tmp
,
"/"
);
tmp
=
dir
+
strcspn
(
dir
,
"/"
);
makeme
=
strndup
(
orig
,
dir
-
orig
);
if
(
*
makeme
)
{
if
(
mkdir
(
makeme
,
mode
)
&&
errno
!=
EEXIST
)
{
fprintf
(
stderr
,
"Failed to create directory
\"
%s
\"\n
"
,
makeme
);
free
(
makeme
);
return
-
1
;
}
}
free
(
makeme
);
}
while
(
tmp
!=
dir
);
return
0
;
}
src/lxc/tools/tool_utils.h
View file @
e6294545
...
@@ -139,6 +139,9 @@ extern char **lxc_normalize_path(const char *path);
...
@@ -139,6 +139,9 @@ extern char **lxc_normalize_path(const char *path);
extern
char
*
lxc_string_join
(
const
char
*
sep
,
const
char
**
parts
,
extern
char
*
lxc_string_join
(
const
char
*
sep
,
const
char
**
parts
,
bool
use_as_prefix
);
bool
use_as_prefix
);
extern
int
mkdir_p
(
const
char
*
dir
,
mode_t
mode
);
extern
int
is_dir
(
const
char
*
path
);
extern
int
is_dir
(
const
char
*
path
);
extern
char
*
get_template_path
(
const
char
*
t
);
#endif
/* __LXC_UTILS_H */
#endif
/* __LXC_UTILS_H */
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