mirror of https://git.48k.eu/ogserver
rest: add retcode to shell/output
Add retcode field to specify return code of shell invocation.master
parent
98fab52b74
commit
12d5caf6a6
11
src/client.c
11
src/client.c
|
@ -172,6 +172,7 @@ static int og_resp_probe(struct og_client *cli, json_t *data)
|
||||||
static int og_resp_shell_run(struct og_client *cli, json_t *data)
|
static int og_resp_shell_run(struct og_client *cli, json_t *data)
|
||||||
{
|
{
|
||||||
const char *output = NULL;
|
const char *output = NULL;
|
||||||
|
uint32_t retcode;
|
||||||
const char *key;
|
const char *key;
|
||||||
json_t *value;
|
json_t *value;
|
||||||
int err = -1;
|
int err = -1;
|
||||||
|
@ -184,7 +185,12 @@ static int og_resp_shell_run(struct og_client *cli, json_t *data)
|
||||||
err = og_json_parse_string(value, &output);
|
err = og_json_parse_string(value, &output);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
|
} else if (!strcmp(key, "retcode")) {
|
||||||
|
err = og_json_parse_uint(value, &retcode);
|
||||||
|
if (err < 0)
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!output) {
|
if (!output) {
|
||||||
|
@ -193,8 +199,9 @@ static int og_resp_shell_run(struct og_client *cli, json_t *data)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
free((void *)cli->shell_output);
|
free((void *)cli->shell.output);
|
||||||
cli->shell_output = strdup(output);
|
cli->shell.output = strdup(output);
|
||||||
|
cli->shell.retcode = retcode;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ static void og_client_release(struct ev_loop *loop, struct og_client *cli)
|
||||||
ev_timer_stop(loop, &cli->timer);
|
ev_timer_stop(loop, &cli->timer);
|
||||||
ev_io_stop(loop, &cli->io);
|
ev_io_stop(loop, &cli->io);
|
||||||
close(cli->io.fd);
|
close(cli->io.fd);
|
||||||
free((void *)cli->shell_output);
|
free((void *)cli->shell.output);
|
||||||
free(cli);
|
free(cli);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -797,13 +797,14 @@ static int og_cmd_run_get(json_t *element, struct og_msg_params *params,
|
||||||
}
|
}
|
||||||
json_object_set_new(object, "addr", addr);
|
json_object_set_new(object, "addr", addr);
|
||||||
|
|
||||||
output = json_string(cli->shell_output);
|
output = json_string(cli->shell.output);
|
||||||
if (!output) {
|
if (!output) {
|
||||||
json_decref(object);
|
json_decref(object);
|
||||||
json_decref(array);
|
json_decref(array);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
json_object_set_new(object, "output", output);
|
json_object_set_new(object, "output", output);
|
||||||
|
json_object_set_new(object, "retcode", json_integer(cli->shell.retcode));
|
||||||
|
|
||||||
json_array_append_new(array, object);
|
json_array_append_new(array, object);
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,10 @@ struct og_client {
|
||||||
bool autorun;
|
bool autorun;
|
||||||
uint32_t speed;
|
uint32_t speed;
|
||||||
uint32_t seq;
|
uint32_t seq;
|
||||||
const char *shell_output;
|
struct {
|
||||||
|
const char *output;
|
||||||
|
uint32_t retcode;
|
||||||
|
} shell;
|
||||||
};
|
};
|
||||||
|
|
||||||
void og_client_add(struct og_client *cli);
|
void og_client_add(struct og_client *cli);
|
||||||
|
|
Loading…
Reference in New Issue