int lxc_conf_init(struct lxc_conf *conf)
{
+ conf->rcfile = NULL;
conf->rootfs = NULL;
conf->fstab = NULL;
conf->utsname = NULL;
* @utsname : the container utsname
*/
struct lxc_conf {
+ const char *rcfile;
char *rootfs;
char *fstab;
int tty;
{
char buffer[MAXPATHLEN];
+ conf->rcfile = file;
+
return lxc_file_for_each_line(file, parse_line, buffer,
sizeof(buffer), conf);
}
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#define _GNU_SOURCE
#include <stdio.h>
+#undef _GNU_SOURCE
+#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <unistd.h>
return 0;
}
+static int copy_config_file(const char *name, const char *file)
+{
+ char *dst;
+ int ret;
+
+ if (!asprintf(&dst, LXCPATH "/%s/config", name)) {
+ ERROR("failed to allocate memory");
+ return -1;
+ }
+
+ ret = lxc_copy_file(file, dst);
+ if (ret)
+ ERROR("failed to copy '%s' to '%s'", file, dst);
+ free(dst);
+
+ return ret;
+}
+
int lxc_create(const char *name, struct lxc_conf *conf)
{
int lock, err = -1;
goto err_state;
}
+ if (conf->rcfile && copy_config_file(name, conf->rcfile)) {
+ ERROR("failed to copy the configuration file");
+ goto err_state;
+ }
+
err = 0;
out:
lxc_put_lock(lock);
return 0;
}
+static int remove_config_file(const char *name)
+{
+ char path[MAXPATHLEN];
+
+ snprintf(path, MAXPATHLEN, LXCPATH "/%s/config", name);
+
+ /* config file does not exists */
+ if (access(path, F_OK))
+ return 0;
+
+ if (unlink(path)) {
+ ERROR("failed to unlink '%s'", path);
+ return -1;
+ }
+
+ return 0;
+}
+
int lxc_destroy(const char *name)
{
int lock, ret = -1;
if (lock < 0)
return ret;
+ if (remove_config_file(name))
+ WARN("failed to remove the configuration file");
+
if (lxc_rmstate(name)) {
ERROR("failed to remove state file for %s", name);
goto out_lock;
.checker = NULL,
};
-static int copy_config_file(const char *name, const char *file)
-{
- char *src;
- int ret;
-
- if (!asprintf(&src, LXCPATH "/%s/config", name)) {
- ERROR("failed to allocate memory");
- return -1;
- }
-
- ret = lxc_copy_file(file, src);
- if (ret)
- ERROR("failed to copy '%s' to '%s'", file, src);
- free(src);
-
- return ret;
-}
-
int main(int argc, char *argv[])
{
struct lxc_conf lxc_conf;
return -1;
}
- if (my_args.rcfile && copy_config_file(my_args.name, my_args.rcfile)) {
- ERROR("failed to copy the configuration file");
- lxc_destroy(my_args.name);
- return -1;
- }
-
INFO("'%s' created", my_args.name);
return 0;
.checker = NULL,
};
-static int remove_config_file(const char *name)
-{
- char path[MAXPATHLEN];
-
- snprintf(path, MAXPATHLEN, LXCPATH "/%s/config", name);
-
- /* config file does not exists */
- if (access(path, F_OK))
- return 0;
-
- if (unlink(path)) {
- ERROR("failed to unlink '%s'", path);
- return -1;
- }
-
- return 0;
-}
-
int main(int argc, char *argv[])
{
if (lxc_arguments_parse(&my_args, argc, argv))
my_args.progname, my_args.quiet))
return -1;
- if (remove_config_file(my_args.name))
- WARN("failed to remove the configuration file");
-
if (lxc_destroy(my_args.name)) {
ERROR("failed to destroy the container");
return -1;