[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [PATCH] lineedit: get PWD from ash
From:       Denys Vlasenko <vda.linux () googlemail ! com>
Date:       2022-07-03 19:44:27
Message-ID: CAK1hOcP9cg375gXUOzG5FKSyfag7nG2vrrqWeBDocha0SnyvSA () mail ! gmail ! com
[Download RAW message or body]

Applied, thank you.

On Tue, Jun 28, 2022 at 2:46 PM Ron Yorston <rmy@pobox.com> wrote:
> 
> The line editing code and ash disagree when the current directory
> is changed to a symbolic link:
> 
> ~ $ mkdir real
> ~ $ ln -s real link
> ~ $ cd link
> ~/real $ pwd
> /home/rmyf36/link
> 
> Note the prompt says we're in ~/real.  Bash does:
> 
> [rmy@random ~]$ cd link
> [rmy@random link]$ pwd
> /home/rmyf36/link
> 
> Ash uses the name supplied by the user while the line editing code
> calls getcwd(3).  The discrepancy can be avoided by fetching the
> value of PWD from ash.
> 
> Hush (incorrectly?) calls getcwd(3) when the directory is changed
> so there's no disagreement with the line editing code.
> 
> function                                             old     new   delta
> parse_and_put_prompt                                 921     904     -17
> 
> Signed-off-by: Ron Yorston <rmy@pobox.com>
> ---
> libbb/lineedit.c | 6 ++++++
> 1 file changed, 6 insertions(+)
> 
> diff --git a/libbb/lineedit.c b/libbb/lineedit.c
> index b685399f9..27b5ef30e 100644
> --- a/libbb/lineedit.c
> +++ b/libbb/lineedit.c
> @@ -2035,7 +2035,13 @@ static void parse_and_put_prompt(const char *prmt_ptr)
> case 'W': /* basename of cur dir */
> if (!cwd_buf) {
> const char *home;
> +#if ENABLE_SHELL_ASH
> +                                               cwd_buf = state->sh_get_var ?
> +                                                               \
> xstrdup(state->sh_get_var("PWD")) : +                                               \
> xrealloc_getcwd_or_warn(NULL); +#else
> cwd_buf = xrealloc_getcwd_or_warn(NULL);
> +#endif
> if (!cwd_buf)
> cwd_buf = (char *)bb_msg_unknown;
> else if ((home = get_homedir_or_NULL()) != NULL && home[0]) {
> --
> 2.36.1
> 
> _______________________________________________
> busybox mailing list
> busybox@busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic