Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: wja@cs.nott.ac.uk (William Armitage)
Subject: Re: Fork bug in Sys5 (or similar) system
Date: Thu, 26 May 94 18:16:12 GMT	[thread overview]
Message-ID: <1994May26.181612.1484@cs.nott.ac.uk> (raw)
In-Reply-To: 2s1kg2$7or@mail.fwi.uva.nl

casper@fwi.uva.nl (Casper H.S. Dik) writes:

 > jin@eubie.lbl.gov (Guojun Jin[ITG]) writes:
 > 
 > >In sys5 or similar system, the fork() will misplace a file position in a pointer
 > >which opened by a parent and passed to children.  The bugs affects only fread().
 > >fwrite() has not been tested yet, but similar peoblem should exist.
 > 
 > You're not allowed to call exit(3) after fork(), unless you
 > flush all files before calling fork().
 > 
 > Casper
 > 

This seems to be a change introduced to support Multi-Threading.
I hit this the other day while getting the Solaris 2 port of the Berkeley
spooler going on my 2.3 machine. At startup the deamon forks a copy of
itself for each printer to process any existing print jobs.
The loop is basicaly -

	pfp = fopen("/etc/printcap", "r");

	while (fgets(buf, sizeof(buf), pfp)) {
		if (fork() == 0) {
			fclose(pfp);
			...
			exit();
		}
	}

lpd ran away forking printer processes. Trussing things showed that the
fclose was doing an lseek before closing. Putting an fflush before the
fork solved the problem.
I'd not seen this mentioned anywhere before i reread the fclose manual page.
It needs a mention in the solaris porting FAQ.

*** printcap.c.orig	Wed Sep  8 11:09:51 1993
--- printcap.c	Tue May 24 21:20:07 1994
***************
*** 29,34 ****
--- 29,41 ----
   * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
+  *
+  * wja@cs.nott.ac.uk - Tue May 24 21:16:32 BST 1994
+  *
+  * New class of Solaris 2 porting problem. The 2.3 fclose will do a lseek
+  * on a file descripter if open for reading and not at end of file. This
+  * can be unfortunate in the presence of fork/fclose.
+  * Place fflush before returns from  getprent().
   */
  
  #ifndef lint
***************
*** 109,114 ****
--- 116,122 ----
  				continue;
  			}
  			*bp = '\0';
+ 			fflush(pfp);
  			return(1);
  		case '#':
  			if (bp == tbuf)
***************
*** 119,124 ****
--- 127,133 ----
  			if (bp >= tbuf+BUFSIZ) {
  				write(2, "Termcap entry too long\n", 23);
  				*bp = '\0';
+ 				fflush(pfp);
  				return(1);
  			}
  			*bp++ = c;


  reply	other threads:[~1994-05-26 18:16 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-05-25 22:16 Fork bug in Sys5 (or similar) system Guojun Jin[ITG]
1994-05-26  7:52 ` Casper H.S. Dik
1994-05-26 18:16   ` William Armitage [this message]
1994-05-27  8:48     ` Casper H.S. Dik
1994-05-27 12:59       ` Dave Johnson
1994-05-27 13:40         ` Casper H.S. Dik
1994-05-28  2:51           ` Doug Gwyn (ACISD/MCSB) <gwyn>
1994-05-31  1:25     ` Peter da Silva
1994-05-26 18:08 ` Doug Gwyn (ACISD/MCSB) <gwyn>
1994-05-31 19:34   ` Guojun Jin[ITG]
1994-05-31 20:07     ` Casper H.S. Dik
1994-06-01 22:06     ` Peter da Silva
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox