[lxc-devel] [lxc/master] lxc-attach: add -f option & cleanup

Blub on Github lxc-bot at linuxcontainers.org
Thu Aug 4 09:48:27 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 845 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160804/c4a461a2/attachment.bin>
-------------- next part --------------
From 7f062284cd63a4a5b04689d89ffbcfb705dfa0c3 Mon Sep 17 00:00:00 2001
From: Wolfgang Bumiller <w.bumiller at proxmox.com>
Date: Thu, 4 Aug 2016 11:23:54 +0200
Subject: [PATCH 1/2] add -f option to lxc-attach

Otherwise a container with a non-standard configuration file
can be started but not attached to.
Fixes the following case:
 # lxc-start -n ct -f /different/path/my.config
 # lxc-attach -n ct
 Error: container ct is not defined
---
 src/lxc/tools/lxc_attach.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/lxc/tools/lxc_attach.c b/src/lxc/tools/lxc_attach.c
index 58f658b..7116885 100644
--- a/src/lxc/tools/lxc_attach.c
+++ b/src/lxc/tools/lxc_attach.c
@@ -65,6 +65,7 @@ static const struct option my_longopts[] = {
 	{"keep-var", required_argument, 0, 502},
 	{"set-var", required_argument, 0, 'v'},
 	{"pty-log", required_argument, 0, 'L'},
+	{"rcfile", required_argument, 0, 'f'},
 	LXC_COMMON_OPTIONS
 };
 
@@ -153,6 +154,7 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
 	case 'L':
 		args->console_log = arg;
 		break;
+	case 'f': args->rcfile = arg; break;
 	}
 
 	return 0;
@@ -202,7 +204,10 @@ Options :\n\
                     multiple times.\n\
       --keep-var    Keep an additional environment variable. Only\n\
                     applicable if --clear-env is specified. May be used\n\
-                    multiple times.\n",
+                    multiple times.\n\
+  -f, --rcfile=FILE\n\
+                    Load configuration file FILE\n\
+",
 	.options  = my_longopts,
 	.parser   = my_parser,
 	.checker  = NULL,
@@ -373,6 +378,15 @@ int main(int argc, char *argv[])
 	if (!c)
 		exit(EXIT_FAILURE);
 
+	if (my_args.rcfile) {
+		c->clear_config(c);
+		if (!c->load_config(c, my_args.rcfile)) {
+			ERROR("Failed to load rcfile");
+			lxc_container_put(c);
+			exit(EXIT_FAILURE);
+		}
+	}
+
 	if (!c->may_control(c)) {
 		fprintf(stderr, "Insufficent privileges to control %s\n", c->name);
 		lxc_container_put(c);

From 994d1cf043f5c96f0b6b3eec362e5a5b4b36cd94 Mon Sep 17 00:00:00 2001
From: Wolfgang Bumiller <w.bumiller at proxmox.com>
Date: Thu, 4 Aug 2016 11:28:37 +0200
Subject: [PATCH 2/2] whitespace cleanup

The rest of this block uses spaces instead of tabs already.
---
 src/lxc/tools/lxc_attach.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lxc/tools/lxc_attach.c b/src/lxc/tools/lxc_attach.c
index 7116885..281f97a 100644
--- a/src/lxc/tools/lxc_attach.c
+++ b/src/lxc/tools/lxc_attach.c
@@ -198,7 +198,7 @@ Options :\n\
                     is the current default behaviour, but is likely to\n\
                     change in the future.\n\
   -L, --pty-log=FILE\n\
-		    Log pty output to FILE\n\
+                    Log pty output to FILE\n\
   -v, --set-var     Set an additional variable that is seen by the\n\
                     attached program in the container. May be specified\n\
                     multiple times.\n\


More information about the lxc-devel mailing list