diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | cmdedit.c | 4 | ||||
-rw-r--r-- | hush.c | 6 | ||||
-rw-r--r-- | include/libbb.h | 1 | ||||
-rw-r--r-- | lash.c | 9 | ||||
-rw-r--r-- | libbb/libbb.h | 1 | ||||
-rw-r--r-- | libbb/messages.c | 3 | ||||
-rw-r--r-- | shell/cmdedit.c | 4 | ||||
-rw-r--r-- | shell/hush.c | 6 | ||||
-rw-r--r-- | shell/lash.c | 9 |
10 files changed, 40 insertions, 5 deletions
@@ -259,7 +259,7 @@ endif LIBBB_MSRC=libbb/messages.c LIBBB_MESSAGES= full_version name_too_long omitting_directory not_a_directory \ memory_exhausted invalid_date invalid_option io_error dash_dash_help \ -write_error too_few_args name_longer_than_foo +write_error too_few_args name_longer_than_foo unknown LIBBB_MOBJ=$(patsubst %,$(LIBBB)/%.o, $(LIBBB_MESSAGES)) @@ -355,6 +355,10 @@ static void parse_prompt(const char *prmt_ptr) char c; char *pbuf; + if (!pwd_buf) { + pwd_buf=unknown; + } + while (*prmt_ptr) { pbuf = buf; pbuf[1] = 0; @@ -429,6 +429,8 @@ static int builtin_cd(struct child_prog *child) return EXIT_FAILURE; } cwd = xgetcwd(cwd); + if (!cwd) + cwd = unknown; return EXIT_SUCCESS; } @@ -568,6 +570,8 @@ static int builtin_jobs(struct child_prog *child) static int builtin_pwd(struct child_prog *dummy) { cwd = xgetcwd(cwd); + if (!cwd) + cwd = unknown; puts(cwd); return EXIT_SUCCESS; } @@ -2307,6 +2311,8 @@ int shell_main(int argc, char **argv) /* initialize the cwd -- this is never freed...*/ cwd = xgetcwd(0); + if (!cwd) + cwd = unknown; #ifdef BB_FEATURE_COMMAND_EDITING cmdedit_set_initial_prompt(); #else diff --git a/include/libbb.h b/include/libbb.h index 21af568..fde58b0 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -282,5 +282,6 @@ extern const char * const dash_dash_help; extern const char * const write_error; extern const char * const too_few_args; extern const char * const name_longer_than_foo; +extern const char * const unknown; #endif /* __LIBBB_H__ */ @@ -297,7 +297,8 @@ static int builtin_cd(struct child_prog *child) return EXIT_FAILURE; } cwd = xgetcwd(cwd); - + if (!cwd) + cwd = unknown; return EXIT_SUCCESS; } @@ -412,6 +413,9 @@ static int builtin_jobs(struct child_prog *child) /* built-in 'pwd' handler */ static int builtin_pwd(struct child_prog *dummy) { + cwd = xgetcwd(cwd); + if (!cwd) + cwd = unknown; printf( "%s\n", cwd); return EXIT_SUCCESS; } @@ -1827,7 +1831,6 @@ void free_memory(void) { if (cwd) { free(cwd); - cwd = NULL; } if (local_pending_command) free(local_pending_command); @@ -1919,6 +1922,8 @@ int shell_main(int argc_l, char **argv_l) /* initialize the cwd -- this is never freed...*/ cwd = xgetcwd(0); + if (!cwd) + cwd = unknown; #ifdef BB_FEATURE_CLEAN_UP atexit(free_memory); diff --git a/libbb/libbb.h b/libbb/libbb.h index 21af568..fde58b0 100644 --- a/libbb/libbb.h +++ b/libbb/libbb.h @@ -282,5 +282,6 @@ extern const char * const dash_dash_help; extern const char * const write_error; extern const char * const too_few_args; extern const char * const name_longer_than_foo; +extern const char * const unknown; #endif /* __LIBBB_H__ */ diff --git a/libbb/messages.c b/libbb/messages.c index 99c2bc9..910cb8f 100644 --- a/libbb/messages.c +++ b/libbb/messages.c @@ -58,4 +58,7 @@ #ifdef L_name_longer_than_foo const char * const name_longer_than_foo = "Names longer than %d chars not supported."; #endif +#ifdef L_unknown + const char * const unknown = "(unknown)"; +#endif diff --git a/shell/cmdedit.c b/shell/cmdedit.c index ce54500..ec99393 100644 --- a/shell/cmdedit.c +++ b/shell/cmdedit.c @@ -355,6 +355,10 @@ static void parse_prompt(const char *prmt_ptr) char c; char *pbuf; + if (!pwd_buf) { + pwd_buf=unknown; + } + while (*prmt_ptr) { pbuf = buf; pbuf[1] = 0; diff --git a/shell/hush.c b/shell/hush.c index abc8f6e..9a2243a 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -429,6 +429,8 @@ static int builtin_cd(struct child_prog *child) return EXIT_FAILURE; } cwd = xgetcwd(cwd); + if (!cwd) + cwd = unknown; return EXIT_SUCCESS; } @@ -568,6 +570,8 @@ static int builtin_jobs(struct child_prog *child) static int builtin_pwd(struct child_prog *dummy) { cwd = xgetcwd(cwd); + if (!cwd) + cwd = unknown; puts(cwd); return EXIT_SUCCESS; } @@ -2307,6 +2311,8 @@ int shell_main(int argc, char **argv) /* initialize the cwd -- this is never freed...*/ cwd = xgetcwd(0); + if (!cwd) + cwd = unknown; #ifdef BB_FEATURE_COMMAND_EDITING cmdedit_set_initial_prompt(); #else diff --git a/shell/lash.c b/shell/lash.c index 1d12835..0129d6c 100644 --- a/shell/lash.c +++ b/shell/lash.c @@ -297,7 +297,8 @@ static int builtin_cd(struct child_prog *child) return EXIT_FAILURE; } cwd = xgetcwd(cwd); - + if (!cwd) + cwd = unknown; return EXIT_SUCCESS; } @@ -412,6 +413,9 @@ static int builtin_jobs(struct child_prog *child) /* built-in 'pwd' handler */ static int builtin_pwd(struct child_prog *dummy) { + cwd = xgetcwd(cwd); + if (!cwd) + cwd = unknown; printf( "%s\n", cwd); return EXIT_SUCCESS; } @@ -1827,7 +1831,6 @@ void free_memory(void) { if (cwd) { free(cwd); - cwd = NULL; } if (local_pending_command) free(local_pending_command); @@ -1919,6 +1922,8 @@ int shell_main(int argc_l, char **argv_l) /* initialize the cwd -- this is never freed...*/ cwd = xgetcwd(0); + if (!cwd) + cwd = unknown; #ifdef BB_FEATURE_CLEAN_UP atexit(free_memory); |