Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site cepu.UUCP Path: utzoo!watmath!clyde!floyd!harpo!seismo!hao!hplabs!sdcrdcf!sdcsvax!bmcg!cepu!scw From: scw@cepu.UUCP Newsgroups: net.bugs.uucp Subject: Re: News 2.10 /usr/lib/news/recmail crashes Message-ID: <131@cepu.UUCP> Date: Tue, 31-Jan-84 10:08:51 EST Article-I.D.: cepu.131 Posted: Tue Jan 31 10:08:51 1984 Date-Received: Wed, 8-Feb-84 03:05:54 EST References: <3949@edai.UUCP> Organization: VA Wadsworth Med. Center, LA CA Lines: 56 *<- dead bug recmail.c has a section which looks roughly like this: FILE *fd; char *tmpf; char linebuf[1024]; ... tmpf = mktemp("/tmp/rmXXXXXX"); + close(creat(tmpf,0666)); fd = fopen(tmpf, "w"); while (fgets(linebuf, sizeof linebuf, stdin) != NULL) { fputs(linebuf, fd); ... > The immediate cause of the problem is the fputs call: fd is NULL! >I am not all that charmed by recmail's failure to check that the fopen >call worked. I am totally bewildered by the fact that fopen sometimes >returns NULL here. The call to mktemp has in fact come up with a file >name which I can create. I have tried to make this program fail on its >own, and I can't. The only thing I can think of is *maybe* it is called >from some process which has tied up all the channels available and isn't >closing them when it forks? The problem arrises from the case that fopen won't create the file for you (at least on some versions of unix). My copy of readnews had the same problem I fixed it very easily by putting the following line in front of the offending fopen. close(creat(tmpf,0666)); This needs to be done at 2 locations in readnews (in the readr.c file follow_up_command near line 859, and in reply_command near line 670). (See above). This fix is applicable to anyplace that you have an fopen(tmp,...) and are not sure that the file already exsists. if you want to be VERY sure (you think that the file may not be openable) you can use: int cre_ok; ... cre_ok=creat(tmpf,0666); if(cre_ok < 0){ perror(tmpf); ...error processing... } else { close(cre_ok); fd=fopen(tmpf,"w"); ...process tmpf... unlink(tmpf); } -- Stephen C. Woods (VA Wadsworth Med Ctr./UCLA Dept. of Neurology) uucp: ...{ hao, trw-unix, sdcsvax!bmcg}!cepu!scw ARPA: cepu!scw@ucla-locus location: N 34 06'37" W 118 25'43"