mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-06-20 21:29:21 +00:00
keep rcfile for lxc-execute as already done for lxc-create
The code previously added in lxc-create with
commit d7efa8fcbf
is also required in lxc-execute.
So make this code common for the two callers.
Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
This commit is contained in:
parent
70f7755e98
commit
cfd1dc0932
@ -1393,6 +1393,7 @@ out:
|
||||
|
||||
int lxc_conf_init(struct lxc_conf *conf)
|
||||
{
|
||||
conf->rcfile = NULL;
|
||||
conf->rootfs = NULL;
|
||||
conf->fstab = NULL;
|
||||
conf->utsname = NULL;
|
||||
|
@ -117,6 +117,7 @@ struct lxc_cgroup {
|
||||
* @utsname : the container utsname
|
||||
*/
|
||||
struct lxc_conf {
|
||||
const char *rcfile;
|
||||
char *rootfs;
|
||||
char *fstab;
|
||||
int tty;
|
||||
|
@ -564,6 +564,8 @@ int lxc_config_read(const char *file, struct lxc_conf *conf)
|
||||
{
|
||||
char buffer[MAXPATHLEN];
|
||||
|
||||
conf->rcfile = file;
|
||||
|
||||
return lxc_file_for_each_line(file, parse_line, buffer,
|
||||
sizeof(buffer), conf);
|
||||
}
|
||||
|
@ -21,7 +21,10 @@
|
||||
* 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>
|
||||
@ -95,6 +98,24 @@ static int remove_lxc_directory(const char *dirname)
|
||||
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;
|
||||
@ -121,6 +142,11 @@ int lxc_create(const char *name, struct lxc_conf *conf)
|
||||
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);
|
||||
|
@ -49,6 +49,24 @@ static int remove_lxc_directory(const char *dirname)
|
||||
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;
|
||||
@ -58,6 +76,9 @@ int lxc_destroy(const char *name)
|
||||
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;
|
||||
|
@ -67,24 +67,6 @@ Options :\n\
|
||||
.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;
|
||||
@ -111,12 +93,6 @@ int main(int argc, char *argv[])
|
||||
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;
|
||||
|
@ -48,24 +48,6 @@ Options :\n\
|
||||
.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))
|
||||
@ -75,9 +57,6 @@ int main(int argc, char *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;
|
||||
|
Loading…
Reference in New Issue
Block a user