]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
tools: move lxc-destroy to API symbols only
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 12 Jan 2018 13:39:21 +0000 (14:39 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 6 Feb 2018 20:03:34 +0000 (21:03 +0100)
Closes #2073.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/tools/lxc_destroy.c
src/lxc/tools/tool_utils.c
src/lxc/tools/tool_utils.h

index 1c3f7dc5011e54190306805780d0b184ade572df..48484a6be8c3e97ea62d155618ea5892ffed9b34 100644 (file)
  */
 
 #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;
@@ -83,7 +82,7 @@ int main(int argc, char *argv[])
 
        if (lxc_log_init(&log))
                exit(EXIT_FAILURE);
-       lxc_log_options_no_override();
+
        if (my_args.quiet)
                quiet = true;
 
@@ -155,11 +154,11 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
 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)) {
@@ -168,8 +167,8 @@ static bool do_destroy(struct lxc_container *c)
                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) {
@@ -189,8 +188,13 @@ static bool do_destroy(struct lxc_container *c)
 
        /* 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)
@@ -206,7 +210,7 @@ static bool do_destroy_with_snapshots(struct lxc_container *c)
        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;
@@ -216,8 +220,8 @@ static bool do_destroy_with_snapshots(struct lxc_container *c)
        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);
@@ -268,8 +272,8 @@ static bool do_destroy_with_snapshots(struct lxc_container *c)
        }
 
        /* 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)
index 94f118e635e34df144223d1478878abad8c0f81f..e50f50273d80de73d46b7fb5afb9b38da67fd264 100644 (file)
@@ -596,3 +596,10 @@ int mkdir_p(const char *dir, mode_t mode)
 
        return 0;
 }
+
+bool file_exists(const char *f)
+{
+       struct stat statbuf;
+
+       return stat(f, &statbuf) == 0;
+}
index 02b2eedd03a65033037c5ae00e99dfa7319f7d80..4c9b43a28efd193faf56582ada69c12799859488 100644 (file)
@@ -140,6 +140,7 @@ extern char *lxc_string_join(const char *sep, const char **parts,
                             bool use_as_prefix);
 
 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 char *get_template_path(const char *t);