diff --git a/applications/services/cli/cli_vcp.c b/applications/services/cli/cli_vcp.c index 1f9c77b08..9dcd7178a 100644 --- a/applications/services/cli/cli_vcp.c +++ b/applications/services/cli/cli_vcp.c @@ -217,7 +217,11 @@ static void cli_vcp_internal_event_happened(FuriEventLoopObject* object, void* c // disconnect our side of the pipe pipe_detach_from_event_loop(cli_vcp->own_pipe); pipe_free(cli_vcp->own_pipe); - cli_vcp->own_pipe = NULL; + + // wait for shell to stop + cli_shell_join(cli_vcp->shell); + cli_shell_free(cli_vcp->shell); + pipe_free(cli_vcp->shell_pipe); break; } @@ -226,14 +230,6 @@ static void cli_vcp_internal_event_happened(FuriEventLoopObject* object, void* c FURI_LOG_D(TAG, "Connected"); cli_vcp->is_connected = true; - // wait for previous shell to stop - furi_check(!cli_vcp->own_pipe); - if(cli_vcp->shell) { - cli_shell_join(cli_vcp->shell); - cli_shell_free(cli_vcp->shell); - pipe_free(cli_vcp->shell_pipe); - } - // start shell thread PipeSideBundle bundle = pipe_alloc(VCP_BUF_SIZE, 1); cli_vcp->own_pipe = bundle.alices_side; diff --git a/lib/toolbox/cli/shell/cli_shell.c b/lib/toolbox/cli/shell/cli_shell.c index 7a4c7ec1f..473f10e6d 100644 --- a/lib/toolbox/cli/shell/cli_shell.c +++ b/lib/toolbox/cli/shell/cli_shell.c @@ -423,11 +423,16 @@ static int32_t cli_shell_thread(void* context) { cli_shell_init(shell); FURI_LOG_D(TAG, "Started"); + if(pipe_state(shell->pipe) == PipeStateBroken) goto bail; + shell->motd(shell->callback_context); cli_shell_line_prompt(shell->components[CliShellComponentLine]); + if(pipe_state(shell->pipe) == PipeStateBroken) goto bail; + furi_event_loop_run(shell->event_loop); +bail: FURI_LOG_D(TAG, "Stopped"); cli_shell_deinit(shell); return 0;