On Sun, Jan 29, 2023, 5:25 PM Phil Budne <phil@ultimate.com> wrote:
Ron Natalie wrote:
> Warner Losh wrote:
> >"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).
> >
> Unfortunately, the source code says otherwise.   None of shells V6, PWB,
> V7 do anything like is mentioned above.   They assume 0 and 1 (and 2)
> are already open.
> The only fd redirection they do is when you do pipes or redirection on
> the command line.
>
> Where this is done is, as I posted earlier, in /etc/init.    Init opens
> the tty device and dups it to 1 and then invokes either the shell (if
> we're in single user mode) or getty for interactive mode.
> This was done in V6 and PWB (1).   In V7, init added a second dup for
> file descriptor 2.

I think the text Warner quoted applied to only the pre-fork version of
the system, since it's preceeded by:

  "Processes (independently executing entities) existed very early in
  PDP-7 Unix. There were in fact precisely two of them, one for each
  of the two terminals attached to the machine. There was no fork,
  wait, or exec. There was an exit, but its meaning was rather
  different, as will be seen.

and ends with:

  "4) The command did its work, then terminated by calling exit. The
  exit call caused the system to read in a fresh copy of the shell
  over the terminated command, then to jump to its start (and thus in
  effect to go to step 1)."

In the (late) PDP-7 Unix we have sources for, FDs 1 & 2 are
established in init at labels init1 (for the user on the console tty)
and init2 (for the user on the display & display keyboard) after forking
and doing the job of the login executable:

https://github.com/DoctorWkt/pdp7-unix/blob/master/src/cmd/init.s


It looks like 0 & 1 to me. Am I missing something?

Warner

A remaining mystery about the set of PDP-7 Unix sources we have is
that cat.s (and only cat.s?) writes error messages to FD 8, but I
haven't seen any place that sets FD 8:

https://github.com/DoctorWkt/pdp7-unix/blob/master/scans/cat.s#L43
https://github.com/DoctorWkt/pdp7-unix/blob/master/scans/cat.s#L45
https://github.com/DoctorWkt/pdp7-unix/blob/master/scans/cat.s#L51

Listing scan at:
https://www.tuhs.org/Archive/Distributions/Research/McIlroy_v0/06-5-12.pdf#page=21