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
e3347eef
Unverified
Commit
e3347eef
authored
Jan 12, 2018
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools: move lxc-destroy to API symbols only
Closes #2073. Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
e6294545
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
17 deletions
+29
-17
lxc_destroy.c
src/lxc/tools/lxc_destroy.c
+21
-17
tool_utils.c
src/lxc/tools/tool_utils.c
+7
-0
tool_utils.h
src/lxc/tools/tool_utils.h
+1
-0
No files found.
src/lxc/tools/lxc_destroy.c
View file @
e3347eef
...
@@ -18,19 +18,18 @@
...
@@ -18,19 +18,18 @@
*/
*/
#define _GNU_SOURCE
#define _GNU_SOURCE
#include "config.h"
#include <fcntl.h>
#include <libgen.h>
#include <libgen.h>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/types.h>
#include <lxc/lxccontainer.h>
#include <lxc/lxccontainer.h>
#include "arguments.h"
#include "arguments.h"
#include "log.h"
#include "tool_utils.h"
#include "lxc.h"
#include "utils.h"
static
int
my_parser
(
struct
lxc_arguments
*
args
,
int
c
,
char
*
arg
);
static
int
my_parser
(
struct
lxc_arguments
*
args
,
int
c
,
char
*
arg
);
static
bool
quiet
;
static
bool
quiet
;
...
@@ -83,7 +82,7 @@ int main(int argc, char *argv[])
...
@@ -83,7 +82,7 @@ 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
();
if
(
my_args
.
quiet
)
if
(
my_args
.
quiet
)
quiet
=
true
;
quiet
=
true
;
...
@@ -155,11 +154,11 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
...
@@ -155,11 +154,11 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
static
bool
do_destroy
(
struct
lxc_container
*
c
)
static
bool
do_destroy
(
struct
lxc_container
*
c
)
{
{
bool
bret
=
true
;
bool
bret
=
true
;
char
path
[
MAXPATHLEN
];
char
path
[
TOOL_
MAXPATHLEN
];
/* First check whether the container has dependent clones or snapshots. */
/* First check whether the container has dependent clones or snapshots. */
int
ret
=
snprintf
(
path
,
MAXPATHLEN
,
"%s/%s/lxc_snapshots"
,
c
->
config_path
,
c
->
name
);
int
ret
=
snprintf
(
path
,
TOOL_
MAXPATHLEN
,
"%s/%s/lxc_snapshots"
,
c
->
config_path
,
c
->
name
);
if
(
ret
<
0
||
ret
>=
MAXPATHLEN
)
if
(
ret
<
0
||
ret
>=
TOOL_
MAXPATHLEN
)
return
false
;
return
false
;
if
(
file_exists
(
path
))
{
if
(
file_exists
(
path
))
{
...
@@ -168,8 +167,8 @@ static bool do_destroy(struct lxc_container *c)
...
@@ -168,8 +167,8 @@ static bool do_destroy(struct lxc_container *c)
return
false
;
return
false
;
}
}
ret
=
snprintf
(
path
,
MAXPATHLEN
,
"%s/%s/snaps"
,
c
->
config_path
,
c
->
name
);
ret
=
snprintf
(
path
,
TOOL_
MAXPATHLEN
,
"%s/%s/snaps"
,
c
->
config_path
,
c
->
name
);
if
(
ret
<
0
||
ret
>=
MAXPATHLEN
)
if
(
ret
<
0
||
ret
>=
TOOL_
MAXPATHLEN
)
return
false
;
return
false
;
if
(
rmdir
(
path
)
<
0
&&
errno
!=
ENOENT
)
{
if
(
rmdir
(
path
)
<
0
&&
errno
!=
ENOENT
)
{
...
@@ -189,8 +188,13 @@ static bool do_destroy(struct lxc_container *c)
...
@@ -189,8 +188,13 @@ static bool do_destroy(struct lxc_container *c)
/* If the container was ephemeral we have already removed it when we
/* If the container was ephemeral we have already removed it when we
* stopped it. */
* stopped it. */
if
(
c
->
is_defined
(
c
)
&&
!
c
->
lxc_conf
->
ephemeral
)
if
(
c
->
is_defined
(
c
))
{
char
buf
[
256
];
ret
=
c
->
get_config_item
(
c
,
"lxc.ephemeral"
,
buf
,
256
);
if
(
ret
>
0
&&
strcmp
(
buf
,
"0"
)
==
0
)
{
bret
=
c
->
destroy
(
c
);
bret
=
c
->
destroy
(
c
);
}
}
if
(
!
bret
)
{
if
(
!
bret
)
{
if
(
!
quiet
)
if
(
!
quiet
)
...
@@ -206,7 +210,7 @@ static bool do_destroy_with_snapshots(struct lxc_container *c)
...
@@ -206,7 +210,7 @@ static bool do_destroy_with_snapshots(struct lxc_container *c)
struct
lxc_container
*
c1
;
struct
lxc_container
*
c1
;
struct
stat
fbuf
;
struct
stat
fbuf
;
bool
bret
=
false
;
bool
bret
=
false
;
char
path
[
MAXPATHLEN
];
char
path
[
TOOL_
MAXPATHLEN
];
char
*
buf
=
NULL
;
char
*
buf
=
NULL
;
char
*
lxcpath
=
NULL
;
char
*
lxcpath
=
NULL
;
char
*
lxcname
=
NULL
;
char
*
lxcname
=
NULL
;
...
@@ -216,8 +220,8 @@ static bool do_destroy_with_snapshots(struct lxc_container *c)
...
@@ -216,8 +220,8 @@ static bool do_destroy_with_snapshots(struct lxc_container *c)
int
counter
=
0
;
int
counter
=
0
;
/* Destroy clones. */
/* Destroy clones. */
ret
=
snprintf
(
path
,
MAXPATHLEN
,
"%s/%s/lxc_snapshots"
,
c
->
config_path
,
c
->
name
);
ret
=
snprintf
(
path
,
TOOL_
MAXPATHLEN
,
"%s/%s/lxc_snapshots"
,
c
->
config_path
,
c
->
name
);
if
(
ret
<
0
||
ret
>=
MAXPATHLEN
)
if
(
ret
<
0
||
ret
>=
TOOL_
MAXPATHLEN
)
return
false
;
return
false
;
fd
=
open
(
path
,
O_RDONLY
|
O_CLOEXEC
);
fd
=
open
(
path
,
O_RDONLY
|
O_CLOEXEC
);
...
@@ -268,8 +272,8 @@ static bool do_destroy_with_snapshots(struct lxc_container *c)
...
@@ -268,8 +272,8 @@ static bool do_destroy_with_snapshots(struct lxc_container *c)
}
}
/* Destroy snapshots located in the containers snap/ folder. */
/* Destroy snapshots located in the containers snap/ folder. */
ret
=
snprintf
(
path
,
MAXPATHLEN
,
"%s/%s/snaps"
,
c
->
config_path
,
c
->
name
);
ret
=
snprintf
(
path
,
TOOL_
MAXPATHLEN
,
"%s/%s/snaps"
,
c
->
config_path
,
c
->
name
);
if
(
ret
<
0
||
ret
>=
MAXPATHLEN
)
if
(
ret
<
0
||
ret
>=
TOOL_
MAXPATHLEN
)
return
false
;
return
false
;
if
(
rmdir
(
path
)
<
0
&&
errno
!=
ENOENT
)
if
(
rmdir
(
path
)
<
0
&&
errno
!=
ENOENT
)
...
...
src/lxc/tools/tool_utils.c
View file @
e3347eef
...
@@ -596,3 +596,10 @@ int mkdir_p(const char *dir, mode_t mode)
...
@@ -596,3 +596,10 @@ int mkdir_p(const char *dir, mode_t mode)
return
0
;
return
0
;
}
}
bool
file_exists
(
const
char
*
f
)
{
struct
stat
statbuf
;
return
stat
(
f
,
&
statbuf
)
==
0
;
}
src/lxc/tools/tool_utils.h
View file @
e3347eef
...
@@ -140,6 +140,7 @@ extern char *lxc_string_join(const char *sep, const char **parts,
...
@@ -140,6 +140,7 @@ 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
mkdir_p
(
const
char
*
dir
,
mode_t
mode
);
extern
bool
file_exists
(
const
char
*
f
);
extern
int
is_dir
(
const
char
*
path
);
extern
int
is_dir
(
const
char
*
path
);
extern
char
*
get_template_path
(
const
char
*
t
);
extern
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