[lxc-devel] [PATCH 2/2] api_clone: don't remove storage if we haven't created it

2013-06-21 Thread Serge Hallyn
In the best case we'll get errors about failing to remove it.  In the
worst case we'll be trying to delete the original container's rootfs.

Reported-by: zoolook 
Signed-off-by: Serge Hallyn 
---
 src/lxc/lxccontainer.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index b6d5b2f..677fa56 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -1866,7 +1866,7 @@ struct lxc_container *lxcapi_clone(struct lxc_container 
*c, const char *newname,
 {
struct lxc_container *c2 = NULL;
char newpath[MAXPATHLEN];
-   int ret;
+   int ret, storage_copied = 0;
const char *n, *l;
FILE *fout;
 
@@ -1948,6 +1948,10 @@ struct lxc_container *lxcapi_clone(struct lxc_container 
*c, const char *newname,
if (ret < 0)
goto out;
 
+   // We've now successfully created c2's storage, so clear it out if we
+   // fail after this
+   storage_copied = 1;
+
if (!c2->save_config(c2, NULL))
goto out;
 
@@ -1961,6 +1965,8 @@ struct lxc_container *lxcapi_clone(struct lxc_container 
*c, const char *newname,
 out:
container_mem_unlock(c);
if (c2) {
+   if (!storage_copied)
+   c2->lxc_conf->rootfs.path = NULL;
c2->destroy(c2);
lxc_container_put(c2);
}
-- 
1.8.1.2


--
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH 1/2] Accept more word delimiters when updating hooks

2013-06-21 Thread Serge Hallyn
When updating container names in hook files during a container clone,
we substitute the new container name for the old any time the old name
shows up as a separate word.  This patch adds the four characters
'.,_-' as additional delimiters.

Signed-off-by: Serge Hallyn 
---
 src/lxc/lxccontainer.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index b1a05b4..b6d5b2f 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -1524,6 +1524,10 @@ static int is_word_sep(char c)
case '\t':
case ' ':
case '=':
+   case '.':
+   case ',':
+   case '_':
+   case '-':
case '/':
return 1;
default: return 0;
-- 
1.8.1.2


--
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] Possible bug in lxc-netstat w/ patch; feature patch

2013-06-21 Thread Andrew Gilbert
Hi,
I think I've discovered a bug in lxc-netstat when trying to have it run 
netstat with the '-n' option. I've attached a patch for this below 
(patch 1). I've also attached a patch that tries to Do The Right Thing 
if someone uses '-n' without the '--' before it (patch 2). I'd be happy 
to resend the patches as separate emails if that would be better.
--Andrew G

S T E P S   T O   R E P R O D U C E:
1. Start a container.
2. Use lxc-netstat -n  -- -n -a to try to get numeric 
IPs in netstat output.
3. Get error "./lxc-netstat: 75: shift: can't shift that many."

It appears that after the execution of lxc-unshare, the call to 
lxc-netstat does not include the '--' separator to prevent the netstat 
arguments being interpreted as lxc-netstat arguments. This only would 
manifest as a bug if the option is one that is valid for lxc-netstat as 
well as netstat, as the lone -n option is.

P A T C H   1:
 From 78ea721f2a6b0cc01cffba93109bd8d8202eeb98 Mon Sep 17 00:00:00 2001
From: Andrew Gilbert 
Date: Fri, 21 Jun 2013 11:24:37 -0700
Subject: [PATCH] Add double-dash to lxc-netstat re-call arguments

When lxc-netstat was called by lxc-unshare, it would be given the
arguments intended for netstat from the first invocation, but without
anything to separate them from the arguments intended for lxc-netstat.
This meant that netstat arguments like -n would result in lxc-netstat
trying to process them
---
  src/lxc/lxc-netstat.in | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lxc/lxc-netstat.in b/src/lxc/lxc-netstat.in
index 2fa2d23..229c214 100644
--- a/src/lxc/lxc-netstat.in
+++ b/src/lxc/lxc-netstat.in
@@ -93,7 +93,7 @@ if [ -z "$name" ]; then
  fi

  if [ -z "$exec" ]; then
-exec @BINDIR@/lxc-unshare -s MOUNT -- $0 -n $name --exec "$@"
+exec @BINDIR@/lxc-unshare -s MOUNT -- $0 -n $name --exec -- "$@"
  fi

  if lxc-info -n $name --state-is 'STOPPED'; then
-- 
1.8.1.2

P A T C H   2:
 From e45138027e08d291f4fad1357bcf5cb1b610c402 Mon Sep 17 00:00:00 2001
From: Andrew Gilbert 
Date: Fri, 21 Jun 2013 14:36:28 -0700
Subject: [PATCH 2/2] Add -n differentiation to lxc-netstat

lxc-netstat now only processes an -n argument if it has not previously
received a value for $name from --name or -n. If it _has_ received such
a value, it stops processing arguments and leaves the -n for netstat.
This does not apply to the use of --name after a name has been provided
by --name or -n; the current behaviour continues.
---
  src/lxc/lxc-netstat.in | 13 -
  1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/lxc/lxc-netstat.in b/src/lxc/lxc-netstat.in
index 229c214..4a239d9 100644
--- a/src/lxc/lxc-netstat.in
+++ b/src/lxc/lxc-netstat.in
@@ -66,12 +66,23 @@ get_parent_cgroup()
  }

  exec=""
+name=""

  while true; do
  case $1 in
  -h|--help)
  help; exit 1;;
--n|--name)
+-n)
+# If we already have a value for $name, treat -n as being an
+# argument for netstat
+if [ -n "$name" ]
+then
+break
+else
+name="$2"; shift 2;
+fi
+;;
+--name)
  name=$2; shift 2;;
  --exec)
  exec="exec"; shift;;
-- 
1.8.1.2



--
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel