Commit 4f64d0db by Christian Brauner Committed by Stéphane Graber

Cleanup parts of lxc-destroy

A bit of pedantry usually doesn't hurt. The code should be easier to follow now and avoids some repetitions. Signed-off-by: 's avatarChristian Brauner <christianvanbrauner@gmail.com> Acked-by: 's avatarSerge E. Hallyn <serge.hallyn@ubuntu.com>
parent 4e6eb26b
...@@ -141,6 +141,7 @@ static int do_destroy_with_snapshots(struct lxc_container *c) ...@@ -141,6 +141,7 @@ static int 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;
char path[MAXPATHLEN]; char path[MAXPATHLEN];
char *buf = NULL; char *buf = NULL;
char *lxcpath = NULL; char *lxcpath = NULL;
...@@ -184,8 +185,10 @@ static int do_destroy_with_snapshots(struct lxc_container *c) ...@@ -184,8 +185,10 @@ static int do_destroy_with_snapshots(struct lxc_container *c)
if (!(lxcname = strtok_r(NULL, "\n", &scratch))) if (!(lxcname = strtok_r(NULL, "\n", &scratch)))
break; break;
c1 = lxc_container_new(lxcname, lxcpath); c1 = lxc_container_new(lxcname, lxcpath);
if (!c1) if (!c1) {
goto next; counter++;
continue;
}
if (!c1->destroy(c1)) { if (!c1->destroy(c1)) {
fprintf(stderr, "Destroying snapshot %s of %s failed\n", lxcname, my_args.name); fprintf(stderr, "Destroying snapshot %s of %s failed\n", lxcname, my_args.name);
lxc_container_put(c1); lxc_container_put(c1);
...@@ -193,7 +196,6 @@ static int do_destroy_with_snapshots(struct lxc_container *c) ...@@ -193,7 +196,6 @@ static int do_destroy_with_snapshots(struct lxc_container *c)
return -1; return -1;
} }
lxc_container_put(c1); lxc_container_put(c1);
next:
counter++; counter++;
} }
free(buf); free(buf);
...@@ -203,16 +205,15 @@ next: ...@@ -203,16 +205,15 @@ next:
ret = snprintf(path, MAXPATHLEN, "%s/%s/snaps", c->config_path, c->name); ret = snprintf(path, MAXPATHLEN, "%s/%s/snaps", c->config_path, c->name);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= MAXPATHLEN)
return -1; return -1;
if (dir_exists(path)) {
if (!c->destroy_with_snapshots(c)) { if (dir_exists(path))
fprintf(stderr, "Destroying %s failed\n", my_args.name); bret = c->destroy_with_snapshots(c);
return -1; else
} bret = c->destroy(c);
} else {
if (!c->destroy(c)) { if (!bret) {
fprintf(stderr, "Destroying %s failed\n", my_args.name); fprintf(stderr, "Destroying %s failed\n", my_args.name);
return -1; return -1;
}
} }
printf("Destroyed container %s including snapshots \n", my_args.name); printf("Destroyed container %s including snapshots \n", my_args.name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment