From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f7cee,d4695b171a94685b X-Google-Attributes: gidf7cee,public X-Google-Thread: 10c665,d4695b171a94685b X-Google-Attributes: gid10c665,public X-Google-Thread: fee84,d4695b171a94685b X-Google-Attributes: gidfee84,public X-Google-Thread: 11035d,d4695b171a94685b X-Google-Attributes: gid11035d,public X-Google-ArrivalTime: 1994-05-26 14:47:37 PST Newsgroups: comp.unix.osf.osf1,comp.unix.solaris,comp.unix.sys5.r4,comp.bugs.sys5 Path: bga.com!news.sprintlink.net!hookup!swrinde!pipex!warwick!nott-cs!wja From: wja@cs.nott.ac.uk (William Armitage) Subject: Re: Fork bug in Sys5 (or similar) system Message-ID: <1994May26.181612.1484@cs.nott.ac.uk> Organization: Computer Science, Nottingham University References: <2s0io0$248@overload.lbl.gov> <2s1kg2$7or@mail.fwi.uva.nl> Date: Thu, 26 May 94 18:16:12 GMT Xref: bga.com comp.unix.osf.osf1:1718 comp.unix.solaris:8061 comp.unix.sys5.r4:1863 comp.bugs.sys5:40 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;