4 ms·
Wow great bug! > Bash forgot to reset errno before the call. For about 30 years, no one noticed I have to say, this part of the POSIX API is maddening! 99% o
by chubot 1y ago
Wow great bug!
> Bash forgot to reset errno before the call. For about 30 years, no one noticed
I have to say, this part of the POSIX API is maddening!
99% of the time, you don't need to set errno = 0 before making a call. You check for a non-zero return, and only then look at errno.
But SOMETIMES you need to set errno = 0, because in this case readdir() returns NULL on both error and EOF.
I actually didn't realize this before working on https://oils.pub/ https://oils.pub/
---
And it should go without saying: Oils simply uses libc - we don't need to support system with a broken getcwd()!
Although a funny thing is that I just fixed a bug related to $PWD that AT&T ksh (the original shell, that bash is based on) hasn't fixed for 30+ years too!
(and I didn't realize it was still maintained)
https://www.illumos.org/issues/17442 https://www.illumos.org/issues/17442
https://github.com/oils-for-unix/oils/issues/2058 https://github.com/oils-for-unix/oils/issues/2058
There is a subtle issue with respect to:
1) "trusting" the $PWD value you inherit from another process
2) Respecting symlinks - this is the reason the shell can't just call getcwd() !
if (*p != '/' || stat(p, &st1) || stat(".", &st2) ||
st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino)
p = 0;
Basically, the shell considers BOTH the inherited $PWD and the value of getcwd() to determine its $PWD. It can't just use one or the other!
- JdeBP 1y agoThe Bourne Again shell is not based upon the Korn shell. There's a very big clue in its name which prior shell the Bourne Again shell started out to clone. (-:
- chubot 1y agoI'm saying the behavior of bash is largely based on ksh. See https://pages.oils.pub/spec-compat/2025-06-19/renamed-tmp/spec/compat/PASSING.html https://pages.oils.pub/spec-compat/2025-06-19/renamed-tmp/sp... (which I created) Even the upcoming bash 5.4 implement ksh command sub ${ echo hi; }, which is more evidence that bash is based on ksh. They're still implementing ksh 35 years later ...
- JdeBP 1y agoThe unequivocal direct evidence that the Bourne Again shell is based upon the Bourne shell is Richard Stallman saying so, back when it was written in 1988. "Foundation staff member Brian Fox is now implementing an imitation of the Bourne shell."
- chubot 1y agoksh is a superset of Bourne shell https://www.oilshell.org/archive/ksh-usenix.pdf https://www.oilshell.org/archive/ksh-usenix.pdf bash implemented essentially all Bourne shell features a long time ago -- and for the last decade+, and currently, it's implementing ksh features I'm not sure why it's hard to hold those 2 ideas in your head at the same time
- alganet 1y ago> and I didn't realize it was still maintained ksh _was_ unmaintained for ages. It stopped effectively in 2012, with some very small attempts at reviving it in 2016, 2018 and 2020. Then it was picked up for active development in 2021, and it lives here now: https://github.com/ksh93/ksh https://github.com/ksh93/ksh If you didn't already, you should open an issue there with your findings. -- Shameless plug: I keep some docker images with all those versions for testing, and many other shells too both historical and active (including osh!) https://github.com/alganet/shell-versions/blob/main/.github/workflows/docker-build.yml#L44 https://github.com/alganet/shell-versions/blob/main/.github/...