On Sun, Jan 22, 2023 at 2:23 PM Warner Losh <imp(a)bsdimp.com> wrote:
On Sat, Jan 21, 2023 at 11:37 AM Warner Losh <imp(a)bsdimp.com> wrote:
Yea. Like many things, there was a transition... the most important bit
is the shell. And that was more tricky to read through with the phone at
breakfast...
OK. I've dug a bit further and Clem and I have chatted... Here's the
summary.
We don't have V4's shell, alas, since all we have from that time period is
the C kernel a few months before the 4th edition release. V5 /bin/sh closes
fd2 and then dups fd1 to fd2. This creates fd2 as something special. V6
closes all FD's larger than 1 (2-15) and then does the dup(1) which it
makes sure returns 2 or it closes the file. While there were features in V6
to allow use of fd2/stderr, few programs used then.
And neither crypt nor passwd reads from fd2. crypt reads from fd0, while
passwd doesn't read. It just replaces the hashed password with the new
password. I've also looked at pr because
I do remember that pr -p actually read from FD 2.
It probably still does.
and that's not true in V7 at least... pr didn't have a 'p' arg :).
Maybe
later programs started to do these things, but most of what went on with V7
was a transition to most error messages on stderr, which typically went to
stdout in V6.
So, people remembering it coming in with V7 are right, in the sense it was
the first release to do it consistently. And the people remembering V4 or
V5 are also right, in a different sense because the shell was ensuring fd2
was a copy of fd1 there, which a couple of programs (diff) used for errors.
And I believe that the impetus for the V7 changes was phototypesetting
'file not found' too often... But that last bit is mostly because I want
to believe.
One last historical footnote. In researching a forthcoming article for the
30th anniversary of FreeBSD, I noticed the following:
https://www.bell-labs.com/usr/dmr/www/hist.pdf contains Dennis Ritchie's
history of the early days of Unix. It was first published in 1979 (so right
around the time V7 was being finalized), and revised/reprinted in the
famous AT&T Bell Laboratories Technical Journal 63 No. 6 Part 2, October
1984 issue. He talks about FD 0 and FD 1 being special in the pdp-7
implementation on page 4:
"The main loop of the shell went as follows:
1) The shell closed all its open files, then opened the terminal special
file for standard input and output (file descriptors 0 and 1).
..."
No mention is made of when fd 2 became standard error in this paper, which
does mention a lot of other unix milestones (hierarchical notation for
directories, fork/exec changes, pipes, etc), but not this one.
Warner