system/adb: fix shell issue and add reboot feature

This commit is contained in:
Simon Piriou 2020-12-08 14:16:57 +01:00 committed by Xiang Xiao
parent 2bafb70ce1
commit d37a1d2f1b
4 changed files with 43 additions and 10 deletions

View File

@ -22,7 +22,7 @@ include $(APPDIR)/Make.defs
ADB_DIR := $(APPDIR)/system/adb
CONFIG_ADBD_URL ?= "https://github.com/spiriou/microADB.git"
CONFIG_ADBD_VERSION ?= bbd1e74bd795aa2fc53eae2b76bff993d6ccaa37
CONFIG_ADBD_VERSION ?= b7025c67b866925d1e64c016a844a6a3392557a4
ADB_UNPACKNAME := microADB
ADB_UNPACKDIR := $(ADB_DIR)/$(ADB_UNPACKNAME)

View File

@ -46,6 +46,15 @@ void adb_log_impl(FAR const char *func, int line, FAR const char *fmt, ...)
va_end(ap);
}
void adb_reboot_impl(const char *target)
{
#ifdef CONFIG_BOARDCTL_RESET
boardctl(BOARDIOC_RESET, 0);
#else
adb_log("reboot not implemented\n");
#endif
}
int main(int argc, FAR char **argv)
{
UNUSED(argc);

View File

@ -113,6 +113,10 @@ static void shell_pipe_close_callback(uv_handle_t *handle)
{
shell_pipe_t *pipe = container_of(handle, shell_pipe_t, handle);
/* Close stdout pipe */
close(pipe->write_fd);
/* Notify caller pipe is closed */
pipe->close_cb(pipe);
@ -132,6 +136,12 @@ void shell_pipe_destroy(shell_pipe_t *pipe, void (*close_cb)(shell_pipe_t *))
{
pipe->close_cb = close_cb;
close(pipe->write_fd);
if (uv_fileno((const uv_handle_t *)&pipe->handle, &pipe->write_fd))
{
pipe->write_fd = -1;
}
uv_close((uv_handle_t *)&pipe->handle, shell_pipe_close_callback);
}
@ -160,12 +170,17 @@ int shell_pipe_exec(char * const argv[], shell_pipe_t *apipe,
/* Create pipe for stdin */
ret = pipe(in_fds);
assert(ret == 0);
ret = pipe(out_fds);
assert(ret == 0);
if ((ret = pipe(in_fds)))
{
adb_log("failed to open in pipe %d\n", errno);
goto exit_fail;
}
/* TODO check return code */
if ((ret = pipe(out_fds)))
{
adb_log("failed to open out pipe %d\n", errno);
goto exit_close_pipe_in;
}
apipe->write_fd = in_fds[1];
@ -234,4 +249,10 @@ int shell_pipe_exec(char * const argv[], shell_pipe_t *apipe,
assert(ret == 0);
return 0;
exit_close_pipe_in:
close(in_fds[0]);
close(in_fds[1]);
exit_fail:
return ret;
}

View File

@ -199,11 +199,14 @@ adb_service_t * shell_service(adb_client_t *client, const char *params)
ret = shell_pipe_exec(argv, &service->pipe,
exec_on_data_available);
/* TODO check return code */
assert(ret == 0);
free(argv);
if (ret)
{
adb_log("failed to setup shell pipe %d\n", ret);
free(service);
return NULL;
}
return &service->service;
}