From 3e385d22cc57aacddafe38a1b6bcd55aa71d3c80 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 24 Mar 2022 11:43:37 +0000 Subject: ash,hush: use HOME for tab completion and prompts ash and hush correctly use the value of HOME for tilde expansion. However the line editing code in libbb obtains the user's home directory by calling getpwuid(). Thus tildes in tab completion and prompts may be interpreted differently than in tilde expansion. When the line editing code is invoked from a shell make it use the shell's interpretation of tilde. This is similar to how GNU readline and bash collaborate. function old new delta get_homedir_or_NULL 29 72 +43 optschanged 119 126 +7 hush_main 1204 1211 +7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 57/0) Total: 57 bytes v2: Always check for HOME before trying the password database: this is what GNU readline does. Signed-off-by: Ron Yorston --- include/libbb.h | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'include/libbb.h') diff --git a/include/libbb.h b/include/libbb.h index 740c25528..1c9198945 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1984,6 +1984,7 @@ unsigned size_from_HISTFILESIZE(const char *hp) FAST_FUNC; # define MAX_HISTORY 0 # endif typedef const char *get_exe_name_t(int i) FAST_FUNC; +typedef const char *sh_get_var_t(const char *name) FAST_FUNC; typedef struct line_input_t { int flags; int timeout; @@ -1997,9 +1998,8 @@ typedef struct line_input_t { # if ENABLE_SHELL_ASH || ENABLE_SHELL_HUSH /* function to fetch additional application-specific names to match */ get_exe_name_t *get_exe_name; -# define EDITING_HAS_get_exe_name 1 -# else -# define EDITING_HAS_get_exe_name 0 + /* function to fetch value of shell variable */ + sh_get_var_t *sh_get_var; # endif # endif # if MAX_HISTORY @@ -2053,11 +2053,6 @@ int read_line_input(const char* prompt, char* command, int maxsize) FAST_FUNC; read_line_input(prompt, command, maxsize) #endif -#ifndef EDITING_HAS_get_exe_name -# define EDITING_HAS_get_exe_name 0 -#endif - - #ifndef COMM_LEN # ifdef TASK_COMM_LEN enum { COMM_LEN = TASK_COMM_LEN }; -- cgit v1.2.3-55-g6feb