tools: move lxc-create to API symbols only

Closes #2073.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
Christian Brauner 2018-01-12 14:33:06 +01:00
parent 0cb3e3a6dd
commit e6294545d1
No known key found for this signature in database
GPG Key ID: 8EB056D53EECB12D
3 changed files with 82 additions and 8 deletions

View File

@ -22,16 +22,14 @@
#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;

View 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;
}

View 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 */