Re: getcwd() returns with stale errno value upon error

2025-06-26 Thread Chet Ramey
On 6/25/25 3:44 AM, Richard Weinberger wrote: Bash Version: 5.2 Patch Level: 37 Release Status: release Description: getcwd() as implemented in lib/sh/getcwd.c can return with NULL and a stale errno value if the algorithm fails. It aborts if readdir() returns NULL and

Re: getcwd() returns with stale errno value upon error

2025-06-26 Thread Oğuz
On Thursday, June 26, 2025, Martin D Kealey wrote: > There's a fairly obvious race condition where another process replaces a > directory entry That's not the case here. between readlink and lstat. Who said anything about them? > I would like bash to cope more gracefully with "unexpected"

Re: getcwd() returns with stale errno value upon error

2025-06-26 Thread Martin D Kealey
On Thu, 26 Jun 2025 at 04:07, Oğuz wrote: > On Wednesday, June 25, 2025, Richard Weinberger > wrote: > > > > This can happen on filesystems where d_ino != st_ino > > i.e. a broken filesystem. Or not broken. There's a fairly obvious race condition where another process replaces a direc

Re: getcwd() returns with stale errno value upon error

2025-06-25 Thread Richard Weinberger
On Donnerstag, 26. Juni 2025 08:45 Phi Debian wrote: > That's true that the bash shell-init: could be omitted and defered until > one ask for pwd explicitly. > > I don't see any *ino* jazz here, but the classic, my current dir has been > removed under my feet. > > I may have mis-read the *ino* pa

Re: getcwd() returns with stale errno value upon error

2025-06-25 Thread Phi Debian
In the given reproducer, I am not sure btrfs is relevant here on my good'ol ext4 I got. $ mount | grep '/d2 ' | sed 's/(.*//' /dev/sda1 on /d2 type ext4 $ cd /d2 ; mkdir -p a/b/c ; cd a/b/c ; rmdir /d2/a/b/c $ bash -c 'pwd' shell-init: error retrieving current directory: getcwd: cannot access pa

Re: getcwd() returns with stale errno value upon error

2025-06-25 Thread Richard Weinberger
On Mittwoch, 25. Juni 2025 21:28 Oğuz wrote: > On Wednesday, June 25, 2025, Richard Weinberger > wrote: > > > > I'm not asking you to implement a workaround > > > I'm just another user. I agree that a descriptive error message is better > than a random one. But if your system can't return the sa

Re: getcwd() returns with stale errno value upon error

2025-06-25 Thread Oğuz
On Wednesday, June 25, 2025, Richard Weinberger wrote: > > I'm not asking you to implement a workaround I'm just another user. I agree that a descriptive error message is better than a random one. But if your system can't return the same inode number for the same file from two standard functions

Re: getcwd() returns with stale errno value upon error

2025-06-25 Thread Oğuz
On Wednesday, June 25, 2025, Richard Weinberger wrote: > > This can happen on filesystems where d_ino != st_ino i.e. a broken filesystem. What does any of this have to do with bash? -- Oğuz

Re: getcwd() returns with stale errno value upon error

2025-06-25 Thread Oğuz
On Wednesday, June 25, 2025, Richard Weinberger wrote: > > Having different results for d_ino and st_ino is not that uncommon. > POSIX defines both fields to contain the unique serial number of a file in a filesystem. I don't think Bash is at fault here for not assuming otherwise. -- Oğuz

Re: getcwd() returns with stale errno value upon error

2025-06-25 Thread Richard Weinberger
Hello Oğuz, On Mittwoch, 25. Juni 2025 20:07 Oğuz wrote: > On Wednesday, June 25, 2025, Richard Weinberger > wrote: > > > > This can happen on filesystems where d_ino != st_ino > > > i.e. a broken filesystem. What does any of this have to do with bash? Bash could, for example, check th

getcwd() returns with stale errno value upon error

2025-06-25 Thread Richard Weinberger
Configuration Information [Automatically generated, do not change][RW: The configuration info generated by bashbug is useless, as it is a cross build]: Machine: x86_64 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -g -O2 uname output: Linux foxxylove 6.4.0-150600.23.47-default #1 SMP PREEMPT_DYN