Article View: net.bugs.usg
Article #26popen bug
From: Kenneth Almquist
Date: Tue, 22 Nov 1983 17:01
Date: Tue, 22 Nov 1983 17:01
23 lines
1354 bytes
1354 bytes
When a program is invoked from cron, the standard input is not openned,
which will confuse some programs. In particular, it will confuse any
program that uses popen to write to a program, at least under System V,
unless you install this fix. Popen forks off a child and then redirects
the standard input or output of the child with code that looks like:
(void) close(stdio);
(void) fcntl(yourside, 0, stdio);
(void) close(yourside);
That code fails if stdio and yourside are identical; the fix is to add
a test for this case:
if (yourside != stdio) {
(void) close(stdio);
(void) fcntl(yourside, 0, stdio);
(void) close(yourside);
}
By the way, the zero in the call to fcntl is the F_DUPFD function which
is the USG means of duplicating a file descriptor.
Kenneth Almquist
{mhtsa,ihnp4}!hou3c!ka
Technical Details
Message-ID:
<118@hou3c.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!linus!philabs!seismo!harpo!floyd!clyde!burl!hou3c!kaShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site hou3c.UUCP Path: arc1-ca.pugleaf.net!utzoo!linus!philabs!seismo!harpo!floyd!clyde!burl!hou3c!ka From: ka@hou3c.UUCP (Kenneth Almquist) Newsgroups: net.bugs.usg,net.unix-wizards Subject: popen bug Message-ID: <118@hou3c.UUCP> Date: Tue, 22-Nov-83 12:01:30 EST Article-I.D.: hou3c.118 Posted: Tue Nov 22 12:01:30 1983 Date-Received: Fri, 25-Nov-83 04:18:44 EST Organization: Bell Labs, Holmdel, NJ Lines: 23