diff --git a/modules/net/dap_chain_node_cli.c b/modules/net/dap_chain_node_cli.c index 13e8e6799b7d008016f7568a017bd098f96435bc..7de59d2354acac5a4cc1f13f4ad51f6e819d329a 100644 --- a/modules/net/dap_chain_node_cli.c +++ b/modules/net/dap_chain_node_cli.c @@ -342,7 +342,7 @@ int dap_chain_node_cli_init(dap_config_t * g_config) "decree info -net <net_name>\n" "Displays information about the parameters of the decrees in the network.\n"); - dap_cli_server_cmd_add ("exit", com_exec_cmd, "Execute command on remote node", + dap_cli_server_cmd_add ("exec_cmd", com_exec_cmd, "Execute command on remote node", "exec_cmd -net <net_name> -addr <node_addr> -cmd <command,and,all,args,separated,by,commas>\n" ); // Exit - always last! diff --git a/modules/net/dap_chain_node_cli_cmd.c b/modules/net/dap_chain_node_cli_cmd.c index 66ef5a56593a389c72d4a12fce3540efee6a4824..64a501efa37b1951092bca446e44b4883bf67cc4 100644 --- a/modules/net/dap_chain_node_cli_cmd.c +++ b/modules/net/dap_chain_node_cli_cmd.c @@ -8544,17 +8544,18 @@ void dap_notify_new_client_send_info(dap_events_socket_t *a_es, UNUSED_ARG void int com_exec_cmd(int argc, char **argv, void **reply) { json_object ** a_json_arr_reply = (json_object **) reply; if (!dap_json_rpc_exec_cmd_inited()) { - log_it(L_ERROR, "Json-rpc module doesn't inited, check confings"); + dap_json_rpc_error_add(-1, "Json-rpc module doesn't inited, check confings"); return -1; } - const char * l_cmd_arg_str = NULL, * l_ip_str = NULL, * l_net_str = NULL; + const char * l_cmd_arg_str = NULL, * l_addr_str = NULL, * l_net_str = NULL; int arg_index = 1; dap_cli_server_cmd_find_option_val(argv, arg_index, argc, "-cmd", &l_cmd_arg_str); - dap_cli_server_cmd_find_option_val(argv, arg_index, argc, "-addr", &l_ip_str); + dap_cli_server_cmd_find_option_val(argv, arg_index, argc, "-addr", &l_addr_str); dap_cli_server_cmd_find_option_val(argv, arg_index, argc, "-net", &l_net_str); - if (!l_cmd_arg_str || ! l_ip_str || !l_net_str) { + if (!l_cmd_arg_str || ! l_addr_str || !l_net_str) { dap_json_rpc_error_add(-1, "Command exec_cmd require args -cmd, -addr, -net"); + return -2; } dap_chain_net_t* l_net = NULL; l_net = dap_chain_net_by_name(l_net_str); @@ -8572,9 +8573,13 @@ int com_exec_cmd(int argc, char **argv, void **reply) { dap_strfreev(l_cmd_arr_str); // char * request_str = dap_json_rpc_request_to_json_string(a_request); dap_chain_node_addr_t l_node_addr; - dap_chain_node_addr_from_str(&l_node_addr, l_ip_str); + dap_chain_node_addr_from_str(&l_node_addr, l_addr_str); dap_chain_node_info_t *l_remote = dap_chain_node_info_read(l_net, &l_node_addr); DAP_DEL_Z(l_cmd_str); + if (!l_remote) { + dap_json_rpc_error_add(-1, "Can't find remote node: %s", l_addr_str); + return -3; + } if (!dap_json_rpc_request_send(a_request, dap_json_rpc_response_accepted, l_remote->ext_host, l_remote->ext_port, dap_json_rpc_error_callback)) log_it(L_INFO, "com_exec sent request to %s:%d", l_remote->ext_host, l_remote->ext_port);