mirror of
https://github.com/clearlinux/hyperstart.git
synced 2026-08-19 12:26:06 +00:00
rename hyper_reader to file_command
Signed-off-by: Lai Jiangshan <jiangshanlai@gmail.com>
This commit is contained in:
+1
-1
@@ -54,7 +54,7 @@ struct hyper_win_size {
|
||||
uint64_t seq;
|
||||
};
|
||||
|
||||
struct hyper_reader {
|
||||
struct file_command {
|
||||
char *id;
|
||||
char *file;
|
||||
};
|
||||
|
||||
+8
-8
@@ -805,7 +805,7 @@ err:
|
||||
|
||||
static int hyper_cmd_read_file(char *json, int length, uint32_t *datalen, uint8_t **data)
|
||||
{
|
||||
struct hyper_reader reader;
|
||||
struct file_command cmd;
|
||||
struct hyper_container *c;
|
||||
struct hyper_pod *pod = &global_pod;
|
||||
struct hyper_file_arg arg = {
|
||||
@@ -818,13 +818,13 @@ static int hyper_cmd_read_file(char *json, int length, uint32_t *datalen, uint8_
|
||||
|
||||
fprintf(stdout, "%s\n", __func__);
|
||||
|
||||
if (hyper_parse_read_file(&reader, json, length) < 0) {
|
||||
if (hyper_parse_file_command(&cmd, json, length) < 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
c = hyper_find_container(pod, reader.id);
|
||||
c = hyper_find_container(pod, cmd.id);
|
||||
if (c == NULL) {
|
||||
fprintf(stderr, "can not find container whose id is %s\n", reader.id);
|
||||
fprintf(stderr, "can not find container whose id is %s\n", cmd.id);
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -839,7 +839,7 @@ static int hyper_cmd_read_file(char *json, int length, uint32_t *datalen, uint8_
|
||||
goto out;
|
||||
}
|
||||
|
||||
arg.file = reader.file;
|
||||
arg.file = cmd.file;
|
||||
arg.datalen = datalen;
|
||||
arg.data = data;
|
||||
|
||||
@@ -851,7 +851,7 @@ static int hyper_cmd_read_file(char *json, int length, uint32_t *datalen, uint8_
|
||||
|
||||
pid = clone(hyper_do_cmd_read_file, stack + stacksize, CLONE_VM| SIGQUIT, &arg);
|
||||
if (pid < 0) {
|
||||
perror("fail to fork writter process");
|
||||
perror("fail to fork reader process");
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -869,8 +869,8 @@ static int hyper_cmd_read_file(char *json, int length, uint32_t *datalen, uint8_
|
||||
out:
|
||||
close(arg.pipe[0]);
|
||||
close(arg.pipe[1]);
|
||||
free(reader.id);
|
||||
free(reader.file);
|
||||
free(cmd.id);
|
||||
free(cmd.file);
|
||||
free(stack);
|
||||
|
||||
return ret;
|
||||
|
||||
+14
-14
@@ -1406,7 +1406,7 @@ fail:
|
||||
goto out;
|
||||
}
|
||||
|
||||
int hyper_parse_read_file(struct hyper_reader *reader, char *json, int length)
|
||||
int hyper_parse_file_command(struct file_command *cmd, char *json, int length)
|
||||
{
|
||||
int i, n, ret = -1;
|
||||
|
||||
@@ -1414,11 +1414,11 @@ int hyper_parse_read_file(struct hyper_reader *reader, char *json, int length)
|
||||
int toks_num = 10;
|
||||
jsmntok_t *toks = NULL;
|
||||
|
||||
memset(reader, 0, sizeof(*reader));
|
||||
memset(cmd, 0, sizeof(*cmd));
|
||||
|
||||
toks = calloc(toks_num, sizeof(jsmntok_t));
|
||||
if (toks == NULL) {
|
||||
fprintf(stderr, "fail to allocate tokens for read file cmd\n");
|
||||
fprintf(stderr, "fail to allocate tokens for file cmd\n");
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
@@ -1441,20 +1441,20 @@ int hyper_parse_read_file(struct hyper_reader *reader, char *json, int length)
|
||||
goto fail;
|
||||
|
||||
if (json_token_streq(json, t, "container")) {
|
||||
reader->id = (json_token_str(json, &toks[i]));
|
||||
fprintf(stdout, "readfile get container %s\n", reader->id);
|
||||
cmd->id = (json_token_str(json, &toks[i]));
|
||||
fprintf(stdout, "file cmd get container %s\n", cmd->id);
|
||||
} else if (json_token_streq(json, t, "file")) {
|
||||
reader->file = (json_token_str(json, &toks[i]));
|
||||
fprintf(stdout, "readfile get file %s\n", reader->file);
|
||||
cmd->file = (json_token_str(json, &toks[i]));
|
||||
fprintf(stdout, "file cmd get file %s\n", cmd->file);
|
||||
} else {
|
||||
fprintf(stdout, "get unknown section %s in readfile\n",
|
||||
fprintf(stdout, "get unknown section %s in file cmd\n",
|
||||
json_token_str(json, t));
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
if (reader->id == NULL || reader->file == NULL) {
|
||||
fprintf(stderr, "readfile format incorrect\n");
|
||||
if (cmd->id == NULL || cmd->file == NULL) {
|
||||
fprintf(stderr, "file cmd format incorrect\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -1463,10 +1463,10 @@ out:
|
||||
free(toks);
|
||||
return ret;
|
||||
fail:
|
||||
free(reader->id);
|
||||
reader->id = NULL;
|
||||
free(reader->file);
|
||||
reader->file = NULL;
|
||||
free(cmd->id);
|
||||
cmd->id = NULL;
|
||||
free(cmd->file);
|
||||
cmd->file = NULL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ char *json_token_str(char *js, jsmntok_t *t);
|
||||
int json_token_streq(char *js, jsmntok_t *t, char *s);
|
||||
int hyper_parse_winsize(struct hyper_win_size *ws, char *json, int length);
|
||||
int hyper_parse_write_file(struct hyper_writter *writter, char *json, int length);
|
||||
int hyper_parse_read_file(struct hyper_reader *reader, char *json, int length);
|
||||
int hyper_parse_file_command(struct file_command *cmd, char *json, int length);
|
||||
struct hyper_container *hyper_parse_new_container(struct hyper_pod *pod, char *json, int length);
|
||||
void hyper_free_container(struct hyper_container *c);
|
||||
struct hyper_interface *hyper_parse_setup_interface(char *json, int length);
|
||||
|
||||
Reference in New Issue
Block a user