From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 28935 invoked from network); 30 Jan 2023 00:25:59 -0000 Received: from minnie.tuhs.org (50.116.15.146) by inbox.vuxu.org with ESMTPUTF8; 30 Jan 2023 00:25:59 -0000 Received: from minnie.tuhs.org (localhost [IPv6:::1]) by minnie.tuhs.org (Postfix) with ESMTP id 6343C425B1; Mon, 30 Jan 2023 10:25:42 +1000 (AEST) Received: from mail.ultimate.com (mail.ultimate.com [104.225.1.121]) by minnie.tuhs.org (Postfix) with ESMTPS id C7414425B0 for ; Mon, 30 Jan 2023 10:25:36 +1000 (AEST) Received: from ultimate.com (localhost [127.0.0.1]) by mail.ultimate.com (8.16.1/8.16.1) with ESMTPS id 30U0PHCa022104 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Sun, 29 Jan 2023 19:25:17 -0500 (EST) (envelope-from phil@ultimate.com) Received: (from phil@localhost) by ultimate.com (8.16.1/8.16.1/Submit) id 30U0PHEh022103; Sun, 29 Jan 2023 19:25:17 -0500 (EST) (envelope-from phil) From: Phil Budne Message-Id: <202301300025.30U0PHEh022103@ultimate.com> Date: Sun, 29 Jan 2023 19:25:17 -0500 To: tuhs@tuhs.org References: In-Reply-To: User-Agent: Heirloom mailx 12.4 7/29/08 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID-Hash: MTBVKZR4DWZR3PHNNCLRS3FTRGI3IF6K X-Message-ID-Hash: MTBVKZR4DWZR3PHNNCLRS3FTRGI3IF6K X-MailFrom: phil@ultimate.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-tuhs.tuhs.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.6b1 Precedence: list Subject: [TUHS] Re: FD 2 List-Id: The Unix Heritage Society mailing list Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 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