Commit fa7eddbb by Daniel Lezcano Committed by Daniel Lezcano

add a helper to dup the lxc arguments

Add a helper to dup the lxc_arguments, so the code making the copy of the arguments will be more clear. Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent e46ac651
...@@ -201,3 +201,46 @@ error: ...@@ -201,3 +201,46 @@ error:
lxc_error(args, "could not parse command line"); lxc_error(args, "could not parse command line");
return ret; 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;
}
...@@ -73,8 +73,11 @@ struct lxc_arguments { ...@@ -73,8 +73,11 @@ struct lxc_arguments {
/* option keys for long only options */ /* option keys for long only options */
#define OPT_USAGE 0x1000 #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[]); int argc, char *const argv[]);
extern char **lxc_arguments_dup(const char *file, struct lxc_arguments *args);
extern const char *lxc_strerror(int errnum); extern const char *lxc_strerror(int errnum);
#define lxc_error(arg, fmt, args...) if (!(arg)->quiet) \ #define lxc_error(arg, fmt, args...) if (!(arg)->quiet) \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment