static void create_helpfn(const struct lxc_arguments *args) {
char *argv[3], *path;
- size_t len;
- int ret;
pid_t pid;
if (!args->template)
return;
}
- len = strlen(LXCTEMPLATEDIR) + strlen(args->template) + strlen("/lxc-") + 1;
- path = alloca(len);
- ret = snprintf(path, len, "%s/lxc-%s", LXCTEMPLATEDIR, args->template);
- if (ret < 0 || ret >= len)
- return;
+ path = get_template_path(args->template);
argv[0] = path;
argv[1] = "-h";
return bdev;
}
-/*
- * 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.
- */
-static 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) {
- SYSERROR("bad template: %s", t);
- free(tpath);
- return NULL;
- }
-
- return tpath;
-}
-
static char *lxcbasename(char *path)
{
char *p = path + strlen(path) - 1;
return 1;
return 0;
}
+
+/*
+ * 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) {
+ SYSERROR("bad template: %s", t);
+ free(tpath);
+ return NULL;
+ }
+
+ return tpath;
+}
int print_to_file(const char *file, const char *content);
bool switch_to_ns(pid_t pid, const char *ns);
int is_dir(const char *path);
+char *get_template_path(const char *t);