Open
fix: 修复clp_comm按Tab键CPU占用过高 #10
HuangJiayiAdd on Aug 26
fix: 修复clp_comm按Tab键CPU占用过高 #10
Open
HuangJiayiAdd on Aug 26
Total: 4 files changed+26-1
@@ -23,6 +23,7 @@ gint32 get_no_timeout_flag(void);
23void dal_clear_sensitive_info(gchar *buf, guint32 len);23void dal_clear_sensitive_info(gchar *buf, guint32 len);
24gint32 getch(void);24gint32 getch(void);
25gchar *safe_getstr(gsize max_len);25gchar *safe_getstr(gsize max_len);
26+gint32 clp_ignore_tab(gint32 count, gint32 key);
26#endif27#endif
27 28 
28/* end of clp_command.h */29/* end of clp_command.h */
@@ -53,6 +53,13 @@ gchar g_clp_user_prompt[PARAMETER_LEN + 8] = {
53 "iBMC:/->"}; /* user prompt in clp */53 "iBMC:/->"}; /* user prompt in clp */
54LOCAL pthread_mutex_t g_no_timeout_flag_mutex = PTHREAD_MUTEX_INITIALIZER;54LOCAL pthread_mutex_t g_no_timeout_flag_mutex = PTHREAD_MUTEX_INITIALIZER;
55 55 
56+/* Keep TAB disabled without pushing it back into libedit's input queue. */
57+gint32 clp_ignore_tab(gint32 count, gint32 key) {
58+ (void)count;
59+ (void)key;
60+ return 0;
61+}
62+ 
56typedef gint32 (*clp_verb_handler_t)(SMASH_SESSION_T *session,63typedef gint32 (*clp_verb_handler_t)(SMASH_SESSION_T *session,
57 SMASH_CMD_T *cmd);64 SMASH_CMD_T *cmd);
58LOCAL clp_verb_handler_t clp_verb_handler[SMASH_NUM_VERBS] = {65LOCAL clp_verb_handler_t clp_verb_handler[SMASH_NUM_VERBS] = {
@@ -948,7 +955,10 @@ gint32 main(gint32 argc, gchar *argv[]) {
948 955 
949 (void)clp_get_username_ip(username, sizeof(username), ipaddr,956 (void)clp_get_username_ip(username, sizeof(username), ipaddr,
950 sizeof(ipaddr)); /* 获取登录的用户名与IP地址 */957 sizeof(ipaddr)); /* 获取登录的用户名与IP地址 */
951- rl_bind_key(TAB, rl_insert);958+ (void)rl_initialize();
959+ if (rl_add_defun("clp-ignore-tab", clp_ignore_tab, TAB) != 0) {
960+ debug_log(DLOG_ERROR, "Disable TAB behavior failed");
961+ }
952 set_log_username(log_username, sizeof(log_username),962 set_log_username(log_username, sizeof(log_username),
953 username); /* Disable default TAB behavior */963 username); /* Disable default TAB behavior */
954 964 
@@ -20,6 +20,7 @@
20 20 
21void dal_clear_sensitive_info(gchar *buf, guint32 len);21void dal_clear_sensitive_info(gchar *buf, guint32 len);
22gchar *safe_getstr(gsize max_len);22gchar *safe_getstr(gsize max_len);
23+gint32 clp_ignore_tab(gint32 count, gint32 key);
23 24 
24static int l_test_safe_getstr(lua_State *L) {25static int l_test_safe_getstr(lua_State *L) {
25 // 1. 检查第一个参数是否为数字26 // 1. 检查第一个参数是否为数字
@@ -61,11 +62,20 @@ static int l_test_dal_clear_sensitive_info(lua_State *L) {
61 return 1;62 return 1;
62}63}
63 64 
65+static int l_test_clp_ignore_tab(lua_State *L) {
66+ gint32 count = (gint32)luaL_checkinteger(L, 1);
67+ gint32 key = (gint32)luaL_checkinteger(L, 2);
68+ 
69+ lua_pushinteger(L, clp_ignore_tab(count, key));
70+ return 1;
71+}
72+ 
64LUAMOD_API int luaopen_clpcomm(lua_State *L) {73LUAMOD_API int luaopen_clpcomm(lua_State *L) {
65 luaL_checkversion(L);74 luaL_checkversion(L);
66 luaL_Reg l[] = {75 luaL_Reg l[] = {
67 {"test_safe_getstr", l_test_safe_getstr},76 {"test_safe_getstr", l_test_safe_getstr},
68 {"test_dal_clear_sensitive_info", l_test_dal_clear_sensitive_info},77 {"test_dal_clear_sensitive_info", l_test_dal_clear_sensitive_info},
78+ {"test_clp_ignore_tab", l_test_clp_ignore_tab},
69 {NULL, NULL},79 {NULL, NULL},
70 };80 };
71 luaL_newlib(L, l);81 luaL_newlib(L, l);
@@ -24,3 +24,7 @@ function TestPasswd:test_dal_clear_sensitive_info()
24 lu.assertEquals(ok, true)24 lu.assertEquals(ok, true)
25 lu.assertEquals(res, true)25 lu.assertEquals(res, true)
26end26end
27+ 
28+function TestPasswd:test_clp_ignore_tab()
29+ lu.assertEquals(clp_comm.test_clp_ignore_tab(1, 9), 0)
30+end