]> git.proxmox.com Git - mirror_lxc.git/commitdiff
tools: move lxc-create to API symbols only
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 12 Jan 2018 13:33:06 +0000 (14:33 +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_create.c
src/lxc/tools/tool_utils.c
src/lxc/tools/tool_utils.h

index f702c2ba7c5680929f8b4bebfb0d3954d626ca8b..9a4640316f69aace5254db83caa6b1d8c4dcadc1 100644 (file)
 #include <libgen.h>
 #include <stdint.h>
 #include <stdio.h>
+#include <string.h>
 #include <unistd.h>
-#include <lxc/lxccontainer.h>
 #include <sys/types.h>
 
+#include <lxc/lxccontainer.h>
+
 #include "arguments.h"
-#include "log.h"
-#include "lxc.h"
-#include "storage.h"
-#include "storage_utils.h"
-#include "utils.h"
+#include "tool_utils.h"
 
 static uint64_t get_fssize(char *s)
 {
@@ -203,6 +201,23 @@ static bool validate_bdev_args(struct lxc_arguments *a)
        return true;
 }
 
+static bool is_valid_storage_type(const char *type)
+{
+       if (strcmp(type, "dir") == 0 ||
+           strcmp(type, "btrfs") == 0 ||
+           strcmp(type, "aufs") == 0 ||
+           strcmp(type, "loop") == 0 ||
+           strcmp(type, "lvm") == 0 ||
+           strcmp(type, "nbd") == 0 ||
+           strcmp(type, "overlay") == 0 ||
+           strcmp(type, "overlayfs") == 0 ||
+           strcmp(type, "rbd") == 0 ||
+           strcmp(type, "zfs") == 0)
+               return true;
+
+       return false;
+}
+
 int main(int argc, char *argv[])
 {
        struct lxc_container *c;
@@ -225,7 +240,6 @@ int main(int argc, char *argv[])
 
        if (lxc_log_init(&log))
                exit(EXIT_FAILURE);
-       lxc_log_options_no_override();
 
        /* REMOVE IN LXC 3.0 */
        setenv("LXC_UPDATE_CONFIG_FORMAT", "1", 0);
@@ -286,7 +300,7 @@ int main(int argc, char *argv[])
        if (my_args.configfile)
                c->load_config(c, my_args.configfile);
        else
-               c->load_config(c, lxc_global_config_value("lxc.default_config"));
+               c->load_config(c, lxc_get_global_config_item("lxc.default_config"));
 
        if (my_args.fstype)
                spec.fstype = my_args.fstype;
index 29adc67763f70ecad69021e7a0e11ea9c4831470..94f118e635e34df144223d1478878abad8c0f81f 100644 (file)
@@ -539,3 +539,60 @@ size_t lxc_array_len(void **array)
 
        return result;
 }
+
+/*
+ * Given the '-t' template option to lxc-create, figure out what to
+ * do.  If the template is a full executable path, use that.  If it
+ * is something like 'sshd', then return $templatepath/lxc-sshd.
+ * On success return the template, on error return NULL.
+ */
+char *get_template_path(const char *t)
+{
+       int ret, len;
+       char *tpath;
+
+       if (t[0] == '/' && access(t, X_OK) == 0) {
+               tpath = strdup(t);
+               return tpath;
+       }
+
+       len = strlen(LXCTEMPLATEDIR) + strlen(t) + strlen("/lxc-") + 1;
+       tpath = malloc(len);
+       if (!tpath)
+               return NULL;
+       ret = snprintf(tpath, len, "%s/lxc-%s", LXCTEMPLATEDIR, t);
+       if (ret < 0 || ret >= len) {
+               free(tpath);
+               return NULL;
+       }
+       if (access(tpath, X_OK) < 0) {
+               fprintf(stderr, "Bad template: %s\n", t);
+               free(tpath);
+               return NULL;
+       }
+
+       return tpath;
+}
+
+int mkdir_p(const char *dir, mode_t mode)
+{
+       const char *tmp = dir;
+       const char *orig = dir;
+       char *makeme;
+
+       do {
+               dir = tmp + strspn(tmp, "/");
+               tmp = dir + strcspn(dir, "/");
+               makeme = strndup(orig, dir - orig);
+               if (*makeme) {
+                       if (mkdir(makeme, mode) && errno != EEXIST) {
+                               fprintf(stderr, "Failed to create directory \"%s\"\n", makeme);
+                               free(makeme);
+                               return -1;
+                       }
+               }
+               free(makeme);
+       } while(tmp != dir);
+
+       return 0;
+}
index 2453e3d612cdc244c0854fb5d8367d993825ea22..02b2eedd03a65033037c5ae00e99dfa7319f7d80 100644 (file)
@@ -139,6 +139,9 @@ extern char **lxc_normalize_path(const char *path);
 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 int is_dir(const char *path);
 
+extern char *get_template_path(const char *t);
+
 #endif /* __LXC_UTILS_H */