printf(" -L: for blockdev-backed backingstore, use specified size\n");
printf(" -K: Keep name - do not change the container name\n");
printf(" -M: Keep macaddr - do not choose a random new mac address\n");
- printf(" -H: copy Hooks - copy mount hooks into container directory\n");
- printf(" and substitute container names and lxcpaths\n");
printf(" -p: use container orig from custom lxcpath\n");
printf(" -P: create container new in custom lxcpath\n");
exit(1);
{ "vgname", required_argument, 0, 'v'},
{ "keepname", no_argument, 0, 'K'},
{ "keepmac", no_argument, 0, 'M'},
- { "copyhooks", no_argument, 0, 'H'}, // should this be default?
{ "lxcpath", required_argument, 0, 'p'},
{ "newpath", required_argument, 0, 'P'},
{ "fstype", required_argument, 0, 't'},
int main(int argc, char *argv[])
{
struct lxc_container *c1 = NULL, *c2 = NULL;
- int snapshot = 0, keepname = 0, keepmac = 0, copyhooks = 0;
+ int snapshot = 0, keepname = 0, keepmac = 0;
int flags = 0, option_index;
long newsize = 0;
char *bdevtype = NULL, *lxcpath = NULL, *newpath = NULL, *fstype = NULL;
case 'v': vgname = optarg; break;
case 'K': keepname = 1; break;
case 'M': keepmac = 1; break;
- case 'H': copyhooks = 1; break;
case 'p': lxcpath = optarg; break;
case 'P': newpath = optarg; break;
case 't': fstype = optarg; break;
if (snapshot) flags |= LXC_CLONE_SNAPSHOT;
if (keepname) flags |= LXC_CLONE_KEEPNAME;
if (keepmac) flags |= LXC_CLONE_KEEPMACADDR;
- if (copyhooks) flags |= LXC_CLONE_COPYHOOKS;
// vgname and fstype could be supported by sending them through the
// bdevdata. However, they currently are not yet. I'm not convinced
static int copyhooks(struct lxc_container *oldc, struct lxc_container *c)
{
- int i;
- int ret;
+ int i, len, ret;
struct lxc_list *it;
+ char *cpath;
+
+ len = strlen(oldc->config_path) + strlen(oldc->name) + 3;
+ cpath = alloca(len);
+ ret = snprintf(cpath, len, "%s/%s/", oldc->config_path, oldc->name);
+ if (ret < 0 || ret >= len)
+ return -1;
for (i=0; i<NUM_LXC_HOOKS; i++) {
lxc_list_for_each(it, &c->lxc_conf->hooks[i]) {
char tmppath[MAXPATHLEN];
if (!fname) // relative path - we don't support, but maybe we should
return 0;
+ if (strncmp(hookname, cpath, len - 1) != 0) {
+ // this hook is public - ignore
+ continue;
+ }
// copy the script, and change the entry in confile
ret = snprintf(tmppath, MAXPATHLEN, "%s/%s/%s",
c->config_path, c->name, fname+1);
goto out;
}
-
- // copy hooks if requested
- if (flags & LXC_CLONE_COPYHOOKS) {
- ret = copyhooks(c, c2);
- if (ret < 0) {
- ERROR("error copying hooks");
- goto out;
- }
+ // copy hooks
+ ret = copyhooks(c, c2);
+ if (ret < 0) {
+ ERROR("error copying hooks");
+ goto out;
}
if (copy_fstab(c, c2) < 0) {
{
struct bdev *bdev;
struct lxc_container *newc;
- int flags = LXC_CLONE_KEEPMACADDR | LXC_CLONE_COPYHOOKS;
if (!c || !c->name || !c->config_path)
return false;
return false;
}
- newc = lxcapi_clone(c, newname, c->config_path, flags, NULL, bdev->type, 0, NULL);
+ newc = lxcapi_clone(c, newname, c->config_path, LXC_CLONE_KEEPMACADDR, NULL, bdev->type, 0, NULL);
bdev_put(bdev);
if (!newc) {
lxc_container_put(newc);
#include <stdlib.h>
#define LXC_CLONE_KEEPNAME (1 << 0) /*!< Do not edit the rootfs to change the hostname */
-#define LXC_CLONE_COPYHOOKS (1 << 1) /*!< Copy all hooks into the container directory */
-#define LXC_CLONE_KEEPMACADDR (1 << 2) /*!< Do not change the MAC address on network interfaces */
-#define LXC_CLONE_SNAPSHOT (1 << 3) /*!< Snapshot the original filesystem(s) */
-#define LXC_CLONE_MAXFLAGS (1 << 4) /*!< Number of \c LXC_CLONE_* flags */
+#define LXC_CLONE_KEEPMACADDR (1 << 1) /*!< Do not change the MAC address on network interfaces */
+#define LXC_CLONE_SNAPSHOT (1 << 2) /*!< Snapshot the original filesystem(s) */
+#define LXC_CLONE_MAXFLAGS (1 << 3) /*!< Number of \c LXC_CLONE_* flags */
#define LXC_CREATE_QUIET (1 << 0) /*!< Redirect \c stdin to \c /dev/zero and \c stdout and \c stderr to \c /dev/null */
#define LXC_CREATE_MAXFLAGS (1 << 1) /*!< Number of \c LXC_CREATE* flags */
* (XXX: should we use the default instead?)
* \param flags Additional \c LXC_CLONE* flags to change the cloning behaviour:
* - \ref LXC_CLONE_KEEPNAME
- * - \ref LXC_CLONE_COPYHOOKS
* - \ref LXC_CLONE_KEEPMACADDR
* - \ref LXC_CLONE_SNAPSHOT
* \param bdevtype Optionally force the cloned bdevtype to a specified plugin.
PYLXC_EXPORT_CONST(LXC_ATTACH_SET_PERSONALITY);
/* clone: clone flags */
- PYLXC_EXPORT_CONST(LXC_CLONE_COPYHOOKS);
PYLXC_EXPORT_CONST(LXC_CLONE_KEEPMACADDR);
PYLXC_EXPORT_CONST(LXC_CLONE_KEEPNAME);
PYLXC_EXPORT_CONST(LXC_CLONE_SNAPSHOT);
LXC_ATTACH_SET_PERSONALITY = _lxc.LXC_ATTACH_SET_PERSONALITY
# clone: clone flags
-LXC_CLONE_COPYHOOKS = _lxc.LXC_CLONE_COPYHOOKS
LXC_CLONE_KEEPMACADDR = _lxc.LXC_CLONE_KEEPMACADDR
LXC_CLONE_KEEPNAME = _lxc.LXC_CLONE_KEEPNAME
LXC_CLONE_SNAPSHOT = _lxc.LXC_CLONE_SNAPSHOT