mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-14 03:53:18 +00:00
Merge pull request #811 from hallyn/2016-02-09/destroyquiet
lxc_destroy: be quiet if asked
This commit is contained in:
commit
2fa8e2cd0a
@ -33,6 +33,7 @@
|
||||
lxc_log_define(lxc_destroy_ui, lxc);
|
||||
|
||||
static int my_parser(struct lxc_arguments* args, int c, char* arg);
|
||||
static bool quiet;
|
||||
|
||||
static const struct option my_longopts[] = {
|
||||
{"force", no_argument, 0, 'f'},
|
||||
@ -75,20 +76,25 @@ int main(int argc, char *argv[])
|
||||
my_args.progname, my_args.quiet, my_args.lxcpath[0]))
|
||||
exit(EXIT_FAILURE);
|
||||
lxc_log_options_no_override();
|
||||
if (my_args.quiet)
|
||||
quiet = true;
|
||||
|
||||
c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
|
||||
if (!c) {
|
||||
if (!quiet)
|
||||
fprintf(stderr, "System error loading container\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (!c->may_control(c)) {
|
||||
if (!quiet)
|
||||
fprintf(stderr, "Insufficent privileges to control %s\n", my_args.name);
|
||||
lxc_container_put(c);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (!c->is_defined(c)) {
|
||||
if (!quiet)
|
||||
fprintf(stderr, "Container is not defined\n");
|
||||
lxc_container_put(c);
|
||||
exit(EXIT_FAILURE);
|
||||
@ -96,6 +102,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (c->is_running(c)) {
|
||||
if (!my_args.force) {
|
||||
if (!quiet)
|
||||
fprintf(stderr, "%s is running\n", my_args.name);
|
||||
lxc_container_put(c);
|
||||
exit(EXIT_FAILURE);
|
||||
@ -128,10 +135,12 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
|
||||
static int do_destroy(struct lxc_container *c)
|
||||
{
|
||||
if (!c->destroy(c)) {
|
||||
if (!quiet)
|
||||
fprintf(stderr, "Destroying %s failed\n", my_args.name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!quiet)
|
||||
printf("Destroyed container %s\n", my_args.name);
|
||||
|
||||
return 0;
|
||||
@ -190,6 +199,7 @@ static int do_destroy_with_snapshots(struct lxc_container *c)
|
||||
continue;
|
||||
}
|
||||
if (!c1->destroy(c1)) {
|
||||
if (!quiet)
|
||||
fprintf(stderr, "Destroying snapshot %s of %s failed\n", lxcname, my_args.name);
|
||||
lxc_container_put(c1);
|
||||
free(buf);
|
||||
@ -212,10 +222,12 @@ static int do_destroy_with_snapshots(struct lxc_container *c)
|
||||
bret = c->destroy(c);
|
||||
|
||||
if (!bret) {
|
||||
if (!quiet)
|
||||
fprintf(stderr, "Destroying %s failed\n", my_args.name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!quiet)
|
||||
printf("Destroyed container %s including snapshots \n", my_args.name);
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user