From 4b45b2812228dbd1b1259ef05364f00a7d30f3e5 Mon Sep 17 00:00:00 2001 From: Lai Jiangshan Date: Thu, 7 Apr 2016 15:11:38 +0800 Subject: [PATCH] use VmProcess and hyper_parse_process() for exec Signed-off-by: Lai Jiangshan --- src/parse.c | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/src/parse.c b/src/parse.c index dd5fe3c..5684b5b 100644 --- a/src/parse.c +++ b/src/parse.c @@ -1032,7 +1032,7 @@ fail: struct hyper_exec *hyper_parse_execcmd(char *json, int length) { - int i, j, n, has_seq = 0; + int i, j, n; struct hyper_exec *exec = NULL; jsmn_parser p; @@ -1073,43 +1073,21 @@ realloc: exec->stderrev.fd = -1; INIT_LIST_HEAD(&exec->list); - for (i = 0, j = 0; i < n; i++) { + for (i = 0; i < n; i++) { jsmntok_t *t = &toks[i]; - if (t->type != JSMN_STRING) - continue; - if (json_token_streq(json, t, "container")) { exec->id = (json_token_str(json, &toks[++i])); fprintf(stdout, "get container %s\n", exec->id); - } else if (json_token_streq(json, t, "seq")) { - has_seq = 1; - exec->seq = json_token_ll(json, &toks[++i]); - fprintf(stdout, "get seq %"PRIu64"\n", exec->seq); - } else if (json_token_streq(json, t, "cmd")) { - if (toks[++i].type != JSMN_ARRAY) { - fprintf(stdout, "execcmd need array\n"); + } else if (json_token_streq(json, t, "process") && t->size == 1) { + j = hyper_parse_process(exec, json, &toks[++i]); + if (j < 0) goto fail; - } - - exec->argv = calloc(toks[i].size + 1, sizeof(*exec->argv)); - if (exec->argv == NULL) { - fprintf(stdout, "allocate memory for exec cmd argv failed\n"); - goto fail; - } - exec->argc = toks[i].size; - exec->argv[exec->argc] = NULL; - } else if (j < exec->argc) { - exec->argv[j++] = (json_token_str(json, &toks[i])); - fprintf(stdout, "argv %d, %s\n", j - 1, exec->argv[j - 1]); - } else { - fprintf(stderr, "get unknown section %s in exec cmd\n", - json_token_str(json, t)); - goto fail; + i += j; } } - if (!has_seq) { + if (exec->seq == 0) { fprintf(stderr, "execcmd format error, has no seq\n"); goto fail; }