🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: fa.unix-wizards
1 messages
1 total messages Started by ucbvaxunix-wizards Sun, 27 Dec 1981 04:00
POPEN(III) in V7 Stdio
#326
Author: ucbvaxunix-wizards
Date: Sun, 27 Dec 1981 04:00
27 lines
1732 bytes
>From wales@UCLA-Security Sun Dec 27 03:45:18 1981
RE:  The idea of making "popen" close all file descriptors except 0, 1, and 2

We are running 4.1BSD on VAXen here.  Some time ago, we discovered a maddening
bug in "popen".  If you have two concurrent "popen" processes and are writing
down a pipe to the first one, you cannot cause an EOF on the first pipe while
the second process is still around.  This is because the second process has
(quite obliviously) inherited the first process's pipe.

The solution someone here came up with was to have "popen" keep a static array,
indexed by file descriptor number, in which each pipe produced by "popen" would
be associated with the process number of the corresponding child process.  When
a second (third, etc.) "popen" was issued, this array would be scanned and any
active pipes would be closed in the new child process.  When a child exited,
"pclose" would search for, and clear out, the appropriate array entry.

This is admittedly more work than simply closing everything except stdin,
stdout, and stderr, but at least it seems to do the minimum necessary action
required to fix the problem.

I guess my only reservation about having "popen" close everything in sight is
that someone might want to run a program in which an open file is passed via a
known file descriptor other than 0, 1, or 2.  Since such programs are quite
rare in UNIX, though, maybe it would be OK to force the person to use "fork"
and "exec" manually in such cases.

-- Rich
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads