shared/shell: Fix not handling prompt with color properly
Luiz Augusto von Dentz
maintainerPATCH 1/1 shared/shell: Fix not handling prompt with color properly
From: Luiz Augusto von Dentz <[email protected]>
Colors use escape sequence that needs to be enveloped with RL_PROMPT_START_IGNORE (\001) and RL_PROMPT_END_IGNORE (\002) in order for readline to properly calculate the prompt length.
--- client/main.c | 16 ++++++++-------- client/mgmt.c | 10 ++++------ src/shared/shell.c | 15 +++++++++------ src/shared/shell.h | 2 +- 4 files changed, 22 insertions(+), 21 deletions(-)
client/main.c +8 -8
@@ -43,7 +43,7 @@#define COLORED_CHG COLOR_YELLOW "CHG" COLOR_OFF#define COLORED_DEL COLOR_RED "DEL" COLOR_OFF -#define PROMPT_ON COLOR_BLUE "[bluetooth]" COLOR_OFF "# " +#define PROMPT_ON "[bluetooth]# "#define PROMPT_OFF "Waiting to connect to bluetoothd..."static DBusConnection *dbus_conn;
@@ -106,14 +106,14 @@ static void setup_standard_input(void)static void connect_handler (DBusConnection *connection,void *user_data) { -bt_shell_set_prompt (PROMPT_ON ); +bt_shell_set_prompt (PROMPT_ON ,COLOR_BLUE ); }static void disconnect_handler (DBusConnection *connection,void *user_data) {bt_shell_detach (); -bt_shell_set_prompt (PROMPT_OFF ); +bt_shell_set_prompt (PROMPT_OFF ,NULL );g_list_free_full (ctrl_list, proxy_leak);g_list_free_full (battery_proxies, proxy_leak);
@@ -333,12 +333,12 @@ static void set_default_device(GDBusProxy *proxy, const char *attribute) path =g_dbus_proxy_get_path (proxy);dbus_message_iter_get_basic (&iter, &desc); - desc =g_strdup_printf (COLOR_BLUE "[%s%s%s]" COLOR_OFF "# " , desc, + desc =g_strdup_printf ("[%s%s%s]# " , desc, attribute ?":" :"" , attribute ? attribute +strlen (path) :"" ); done: -bt_shell_set_prompt (desc ? desc :PROMPT_ON ); +bt_shell_set_prompt (desc ? desc :PROMPT_ON ,COLOR_BLUE );g_free (desc); }
@@ -2099,9 +2099,9 @@ static void set_default_local_attribute(char *attr) default_local_attr = attr; default_attr =NULL ; - desc =g_strdup_printf (COLOR_BLUE "[%s]" COLOR_OFF "# " , attr); + desc =g_strdup_printf ("[%s]# " , attr); -bt_shell_set_prompt (desc); +bt_shell_set_prompt (desc,COLOR_BLUE );g_free (desc); }
@@ -3187,7 +3187,7 @@ int main(int argc, char *argv[])bt_shell_add_submenu (&advertise_monitor_menu);bt_shell_add_submenu (&scan_menu);bt_shell_add_submenu (&gatt_menu); -bt_shell_set_prompt (PROMPT_OFF ); +bt_shell_set_prompt (PROMPT_OFF ,NULL );if (agent_option) auto_register_agent =g_strdup (agent_option);
client/mgmt.c +4 -6
@@ -78,13 +78,11 @@ static void update_prompt(uint16_t index)char str[32 ];if (index ==MGMT_INDEX_NONE ) -snprintf (str,sizeof (str),"%s# " , -COLOR_BLUE "[mgmt]" COLOR_OFF ); +snprintf (str,sizeof (str),"[mgmt]# " );else -snprintf (str,sizeof (str), -COLOR_BLUE "[hci%u]" COLOR_OFF "# " , index); +snprintf (str,sizeof (str),"[hci%u]# " , index); -bt_shell_set_prompt (str); +bt_shell_set_prompt (str,COLOR_BLUE ); }void mgmt_set_index (const char *arg)
@@ -860,7 +858,7 @@ static void prompt_input(const char *input, void *user_data) &prompt.addr); }else {mgmt_confirm_neg_reply (prompt.index, &prompt.addr); -bt_shell_set_prompt (PROMPT_ON ); +bt_shell_set_prompt (PROMPT_ON ,COLOR_BLUE ); }break ; }
src/shared/shell.c +9 -6
@@ -750,15 +750,13 @@ void bt_shell_echo(const char *fmt, ...)va_start (args, fmt); ret =vasprintf (&str, fmt, args); -if (ret >=0 ) - ret =asprintf (&str,COLOR_HIGHLIGHT "%s " COLOR_OFF "#" , str);va_end (args);if (ret <0 )return ;rl_save_prompt (); -bt_shell_set_prompt (str); +bt_shell_set_prompt (str,COLOR_HIGHLIGHT );rl_restore_prompt (); }
@@ -823,7 +821,7 @@ static void prompt_input(const char *str, bt_shell_prompt_input_func func, data.saved_user_data = user_data;rl_save_prompt (); -bt_shell_set_prompt (str); +bt_shell_set_prompt (str,COLOR_HIGHLIGHT ); } void bt_shell_prompt_input(const char *label, const char *msg,
@@ -1574,14 +1572,19 @@ bool bt_shell_add_submenu(const struct bt_shell_menu *menu)return true; } -void bt_shell_set_prompt (const char *string) +void bt_shell_set_prompt (const char *string,const char *color) {char *prompt;if (!data.init || data.mode)return ; -if (asprintf (&prompt,"\001%s\002" , string) <0 ) { +/* Envelope color within RL_PROMPT_START_IGNORE (\001) and +* RL_PROMPT_END_IGNORE (\002) so readline can properly calculate the +* prompt length. +*/ +if (!color ||asprintf (&prompt,"\001%s\002%s\001%s\002" , color, string, +COLOR_OFF ) <0 ) {rl_set_prompt (string); }else {rl_set_prompt (prompt);
src/shared/shell.h +1 -1
@@ -66,7 +66,7 @@ bool bt_shell_add_submenu(const struct bt_shell_menu *menu);bool bt_shell_remove_submenu (const struct bt_shell_menu *menu); -void bt_shell_set_prompt (const char *string); +void bt_shell_set_prompt (const char *string,const char *color);void bt_shell_printf (const char *fmt, ...) __attribute__((format (printf,1 ,2 )));
Signature · 1 line
2.47.0
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=899490
---Test result---
Test Summary:
CheckPatch PASS 0.47 seconds GitLint PASS 0.30 seconds BuildEll PASS 24.48 seconds BluezMake FAIL 19.72 seconds MakeCheck FAIL 72.89 seconds MakeDistcheck FAIL 45.01 seconds CheckValgrind FAIL 16.53 seconds CheckSmatch FAIL 26.69 seconds bluezmakeextell FAIL 15.12 seconds IncrementalBuild FAIL 19.87 seconds ScanBuild FAIL 524.58 seconds
Details
##############################
Test: BluezMake - FAIL
Desc: Build BlueZ
Output:
tools/mesh-cfgclient.c: In function ‘client_connected’:tools/mesh-cfgclient.c:2485:2: error: too few arguments to function ‘bt_shell_set_prompt’
2485 | bt_shell_set_prompt(PROMPT_ON);
| ^~~~~~~~~~~~~~~~~~~
In file included from tools/mesh-cfgclient.c:28:
./src/shared/shell.h:69:6: note: declared here
69 | void bt_shell_set_prompt(const char *string, const char *color);
| ^~~~~~~~~~~~~~~~~~~
tools/mesh-cfgclient.c: In function ‘main’:
tools/mesh-cfgclient.c:2645:2: error: too few arguments to function ‘bt_shell_set_prompt’
2645 | bt_shell_set_prompt(PROMPT_OFF);
| ^~~~~~~~~~~~~~~~~~~
In file included from tools/mesh-cfgclient.c:28:
./src/shared/shell.h:69:6: note: declared here
69 | void bt_shell_set_prompt(const char *string, const char *color);
| ^~~~~~~~~~~~~~~~~~~make[1]: *** [Makefile:7872: tools/mesh-cfgclient.o] Error 1 make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:4690: all] Error 2
##############################
Test: MakeCheck - FAIL
Desc: Run Bluez Make Check
Output:
tools/meshctl.c: In function ‘connect_handler’:tools/meshctl.c:175:2: error: too few arguments to function ‘bt_shell_set_prompt’
175 | bt_shell_set_prompt(PROMPT_ON);
| ^~~~~~~~~~~~~~~~~~~
In file included from tools/meshctl.c:34:
./src/shared/shell.h:69:6: note: declared here
69 | void bt_shell_set_prompt(const char *string, const char *color);
| ^~~~~~~~~~~~~~~~~~~
tools/meshctl.c: In function ‘disconnect_handler’:
tools/meshctl.c:182:2: error: too few arguments to function ‘bt_shell_set_prompt’
182 | bt_shell_set_prompt(PROMPT_OFF);
| ^~~~~~~~~~~~~~~~~~~
In file included from tools/meshctl.c:34:
./src/shared/shell.h:69:6: note: declared here
69 | void bt_shell_set_prompt(const char *string, const char *color);
| ^~~~~~~~~~~~~~~~~~~
tools/meshctl.c: In function ‘set_connected_device’:
tools/meshctl.c:611:2: error: too few arguments to function ‘bt_shell_set_prompt’
611 | bt_shell_set_prompt(desc ? desc : PROMPT_ON);
| ^~~~~~~~~~~~~~~~~~~
In file included from tools/meshctl.c:34:
./src/shared/shell.h:69:6: note: declared here
69 | void bt_shell_set_prompt(const char *string, const char *color);
| ^~~~~~~~~~~~~~~~~~~
tools/meshctl.c: In function ‘main’:
tools/meshctl.c:1904:2: error: too few arguments to function ‘bt_shell_set_prompt’
1904 | bt_shell_set_prompt(PROMPT_OFF);
| ^~~~~~~~~~~~~~~~~~~
In file included from tools/meshctl.c:34:
./src/shared/shell.h:69:6: note: declared here
69 | void bt_shell_set_prompt(const char *string, const char *color);
| ^~~~~~~~~~~~~~~~~~~make[1]: *** [Makefile:7872: tools/meshctl.o] Error 1
make: *** [Makefile:12355: check] Error 2
##############################
Test: MakeDistcheck - FAIL
Desc: Run Bluez Make Distcheck
Output:
Package cups was not found in the pkg-config search path.
Perhaps you should add the directory containing `cups.pc'
to the PKG_CONFIG_PATH environment variable
No package 'cups' found../../tools/obexctl.c: In function ‘connect_handler’:../../tools/obexctl.c:67:2: error: too few arguments to function ‘bt_shell_set_prompt’
67 | bt_shell_set_prompt(PROMPT_ON);
| ^~~~~~~~~~~~~~~~~~~
In file included from ../../tools/obexctl.c:29:
../../src/shared/shell.h:69:6: note: declared here
69 | void bt_shell_set_prompt(const char *string, const char *color);
| ^~~~~~~~~~~~~~~~~~~
../../tools/obexctl.c: In function ‘disconnect_handler’:
../../tools/obexctl.c:73:2: error: too few arguments to function ‘bt_shell_set_prompt’
73 | bt_shell_set_prompt(PROMPT_OFF);
| ^~~~~~~~~~~~~~~~~~~
In file included from ../../tools/obexctl.c:29:
../../src/shared/shell.h:69:6: note: declared here
69 | void bt_shell_set_prompt(const char *string, const char *color);
| ^~~~~~~~~~~~~~~~~~~
../../tools/bluetooth-player.c: In function ‘connect_handler’:
../../tools/bluetooth-player.c:44:2: error: too few arguments to function ‘bt_shell_set_prompt’
44 | bt_shell_set_prompt(PROMPT_ON);
| ^~~~~~~~~~~~~~~~~~~
In file included from ../../tools/bluetooth-player.c:33:
../../src/shared/shell.h:69:6: note: declared here
69 | void bt_shell_set_prompt(const char *string, const char *color);
| ^~~~~~~~~~~~~~~~~~~
../../tools/bluetooth-player.c: In function ‘disconnect_handler’:
../../tools/bluetooth-player.c:50:2: error: too few arguments to function ‘bt_shell_set_prompt’
50 | bt_shell_set_prompt(PROMPT_OFF);
| ^~~~~~~~~~~~~~~~~~~
In file included from ../../tools/bluetooth-player.c:33:
../../src/shared/shell.h:69:6: note: declared here
69 | void bt_shell_set_prompt(const char *string, const char *color);
| ^~~~~~~~~~~~~~~~~~~
../../tools/bluetooth-player.c: In function ‘main’:
../../tools/bluetooth-player.c:59:2: error: too few arguments to function ‘bt_shell_set_prompt’
59 | bt_shell_set_prompt(PROMPT_OFF);
| ^~~~~~~~~~~~~~~~~~~
In file included from ../../tools/bluetooth-player.c:33:
../../src/shared/shell.h:69:6: note: declared here
69 | void bt_shell_set_prompt(const char *string, const char *color);
| ^~~~~~~~~~~~~~~~~~~
../../tools/obexctl.c: In function ‘set_default_session’:
../../tools/obexctl.c:415:2: error: too few arguments to function ‘bt_shell_set_prompt’
415 | bt_shell_set_prompt(desc);
| ^~~~~~~~~~~~~~~~~~~
In file included from ../../tools/obexctl.c:29:
../../src/shared/shell.h:69:6: note: declared here
69 | void bt_shell_set_prompt(const char *string, const char *color);
| ^~~~~~~~~~~~~~~~~~~make[2]: *** [Makefile:7872: tools/bluetooth-player.o] Error 1
make[2]: *** Waiting for unfinished jobs....../../tools/obexctl.c: In function ‘main’:../../tools/obexctl.c:2155:2: error: too few arguments to function ‘bt_shell_set_prompt’
2155 | bt_shell_set_prompt(PROMPT_OFF);
| ^~~~~~~~~~~~~~~~~~~
In file included from ../../tools/obexctl.c:29:
../../src/shared/shell.h:69:6: note: declared here
69 | void bt_shell_set_prompt(const char *string, const char *color);
| ^~~~~~~~~~~~~~~~~~~make[2]: *** [Makefile:7872: tools/obexctl.o] Error 1 make[1]: *** [Makefile:4690: all] Error 2
make: *** [Makefile:12276: distcheck] Error 1
##############################
Test: CheckValgrind - FAIL
Desc: Run Bluez Make Check with Valgrind Output:
tools/mesh-cfgclient.c: In function ‘client_connected’:tools/mesh-cfgclient.c:2485:2: error: too few arguments to function ‘bt_shell_set_prompt’
2485 | bt_shell_set_prompt(PROMPT_ON);
| ^~~~~~~~~~~~~~~~~~~
In file included from tools/mesh-cfgclient.c:28:
./src/shared/shell.h:69:6: note: declared here
69 | void bt_shell_set_prompt(const char *string, const char *color);
| ^~~~~~~~~~~~~~~~~~~
tools/mesh-cfgclient.c: In function ‘main’:
tools/mesh-cfgclient.c:2645:2: error: too few arguments to function ‘bt_shell_set_prompt’
2645 | bt_shell_set_prompt(PROMPT_OFF);
| ^~~~~~~~~~~~~~~~~~~
In file included from tools/mesh-cfgclient.c:28:
./src/shared/shell.h:69:6: note: declared here
69 | void bt_shell_set_prompt(const char *string, const char *color);
| ^~~~~~~~~~~~~~~~~~~make[1]: *** [Makefile:7872: tools/mesh-cfgclient.o] Error 1 make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:12355: check] Error 2
##############################
Test: CheckSmatch - FAIL
Desc: Run smatch tool with source
Output:
src/shared/crypto.c:271:21: warning: Variable length array is used. src/shared/crypto.c:272:23: warning: Variable length array is used. src/shared/gatt-helpers.c:768:31: warning: Variable length array is used. src/shared/gatt-helpers.c:830:31: warning: Variable length array is used. src/shared/gatt-helpers.c:1323:31: warning: Variable length array is used. src/shared/gatt-helpers.c:1354:23: warning: Variable length array is used. src/shared/gatt-server.c:278:25: warning: Variable length array is used. src/shared/gatt-server.c:618:25: warning: Variable length array is used. src/shared/gatt-server.c:716:25: warning: Variable length array is used. src/shared/bap.c:288:25: warning: array of flexible structuressrc/shared/bap.c: note: in included file:./src/shared/ascs.h:88:25: warning: array of flexible structuressrc/shared/shell.c: note: in included file (through /usr/include/readline/readline.h):/usr/include/readline/rltypedefs.h:35:23: warning: non-ANSI function declaration of function 'Function' /usr/include/readline/rltypedefs.h:36:25: warning: non-ANSI function declaration of function 'VFunction' /usr/include/readline/rltypedefs.h:37:27: warning: non-ANSI function declaration of function 'CPFunction' /usr/include/readline/rltypedefs.h:38:29: warning: non-ANSI function declaration of function 'CPPFunction' tools/mesh-cfgclient.c: In function ‘client_connected’:tools/mesh-cfgclient.c:2485:2: error: too few arguments to function ‘bt_shell_set_prompt’
2485 | bt_shell_set_prompt(PROMPT_ON);
| ^~~~~~~~~~~~~~~~~~~
In file included from tools/mesh-cfgclient.c:28:
./src/shared/shell.h:69:6: note: declared here
69 | void bt_shell_set_prompt(const char *string, const char *color);
| ^~~~~~~~~~~~~~~~~~~
tools/mesh-cfgclient.c: In function ‘main’:
tools/mesh-cfgclient.c:2645:2: error: too few arguments to function ‘bt_shell_set_prompt’
2645 | bt_shell_set_prompt(PROMPT_OFF);
| ^~~~~~~~~~~~~~~~~~~
In file included from tools/mesh-cfgclient.c:28:
./src/shared/shell.h:69:6: note: declared here
69 | void bt_shell_set_prompt(const char *string, const char *color);
| ^~~~~~~~~~~~~~~~~~~make[1]: *** [Makefile:7872: tools/mesh-cfgclient.o] Error 1 make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:4690: all] Error 2
##############################
Test: bluezmakeextell - FAIL
Desc: Build Bluez with External ELL
Output:
tools/mesh-cfgclient.c: In function ‘client_connected’:tools/mesh-cfgclient.c:2485:2: error: too few arguments to function ‘bt_shell_set_prompt’
2485 | bt_shell_set_prompt(PROMPT_ON);
| ^~~~~~~~~~~~~~~~~~~
In file included from tools/mesh-cfgclient.c:28:
./src/shared/shell.h:69:6: note: declared here
69 | void bt_shell_set_prompt(const char *string, const char *color);
| ^~~~~~~~~~~~~~~~~~~
tools/mesh-cfgclient.c: In function ‘main’:
tools/mesh-cfgclient.c:2645:2: error: too few arguments to function ‘bt_shell_set_prompt’
2645 | bt_shell_set_prompt(PROMPT_OFF);
| ^~~~~~~~~~~~~~~~~~~
In file included from tools/mesh-cfgclient.c:28:
./src/shared/shell.h:69:6: note: declared here
69 | void bt_shell_set_prompt(const char *string, const char *color);
| ^~~~~~~~~~~~~~~~~~~make[1]: *** [Makefile:7872: tools/mesh-cfgclient.o] Error 1 make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:4690: all] Error 2
##############################
Test: IncrementalBuild - FAIL
Desc: Incremental build with the patches in the series Output:
[BlueZ,v1] shared/shell: Fix not handling prompt with color properly
tools/mesh-cfgclient.c: In function ‘client_connected’:tools/mesh-cfgclient.c:2485:2: error: too few arguments to function ‘bt_shell_set_prompt’
2485 | bt_shell_set_prompt(PROMPT_ON);
| ^~~~~~~~~~~~~~~~~~~
In file included from tools/mesh-cfgclient.c:28:
./src/shared/shell.h:69:6: note: declared here
69 | void bt_shell_set_prompt(const char *string, const char *color);
| ^~~~~~~~~~~~~~~~~~~
tools/mesh-cfgclient.c: In function ‘main’:
tools/mesh-cfgclient.c:2645:2: error: too few arguments to function ‘bt_shell_set_prompt’
2645 | bt_shell_set_prompt(PROMPT_OFF);
| ^~~~~~~~~~~~~~~~~~~
In file included from tools/mesh-cfgclient.c:28:
./src/shared/shell.h:69:6: note: declared here
69 | void bt_shell_set_prompt(const char *string, const char *color);
| ^~~~~~~~~~~~~~~~~~~make[1]: *** [Makefile:7872: tools/mesh-cfgclient.o] Error 1 make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:4690: all] Error 2
##############################
Test: ScanBuild - FAIL
Desc: Run Scan Build
Output:
src/shared/gatt-client.c:451:21: warning: Use of memory after it is freed
gatt_db_unregister(op->client->db, op->db_id);
^~~~~~~~~~
src/shared/gatt-client.c:696:2: warning: Use of memory after it is freed
discovery_op_complete(op, false, att_ecode);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:996:2: warning: Use of memory after it is freed
discovery_op_complete(op, success, att_ecode);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1102:2: warning: Use of memory after it is freed
discovery_op_complete(op, success, att_ecode);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1296:2: warning: Use of memory after it is freed
discovery_op_complete(op, success, att_ecode);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1361:2: warning: Use of memory after it is freed
discovery_op_complete(op, success, att_ecode);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1636:6: warning: Use of memory after it is freed
if (read_db_hash(op)) {
^~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1641:2: warning: Use of memory after it is freed
discover_all(op);
^~~~~~~~~~~~~~~~
src/shared/gatt-client.c:2145:6: warning: Use of memory after it is freed
if (read_db_hash(op)) {
^~~~~~~~~~~~~~~~
src/shared/gatt-client.c:2153:8: warning: Use of memory after it is freed
discovery_op_ref(op),
^~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:3242:2: warning: Use of memory after it is freed
complete_write_long_op(req, success, 0, false);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:3264:2: warning: Use of memory after it is freed
request_unref(req);
^~~~~~~~~~~~~~~~~~
12 warnings generated.
tools/mesh-cfgclient.c: In function ‘client_connected’:
tools/mesh-cfgclient.c:2485:2: error: too few arguments to function ‘bt_shell_set_prompt’
2485 | bt_shell_set_prompt(PROMPT_ON);
| ^~~~~~~~~~~~~~~~~~~
In file included from tools/mesh-cfgclient.c:28:
./src/shared/shell.h:69:6: note: declared here
69 | void bt_shell_set_prompt(const char *string, const char *color);
| ^~~~~~~~~~~~~~~~~~~
tools/mesh-cfgclient.c: In function ‘main’:
tools/mesh-cfgclient.c:2645:2: error: too few arguments to function ‘bt_shell_set_prompt’
2645 | bt_shell_set_prompt(PROMPT_OFF);
| ^~~~~~~~~~~~~~~~~~~
In file included from tools/mesh-cfgclient.c:28:
./src/shared/shell.h:69:6: note: declared here
69 | void bt_shell_set_prompt(const char *string, const char *color);
| ^~~~~~~~~~~~~~~~~~~make[1]: *** [Makefile:7872: tools/mesh-cfgclient.o] Error 1 make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:4690: all] Error 2
---
Regards,
Linux Bluetooth