From owner-freebsd-hackers Tue Mar 18 22:53:16 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id WAA20658 for hackers-outgoing; Tue, 18 Mar 1997 22:53:16 -0800 (PST) Received: from bunyip.cc.uq.edu.au (bunyip.cc.uq.edu.au [130.102.2.1]) by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id WAA20646 for ; Tue, 18 Mar 1997 22:53:06 -0800 (PST) Received: (from daemon@localhost) by bunyip.cc.uq.edu.au (8.8.5/8.8.5) id QAA23547; Wed, 19 Mar 1997 16:50:20 +1000 Received: by ogre.dtir.qld.gov.au (8.7.5/DEVETIR-E0.3a) id QAA16421; Wed, 19 Mar 1997 16:40:30 +1000 (EST) Date: Wed, 19 Mar 1997 16:40:30 +1000 (EST) From: Stephen McKay Message-Id: <199703190640.QAA16421@ogre.dtir.qld.gov.au> To: "Jordan K. Hubbard" cc: freebsd-hackers@freebsd.org, syssgm@dtir.qld.gov.au Subject: Re: REPOST: dup3() - interesting feature-in-training or silly hack? X-Newsreader: NN version 6.5.0 #1 (NOV) Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk "Jordan K. Hubbard" wrote: >The subject alone should have the kernel hackers all running for >shelter at this point - "Aigh! He's looking in /usr/src/sys!" >they yell. "Somebody stop him!!" :-) Jordan, Jordan, Jordan! I'm speechless! I think you should have a bit of a rest. Reality should return in a few hours. Unless you took a lot of it, then you might be OK in a few days. To be serious for a moment, this extra utility does not justify the cost. The cost is in degrading our process model. Before this change, a process had certain guarantees and had to ask explicitly for things to happen to it except for 2 things: external signals, and debugging (ptrace). Debugging has to be external to the process. External signals (unlike internally requested signals like timed alarms and child status changes) are usually fatal, and so cause a relatively simple cleanup and exit. The proposed "dup3" adds a new class of invasive system calls. Where does it stop? remote_chdir()? remote_putenv()? The guaranteed boundaries between processes that allow the programmer to be certain of what will work are eroded by the proposed dup3, and by all similar "pull the rug out from under it" mechanisms. (I forgot revoke() back there a bit. It, like external signals, is for fatal conditions only.) >So what's the use of it? To use in things like shells, so that you >can do stuff like this: > ># make world > >^Z%1 Suspended ># bg > make.out ># > >This also works with fg, so you can foreground and redirect stdin, >stdout and stderr at the same time just as easily. There are at least two solutions to this problem, one simple, one complex. I have an alias that always stores the output of make into a file. I can then use tail -f to look at it in real time, or simply wait for later. The more complex version is to change your shell to allocate a virtual terminal to every command and manage the output. Thus, your shell could simply copy the output from make's virtual terminal to your main terminal (virtual or real), or when commanded, it could copy it to a file, or feed it to another pipeline. Similarly for input. This would not violate the sanctity of the processes involved. Then, if you wanted to optimise slightly, you could hack your kernel to plug the output of one virtual terminal directly into the output of another one, avoiding the overhead of the usual case of background processes writing to your terminal. That would be a nicer kernel project. :-) >Feedback most welcome. I think you've had an interesting learning experience doing this (tragic) thing to your kernel, but now you should put it all back. Stephen.