]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
add a helper to dup the lxc arguments
authorDaniel Lezcano <daniel.lezcano@free.fr>
Wed, 15 Jul 2009 21:48:22 +0000 (23:48 +0200)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Wed, 15 Jul 2009 21:48:22 +0000 (23:48 +0200)
Add a helper to dup the lxc_arguments, so the code making
the copy of the arguments will be more clear.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
src/lxc/arguments.c
src/lxc/arguments.h

index 3527be41d2e03c11aaf2a0ba911f2923aa31bd51..03ec2afeb258cd98cdba1527833e368775ccba88 100644 (file)
@@ -201,3 +201,46 @@ error:
                lxc_error(args, "could not parse command line");
        return ret;
 }
+
+extern char **lxc_arguments_dup(const char *file, struct lxc_arguments *args)
+{
+       char **argv;
+       int opt, nbargs = args->argc + 2;
+
+       if (args->log_file)
+               nbargs += 2;
+       if (args->log_priority)
+               nbargs += 2;
+       if (args->quiet)
+               nbargs += 1;
+
+       argv = malloc(nbargs * sizeof(*argv));
+       if (!argv)
+               return NULL;
+
+       nbargs = 0;
+
+       argv[nbargs++] = strdup(file);
+
+       if (args->log_file) {
+               argv[nbargs++] = "--logfile";
+               argv[nbargs++] = strdup(args->log_file);
+       }
+
+       if (args->log_priority) {
+               argv[nbargs++] = "--logpriority";
+               argv[nbargs++] = strdup(args->log_priority);
+       }
+
+       if (args->quiet)
+               argv[nbargs++] = "--quiet";
+
+       argv[nbargs++] = "--";
+
+       for (opt = 0; opt < args->argc; opt++)
+               argv[nbargs++] = strdup(args->argv[opt]);
+
+       argv[nbargs] = NULL;
+
+       return argv;
+}
index ffb436fe35c87551ced919fe7c1e5c792b82ede6..d38de89ec1e67b0b0d99612b85212721ebc52b5e 100644 (file)
@@ -73,8 +73,11 @@ struct lxc_arguments {
 /* option keys for long only options */
 #define        OPT_USAGE 0x1000
 
-extern int lxc_arguments_parse(struct lxc_arguments *a_args,
+extern int lxc_arguments_parse(struct lxc_arguments *args,
                               int argc, char *const argv[]);
+
+extern char **lxc_arguments_dup(const char *file, struct lxc_arguments *args);
+
 extern const char *lxc_strerror(int errnum);
 
 #define lxc_error(arg, fmt, args...) if (!(arg)->quiet)                        \