popen bug

Kenneth Almquist ka at hou3c.UUCP
Wed Nov 23 03:01:30 AEST 1983


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



More information about the Comp.unix.wizards mailing list