*/
#define _GNU_SOURCE
-#include "config.h"
-
+#include <fcntl.h>
#include <libgen.h>
#include <stdio.h>
+#include <string.h>
#include <unistd.h>
+#include <sys/stat.h>
#include <sys/types.h>
#include <lxc/lxccontainer.h>
#include "arguments.h"
-#include "log.h"
-#include "lxc.h"
-#include "utils.h"
+#include "tool_utils.h"
static int my_parser(struct lxc_arguments* args, int c, char* arg);
static bool quiet;
if (lxc_log_init(&log))
exit(EXIT_FAILURE);
- lxc_log_options_no_override();
+
if (my_args.quiet)
quiet = true;
static bool do_destroy(struct lxc_container *c)
{
bool bret = true;
- char path[MAXPATHLEN];
+ char path[TOOL_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);
- if (ret < 0 || ret >= MAXPATHLEN)
+ int ret = snprintf(path, TOOL_MAXPATHLEN, "%s/%s/lxc_snapshots", c->config_path, c->name);
+ if (ret < 0 || ret >= TOOL_MAXPATHLEN)
return false;
if (file_exists(path)) {
return false;
}
- ret = snprintf(path, MAXPATHLEN, "%s/%s/snaps", c->config_path, c->name);
- if (ret < 0 || ret >= MAXPATHLEN)
+ ret = snprintf(path, TOOL_MAXPATHLEN, "%s/%s/snaps", c->config_path, c->name);
+ if (ret < 0 || ret >= TOOL_MAXPATHLEN)
return false;
if (rmdir(path) < 0 && errno != ENOENT) {
/* If the container was ephemeral we have already removed it when we
* stopped it. */
- if (c->is_defined(c) && !c->lxc_conf->ephemeral)
- bret = c->destroy(c);
+ 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);
+ }
+ }
if (!bret) {
if (!quiet)
struct lxc_container *c1;
struct stat fbuf;
bool bret = false;
- char path[MAXPATHLEN];
+ char path[TOOL_MAXPATHLEN];
char *buf = NULL;
char *lxcpath = NULL;
char *lxcname = NULL;
int counter = 0;
/* Destroy clones. */
- ret = snprintf(path, MAXPATHLEN, "%s/%s/lxc_snapshots", c->config_path, c->name);
- if (ret < 0 || ret >= MAXPATHLEN)
+ ret = snprintf(path, TOOL_MAXPATHLEN, "%s/%s/lxc_snapshots", c->config_path, c->name);
+ if (ret < 0 || ret >= TOOL_MAXPATHLEN)
return false;
fd = open(path, O_RDONLY | O_CLOEXEC);
}
/* Destroy snapshots located in the containers snap/ folder. */
- ret = snprintf(path, MAXPATHLEN, "%s/%s/snaps", c->config_path, c->name);
- if (ret < 0 || ret >= MAXPATHLEN)
+ ret = snprintf(path, TOOL_MAXPATHLEN, "%s/%s/snaps", c->config_path, c->name);
+ if (ret < 0 || ret >= TOOL_MAXPATHLEN)
return false;
if (rmdir(path) < 0 && errno != ENOENT)