lxccontainer: split_init_cmd()

parent 1452d3fe
...@@ -727,9 +727,10 @@ static void push_arg(char ***argp, char *arg, int *nargs) ...@@ -727,9 +727,10 @@ static void push_arg(char ***argp, char *arg, int *nargs)
static char **split_init_cmd(const char *incmd) static char **split_init_cmd(const char *incmd)
{ {
size_t len; size_t len;
int nargs = 0; char *copy, *p;
char *copy, *p, *saveptr = NULL;
char **argv; char **argv;
int nargs = 0;
char *saveptr = NULL;
if (!incmd) if (!incmd)
return NULL; return NULL;
...@@ -737,20 +738,21 @@ static char **split_init_cmd(const char *incmd) ...@@ -737,20 +738,21 @@ static char **split_init_cmd(const char *incmd)
len = strlen(incmd) + 1; len = strlen(incmd) + 1;
copy = alloca(len); copy = alloca(len);
strncpy(copy, incmd, len); strncpy(copy, incmd, len);
copy[len-1] = '\0'; copy[len - 1] = '\0';
do { do {
argv = malloc(sizeof(char *)); argv = malloc(sizeof(char *));
} while (!argv); } while (!argv);
argv[0] = NULL; argv[0] = NULL;
for (p = strtok_r(copy, " ", &saveptr); p != NULL; for (; (p = strtok_r(copy, " ", &saveptr)); copy = NULL)
p = strtok_r(NULL, " ", &saveptr))
push_arg(&argv, p, &nargs); push_arg(&argv, p, &nargs);
if (nargs == 0) { if (nargs == 0) {
free(argv); free(argv);
return NULL; return NULL;
} }
return argv; return argv;
} }
......
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