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
a1fe06d6
Unverified
Commit
a1fe06d6
authored
Aug 18, 2018
by
2xsec
Committed by
Christian Brauner
Aug 19, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools: lxc-destroy: add default log priority & cleanups
Signed-off-by:
2xsec
<
dh48.jeong@samsung.com
>
parent
c141d481
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
89 deletions
+91
-89
lxc_destroy.c
src/lxc/tools/lxc_destroy.c
+91
-89
No files found.
src/lxc/tools/lxc_destroy.c
View file @
a1fe06d6
...
...
@@ -35,6 +35,8 @@
lxc_log_define
(
lxc_destroy
,
lxc
);
static
int
my_parser
(
struct
lxc_arguments
*
args
,
int
c
,
char
*
arg
);
static
bool
do_destroy
(
struct
lxc_container
*
c
);
static
bool
do_destroy_with_snapshots
(
struct
lxc_container
*
c
);
static
const
struct
option
my_longopts
[]
=
{
{
"force"
,
no_argument
,
0
,
'f'
},
...
...
@@ -43,8 +45,8 @@ static const struct option my_longopts[] = {
};
static
struct
lxc_arguments
my_args
=
{
.
progname
=
"lxc-destroy"
,
.
help
=
"\
.
progname
=
"lxc-destroy"
,
.
help
=
"\
--name=NAME [-f] [-P lxcpath]
\n
\
\n
\
lxc-destroy destroys a container with the identifier NAME
\n
\
...
...
@@ -54,106 +56,35 @@ Options :\n\
-s, --snapshots destroy including all snapshots
\n
\
-f, --force wait for the container to shut down
\n
\
--rcfile=FILE Load configuration file FILE
\n
"
,
.
options
=
my_longopts
,
.
parser
=
my_parser
,
.
checker
=
NULL
,
.
task
=
DESTROY
,
.
options
=
my_longopts
,
.
parser
=
my_parser
,
.
checker
=
NULL
,
.
log_priority
=
"ERROR"
,
.
log_file
=
"none"
,
.
task
=
DESTROY
,
};
static
bool
do_destroy
(
struct
lxc_container
*
c
);
static
bool
do_destroy_with_snapshots
(
struct
lxc_container
*
c
);
int
main
(
int
argc
,
char
*
argv
[])
{
struct
lxc_container
*
c
;
struct
lxc_log
log
;
bool
bret
;
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
exit
(
EXIT_FAILURE
);
/* Only create log if explicitly instructed */
if
(
my_args
.
log_file
||
my_args
.
log_priority
)
{
log
.
name
=
my_args
.
name
;
log
.
file
=
my_args
.
log_file
;
log
.
level
=
my_args
.
log_priority
;
log
.
prefix
=
my_args
.
progname
;
log
.
quiet
=
my_args
.
quiet
;
log
.
lxcpath
=
my_args
.
lxcpath
[
0
];
if
(
lxc_log_init
(
&
log
))
exit
(
EXIT_FAILURE
);
}
c
=
lxc_container_new
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]);
if
(
!
c
)
{
ERROR
(
"System error loading container"
);
exit
(
EXIT_FAILURE
);
}
if
(
my_args
.
rcfile
)
{
c
->
clear_config
(
c
);
if
(
!
c
->
load_config
(
c
,
my_args
.
rcfile
))
{
ERROR
(
"Failed to load rcfile"
);
lxc_container_put
(
c
);
exit
(
EXIT_FAILURE
);
}
c
->
configfile
=
strdup
(
my_args
.
rcfile
);
if
(
!
c
->
configfile
)
{
ERROR
(
"Out of memory setting new config filename"
);
lxc_container_put
(
c
);
exit
(
EXIT_FAILURE
);
}
}
if
(
!
c
->
may_control
(
c
))
{
ERROR
(
"Insufficent privileges to control %s"
,
my_args
.
name
);
lxc_container_put
(
c
);
exit
(
EXIT_FAILURE
);
}
if
(
!
c
->
is_defined
(
c
))
{
ERROR
(
"Container is not defined"
);
lxc_container_put
(
c
);
exit
(
EXIT_FAILURE
);
}
if
(
my_args
.
task
==
SNAP
)
{
bret
=
do_destroy_with_snapshots
(
c
);
if
(
bret
)
ERROR
(
"Destroyed container %s including snapshots"
,
my_args
.
name
);
}
else
{
bret
=
do_destroy
(
c
);
if
(
bret
)
ERROR
(
"Destroyed container %s"
,
my_args
.
name
);
}
lxc_container_put
(
c
);
if
(
bret
)
exit
(
EXIT_SUCCESS
);
exit
(
EXIT_FAILURE
);
}
static
int
my_parser
(
struct
lxc_arguments
*
args
,
int
c
,
char
*
arg
)
{
switch
(
c
)
{
case
'f'
:
args
->
force
=
1
;
break
;
case
's'
:
args
->
task
=
SNAP
;
break
;
case
'f'
:
args
->
force
=
1
;
break
;
case
's'
:
args
->
task
=
SNAP
;
break
;
}
return
0
;
}
static
bool
do_destroy
(
struct
lxc_container
*
c
)
{
int
ret
;
bool
bret
=
true
;
char
path
[
MAXPATHLEN
];
/* First check whether the container has dependent clones or snapshots. */
int
ret
=
snprintf
(
path
,
MAXPATHLEN
,
"%s/%s/lxc_snapshots"
,
c
->
config_path
,
c
->
name
);
ret
=
snprintf
(
path
,
MAXPATHLEN
,
"%s/%s/lxc_snapshots"
,
c
->
config_path
,
c
->
name
);
if
(
ret
<
0
||
ret
>=
MAXPATHLEN
)
return
false
;
...
...
@@ -187,9 +118,8 @@ static bool do_destroy(struct lxc_container *c)
char
buf
[
256
];
ret
=
c
->
get_config_item
(
c
,
"lxc.ephemeral"
,
buf
,
256
);
if
(
ret
>
0
&&
strcmp
(
buf
,
"0"
)
==
0
)
{
if
(
ret
>
0
&&
strcmp
(
buf
,
"0"
)
==
0
)
bret
=
c
->
destroy
(
c
);
}
}
if
(
!
bret
)
{
...
...
@@ -273,3 +203,75 @@ static bool do_destroy_with_snapshots(struct lxc_container *c)
return
bret
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
struct
lxc_container
*
c
;
struct
lxc_log
log
;
bool
bret
;
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
exit
(
EXIT_FAILURE
);
log
.
name
=
my_args
.
name
;
log
.
file
=
my_args
.
log_file
;
log
.
level
=
my_args
.
log_priority
;
log
.
prefix
=
my_args
.
progname
;
log
.
quiet
=
my_args
.
quiet
;
log
.
lxcpath
=
my_args
.
lxcpath
[
0
];
if
(
lxc_log_init
(
&
log
))
exit
(
EXIT_FAILURE
);
c
=
lxc_container_new
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]);
if
(
!
c
)
{
ERROR
(
"System error loading container"
);
exit
(
EXIT_FAILURE
);
}
if
(
my_args
.
rcfile
)
{
c
->
clear_config
(
c
);
if
(
!
c
->
load_config
(
c
,
my_args
.
rcfile
))
{
ERROR
(
"Failed to load rcfile"
);
lxc_container_put
(
c
);
exit
(
EXIT_FAILURE
);
}
c
->
configfile
=
strdup
(
my_args
.
rcfile
);
if
(
!
c
->
configfile
)
{
ERROR
(
"Out of memory setting new config filename"
);
lxc_container_put
(
c
);
exit
(
EXIT_FAILURE
);
}
}
if
(
!
c
->
may_control
(
c
))
{
ERROR
(
"Insufficent privileges to control %s"
,
my_args
.
name
);
lxc_container_put
(
c
);
exit
(
EXIT_FAILURE
);
}
if
(
!
c
->
is_defined
(
c
))
{
ERROR
(
"Container is not defined"
);
lxc_container_put
(
c
);
exit
(
EXIT_FAILURE
);
}
if
(
my_args
.
task
==
SNAP
)
{
bret
=
do_destroy_with_snapshots
(
c
);
if
(
bret
)
ERROR
(
"Destroyed container %s including snapshots"
,
my_args
.
name
);
}
else
{
bret
=
do_destroy
(
c
);
if
(
bret
)
ERROR
(
"Destroyed container %s"
,
my_args
.
name
);
}
lxc_container_put
(
c
);
if
(
bret
)
exit
(
EXIT_SUCCESS
);
exit
(
EXIT_FAILURE
);
}
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