Closes #2073.
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
#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)
{
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;
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);
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;
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;
+}
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 */