1 From dacc363d7d21434b764d95e4bd3d740c8995e951 Mon Sep 17 00:00:00 2001
2 From: Wolfgang Bumiller <w.bumiller@proxmox.com>
3 Date: Fri, 12 Aug 2016 12:21:22 +0200
4 Subject: [PATCH 1/3] tools: move --rcfile to the common options list
6 In almost all commands it's a useful addition to the -n
7 switch which is a common option, too.
9 Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
11 src/lxc/arguments.c | 1 +
12 src/lxc/arguments.h | 2 ++
13 src/lxc/tools/lxc_attach.c | 1 -
14 src/lxc/tools/lxc_cgroup.c | 12 +++++++++++-
15 src/lxc/tools/lxc_checkpoint.c | 10 ++++++++++
16 src/lxc/tools/lxc_console.c | 12 +++++++++++-
17 src/lxc/tools/lxc_copy.c | 11 ++++++++++-
18 src/lxc/tools/lxc_destroy.c | 12 +++++++++++-
19 src/lxc/tools/lxc_device.c | 11 ++++++++++-
20 src/lxc/tools/lxc_freeze.c | 12 +++++++++++-
21 src/lxc/tools/lxc_info.c | 12 +++++++++++-
22 src/lxc/tools/lxc_snapshot.c | 12 +++++++++++-
23 src/lxc/tools/lxc_stop.c | 11 ++++++++++-
24 src/lxc/tools/lxc_unfreeze.c | 12 +++++++++++-
25 src/lxc/tools/lxc_wait.c | 12 +++++++++++-
26 15 files changed, 131 insertions(+), 12 deletions(-)
28 diff --git a/src/lxc/arguments.c b/src/lxc/arguments.c
29 index c2f7b67..0d2b203 100644
30 --- a/src/lxc/arguments.c
31 +++ b/src/lxc/arguments.c
32 @@ -203,6 +203,7 @@ extern int lxc_arguments_parse(struct lxc_arguments *args,
33 case 'o': args->log_file = optarg; break;
34 case 'l': args->log_priority = optarg; break;
35 case 'q': args->quiet = 1; break;
36 + case OPT_RCFILE: args->rcfile = optarg; break;
38 remove_trailing_slashes(optarg);
39 ret = lxc_arguments_lxcpath_add(args, optarg);
40 diff --git a/src/lxc/arguments.h b/src/lxc/arguments.h
41 index f68f8ab..39bedf5 100644
42 --- a/src/lxc/arguments.h
43 +++ b/src/lxc/arguments.h
44 @@ -151,11 +151,13 @@ struct lxc_arguments {
45 {"logfile", required_argument, 0, 'o'}, \
46 {"logpriority", required_argument, 0, 'l'}, \
47 {"lxcpath", required_argument, 0, 'P'}, \
48 + {"rcfile", required_argument, 0, OPT_RCFILE}, \
51 /* option keys for long only options */
52 #define OPT_USAGE 0x1000
53 #define OPT_VERSION OPT_USAGE-1
54 +#define OPT_RCFILE OPT_USAGE-2
56 extern int lxc_arguments_parse(struct lxc_arguments *args,
57 int argc, char *const argv[]);
58 diff --git a/src/lxc/tools/lxc_cgroup.c b/src/lxc/tools/lxc_cgroup.c
59 index dd60fd1..c644501 100644
60 --- a/src/lxc/tools/lxc_cgroup.c
61 +++ b/src/lxc/tools/lxc_cgroup.c
62 @@ -56,7 +56,8 @@ Get or set the value of a state object (for example, 'cpuset.cpus')\n\
63 in the container's cgroup for the corresponding subsystem.\n\
66 - -n, --name=NAME NAME of the container",
67 + -n, --name=NAME NAME of the container\n\
68 + --rcfile=FILE Load configuration file FILE\n",
69 .options = my_longopts,
71 .checker = my_checker,
72 @@ -84,6 +85,15 @@ int main(int argc, char *argv[])
76 + if (my_args.rcfile) {
78 + if (!c->load_config(c, my_args.rcfile)) {
79 + ERROR("Failed to load rcfile");
80 + lxc_container_put(c);
85 if (!c->may_control(c)) {
86 ERROR("Insufficent privileges to control %s:%s", my_args.lxcpath[0], my_args.name);
88 diff --git a/src/lxc/tools/lxc_checkpoint.c b/src/lxc/tools/lxc_checkpoint.c
89 index 7130245..bc18b80 100644
90 --- a/src/lxc/tools/lxc_checkpoint.c
91 +++ b/src/lxc/tools/lxc_checkpoint.c
92 @@ -114,6 +114,7 @@ Options :\n\
94 -d, --daemon Daemonize the container (default)\n\
95 -F, --foreground Start with the current tty attached to /dev/console\n\
96 + --rcfile=FILE Load configuration file FILE\n\
98 .options = my_longopts,
100 @@ -214,6 +215,15 @@ int main(int argc, char *argv[])
104 + if (my_args.rcfile) {
105 + c->clear_config(c);
106 + if (!c->load_config(c, my_args.rcfile)) {
107 + fprintf(stderr, "Failed to load rcfile\n");
108 + lxc_container_put(c);
113 if (!c->may_control(c)) {
114 fprintf(stderr, "Insufficent privileges to control %s\n", my_args.name);
115 lxc_container_put(c);
116 diff --git a/src/lxc/tools/lxc_console.c b/src/lxc/tools/lxc_console.c
117 index adbd7e0..8a4d1c0 100644
118 --- a/src/lxc/tools/lxc_console.c
119 +++ b/src/lxc/tools/lxc_console.c
120 @@ -80,7 +80,8 @@ lxc-console logs on the container with the identifier NAME\n\
122 -n, --name=NAME NAME of the container\n\
123 -t, --tty=NUMBER console tty number\n\
124 - -e, --escape=PREFIX prefix for escape command\n",
125 + -e, --escape=PREFIX prefix for escape command\n\
126 + --rcfile=FILE Load configuration file FILE\n",
127 .options = my_longopts,
130 @@ -112,6 +113,15 @@ int main(int argc, char *argv[])
134 + if (my_args.rcfile) {
135 + c->clear_config(c);
136 + if (!c->load_config(c, my_args.rcfile)) {
137 + fprintf(stderr, "Failed to load rcfile\n");
138 + lxc_container_put(c);
139 + exit(EXIT_FAILURE);
143 if (!c->may_control(c)) {
144 fprintf(stderr, "Insufficent privileges to control %s\n", my_args.name);
145 lxc_container_put(c);
146 diff --git a/src/lxc/tools/lxc_copy.c b/src/lxc/tools/lxc_copy.c
147 index 3257ab7..c81c077 100644
148 --- a/src/lxc/tools/lxc_copy.c
149 +++ b/src/lxc/tools/lxc_copy.c
150 @@ -126,7 +126,8 @@ Options :\n\
151 -D, --keedata pass together with -e start a persistent snapshot \n\
152 -K, --keepname keep the hostname of the original container\n\
153 -- hook options arguments passed to the hook program\n\
154 - -M, --keepmac keep the MAC address of the original container\n",
155 + -M, --keepmac keep the MAC address of the original container\n\
156 + --rcfile=FILE Load configuration file FILE\n",
157 .options = my_longopts,
160 @@ -210,6 +211,14 @@ int main(int argc, char *argv[])
164 + if (my_args.rcfile) {
165 + c->clear_config(c);
166 + if (!c->load_config(c, my_args.rcfile)) {
167 + fprintf(stderr, "Failed to load rcfile\n");
172 if (!c->may_control(c)) {
174 fprintf(stderr, "Insufficent privileges to control %s\n", c->name);
175 diff --git a/src/lxc/tools/lxc_destroy.c b/src/lxc/tools/lxc_destroy.c
176 index b521739..50fd708 100644
177 --- a/src/lxc/tools/lxc_destroy.c
178 +++ b/src/lxc/tools/lxc_destroy.c
179 @@ -53,7 +53,8 @@ lxc-destroy destroys a container with the identifier NAME\n\
181 -n, --name=NAME NAME of the container\n\
182 -s, --snapshots destroy including all snapshots\n\
183 - -f, --force wait for the container to shut down\n",
184 + -f, --force wait for the container to shut down\n\
185 + --rcfile=FILE Load configuration file FILE\n",
186 .options = my_longopts,
189 @@ -88,6 +89,15 @@ int main(int argc, char *argv[])
193 + if (my_args.rcfile) {
194 + c->clear_config(c);
195 + if (!c->load_config(c, my_args.rcfile)) {
196 + fprintf(stderr, "Failed to load rcfile\n");
197 + lxc_container_put(c);
198 + exit(EXIT_FAILURE);
202 if (!c->may_control(c)) {
204 fprintf(stderr, "Insufficent privileges to control %s\n", my_args.name);
205 diff --git a/src/lxc/tools/lxc_device.c b/src/lxc/tools/lxc_device.c
206 index 0c9e066..0f1ee8b 100644
207 --- a/src/lxc/tools/lxc_device.c
208 +++ b/src/lxc/tools/lxc_device.c
209 @@ -53,7 +53,8 @@ static struct lxc_arguments my_args = {
210 lxc-device attach or detach DEV to or from container.\n\
213 - -n, --name=NAME NAME of the container",
214 + -n, --name=NAME NAME of the container\n\
215 + --rcfile=FILE Load configuration file FILE\n",
216 .options = my_longopts,
219 @@ -125,6 +126,14 @@ int main(int argc, char *argv[])
223 + if (my_args.rcfile) {
224 + c->clear_config(c);
225 + if (!c->load_config(c, my_args.rcfile)) {
226 + ERROR("Failed to load rcfile");
231 if (!c->is_running(c)) {
232 ERROR("Container %s is not running.", c->name);
234 diff --git a/src/lxc/tools/lxc_freeze.c b/src/lxc/tools/lxc_freeze.c
235 index ea8bd3e..d0239bf 100644
236 --- a/src/lxc/tools/lxc_freeze.c
237 +++ b/src/lxc/tools/lxc_freeze.c
238 @@ -47,7 +47,8 @@ static struct lxc_arguments my_args = {
239 lxc-freeze freezes a container with the identifier NAME\n\
242 - -n, --name=NAME NAME of the container",
243 + -n, --name=NAME NAME of the container\n\
244 + --rcfile=FILE Load configuration file FILE\n",
245 .options = my_longopts,
248 @@ -74,6 +75,15 @@ int main(int argc, char *argv[])
252 + if (my_args.rcfile) {
253 + c->clear_config(c);
254 + if (!c->load_config(c, my_args.rcfile)) {
255 + ERROR("Failed to load rcfile");
256 + lxc_container_put(c);
261 if (!c->may_control(c)) {
262 ERROR("Insufficent privileges to control %s:%s", my_args.lxcpath[0], my_args.name);
263 lxc_container_put(c);
264 diff --git a/src/lxc/tools/lxc_info.c b/src/lxc/tools/lxc_info.c
265 index 58ff619..e833697 100644
266 --- a/src/lxc/tools/lxc_info.c
267 +++ b/src/lxc/tools/lxc_info.c
268 @@ -93,7 +93,8 @@ Options :\n\
269 -p, --pid shows the process id of the init container\n\
270 -S, --stats shows usage stats\n\
271 -H, --no-humanize shows stats as raw numbers, not humanized\n\
272 - -s, --state shows the state of the container\n",
273 + -s, --state shows the state of the container\n\
274 + --rcfile=FILE Load configuration file FILE\n",
276 .options = my_longopts,
278 @@ -295,6 +296,15 @@ static int print_info(const char *name, const char *lxcpath)
282 + if (my_args.rcfile) {
283 + c->clear_config(c);
284 + if (!c->load_config(c, my_args.rcfile)) {
285 + fprintf(stderr, "Failed to load rcfile\n");
286 + lxc_container_put(c);
291 if (!c->may_control(c)) {
292 fprintf(stderr, "Insufficent privileges to control %s\n", c->name);
293 lxc_container_put(c);
294 diff --git a/src/lxc/tools/lxc_snapshot.c b/src/lxc/tools/lxc_snapshot.c
295 index 8f44891..aa9b6fe 100644
296 --- a/src/lxc/tools/lxc_snapshot.c
297 +++ b/src/lxc/tools/lxc_snapshot.c
298 @@ -62,7 +62,8 @@ Options :\n\
299 -d, --destroy=NAME destroy snapshot NAME, e.g. 'snap0'\n\
300 use ALL to destroy all snapshots\n\
301 -c, --comment=FILE add FILE as a comment\n\
302 - -C, --showcomments show snapshot comments\n",
303 + -C, --showcomments show snapshot comments\n\
304 + --rcfile=FILE Load configuration file FILE\n",
305 .options = my_longopts,
308 @@ -107,6 +108,15 @@ int main(int argc, char *argv[])
312 + if (my_args.rcfile) {
313 + c->clear_config(c);
314 + if (!c->load_config(c, my_args.rcfile)) {
315 + fprintf(stderr, "Failed to load rcfile\n");
316 + lxc_container_put(c);
317 + exit(EXIT_FAILURE);
321 if (!c->may_control(c)) {
322 fprintf(stderr, "Insufficent privileges to control %s\n",
324 diff --git a/src/lxc/tools/lxc_stop.c b/src/lxc/tools/lxc_stop.c
325 index 10ddce6..bbe1f1c 100644
326 --- a/src/lxc/tools/lxc_stop.c
327 +++ b/src/lxc/tools/lxc_stop.c
328 @@ -75,7 +75,8 @@ Options :\n\
329 -t, --timeout=T wait T seconds before hard-stopping\n\
330 -k, --kill kill container rather than request clean shutdown\n\
331 --nolock Avoid using API locks\n\
332 - --nokill Only request clean shutdown, don't force kill after timeout\n",
333 + --nokill Only request clean shutdown, don't force kill after timeout\n\
334 + --rcfile=FILE Load configuration file FILE\n",
335 .options = my_longopts,
338 @@ -203,6 +204,14 @@ int main(int argc, char *argv[])
342 + if (my_args.rcfile) {
343 + c->clear_config(c);
344 + if (!c->load_config(c, my_args.rcfile)) {
345 + fprintf(stderr, "Failed to load rcfile\n");
350 if (!c->may_control(c)) {
351 fprintf(stderr, "Insufficent privileges to control %s\n", c->name);
353 diff --git a/src/lxc/tools/lxc_unfreeze.c b/src/lxc/tools/lxc_unfreeze.c
354 index 3a13d37..b7bbea6 100644
355 --- a/src/lxc/tools/lxc_unfreeze.c
356 +++ b/src/lxc/tools/lxc_unfreeze.c
357 @@ -45,7 +45,8 @@ static struct lxc_arguments my_args = {
358 lxc-unfreeze unfreezes a container with the identifier NAME\n\
361 - -n, --name=NAME NAME of the container\n",
362 + -n, --name=NAME NAME of the container\n\
363 + --rcfile=FILE Load configuration file FILE\n",
364 .options = my_longopts,
367 @@ -78,6 +79,15 @@ int main(int argc, char *argv[])
371 + if (my_args.rcfile) {
372 + c->clear_config(c);
373 + if (!c->load_config(c, my_args.rcfile)) {
374 + ERROR("Failed to load rcfile");
375 + lxc_container_put(c);
380 if (!c->unfreeze(c)) {
381 ERROR("Failed to unfreeze %s:%s", my_args.lxcpath[0], my_args.name);
382 lxc_container_put(c);
383 diff --git a/src/lxc/tools/lxc_wait.c b/src/lxc/tools/lxc_wait.c
384 index 712ba52..deeff98 100644
385 --- a/src/lxc/tools/lxc_wait.c
386 +++ b/src/lxc/tools/lxc_wait.c
387 @@ -72,7 +72,8 @@ Options :\n\
388 -s, --state=STATE ORed states to wait for\n\
389 STOPPED, STARTING, RUNNING, STOPPING,\n\
390 ABORTING, FREEZING, FROZEN, THAWED\n\
391 - -t, --timeout=TMO Seconds to wait for state changes\n",
392 + -t, --timeout=TMO Seconds to wait for state changes\n\
393 + --rcfile=FILE Load configuration file FILE\n",
394 .options = my_longopts,
396 .checker = my_checker,
397 @@ -104,6 +105,15 @@ int main(int argc, char *argv[])
401 + if (my_args.rcfile) {
402 + c->clear_config(c);
403 + if (!c->load_config(c, my_args.rcfile)) {
404 + fprintf(stderr, "Failed to load rcfile\n");
405 + lxc_container_put(c);
410 if (!c->wait(c, my_args.states, my_args.timeout)) {
411 lxc_container_put(c);