[lxc-devel] [PATCH] Allow to specify containername without -n or --name in front of it

Michael Holzt lxc at my.fqdn.org
Fri Jan 8 04:18:06 UTC 2010


This patch removed the need to use "-n" or "--name" in front of the
container name. If no container name was set using "-n" or "--name"
the first non-option argument is taken.

Signed-off-by: Michael Holzt <lxc at my.fqdn.org>
---
 src/lxc/arguments.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/src/lxc/arguments.c b/src/lxc/arguments.c
index b5ab5b4..3de5330 100644
--- a/src/lxc/arguments.c
+++ b/src/lxc/arguments.c
@@ -180,6 +180,19 @@ extern int lxc_arguments_parse(struct lxc_arguments *args,
 			}
 		}
 	}
+	
+	/*
+	 * Take first remaining argument as container name if
+	 * -n switch was not used
+	 */
+	if (!args->name && optind < argc) {
+		args->name = strdup(argv[optind]);
+		if (!args->name) {
+			lxc_error(args, "could not copy container name");
+			return -1;
+		}
+		optind++;
+	} 
 
 	/*
 	 * Reclaim the remaining command arguments
-- 
1.6.5





More information about the lxc-devel mailing list