Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 beta 3/9/83; site nsc.UUCP Path: utzoo!watmath!clyde!burl!ulysses!harpo!seismo!hao!hplabs!nsc!chuqui From: chuqui@nsc.UUCP (Chuq Von Rospach) Newsgroups: net.news.b,net.sources Subject: news batching with file size limits Message-ID: <821@nsc.UUCP> Date: Sat, 7-Apr-84 15:07:41 EST Article-I.D.: nsc.821 Posted: Sat Apr 7 15:07:41 1984 Date-Received: Mon, 9-Apr-84 05:38:42 EST Organization: National Semiconductor, Sunnyvale Lines: 99 In putting up the batching software on my system, I decided to go ahead and hack in something I've been meaning to do for awhile. This is a version of batchnews.c that knows enough to start a new file if the old one gets too big. there are a couple of reasons for this. If your uucp lines are a touch flakey, passing a 200K file is a lot less likely to happen than passing 4 50K files. If you do die, you don't lose nearly as much. Also, if you are tight on spool space you don't need to worry about keeping room for 200K of batched news AND 200K of messages, because the batched news will delete itself as it goes along. Here it is, enjoy! (install! use!) Note that the filesize maximum of 50,000 characters is rather arbitrary, so feel free to use whatever you want. chuq --- batchnews.c ---- # ifndef NOSCCS static char *sccsid = "@(#)batchnews.c 1.2 4/7/84"; static char *cpyrid = "@(#)Copyright (C) 1984 by National Semiconductor Corp."; # endif /***************************************************************************** * batchnews: take many news articles and batch them into one big * * group * *****************************************************************************/ # include # include # include # define INTERVAL 3600 /* one spool file per hour */ # define FILEMAX 50000 /* maximum number of bytes in a file */ # define BATCHDIR "/usr/spool/bnews" /* where the batching is done */ /* write out a line with the file length, then the file itself */ main(ac, av) char **av; { long now; char fnbuf[100], lckfile[100], buf[BUFSIZ]; char tmpfile[100]; register FILE *fi, *fo; int i; struct stat statbuf; sprintf(tmpfile,"%s/.newsXXXXXX",BATCHDIR); mktemp(tmpfile); if((fi = fopen(tmpfile, "w+")) == NULL) exit(1); while((i = fread(buf, 1, BUFSIZ, stdin)) != NULL) fwrite(buf, 1, i, fi); fflush(fi); rewind(fi); stat(tmpfile, &statbuf); time(&now); sprintf(fnbuf, "%s/%s.%ld",BATCHDIR,ac>1? av[1]: "news",now/INTERVAL); checksize(fnbuf); sprintf(lckfile, "%s/%s.LCK",BATCHDIR,ac>1? av[1]: "news"); while(close(creat(lckfile, 0)) < 0) sleep(2); fo = fopen(fnbuf, "a"); fprintf(fo, "%ld\n", statbuf.st_size); while((i = fread(buf, 1, BUFSIZ, fi)) != NULL) fwrite(buf, 1, i, fo); fclose(fi); fclose(fo); unlink(tmpfile); unlink(lckfile); } checksize(fnbuf) char *fnbuf; { register int i; char s[100]; struct stat sbuf; if ((stat(fnbuf,&sbuf) == -1) || (sbuf.st_size < FILEMAX)) return; strcpy(s,fnbuf); for (i = 0;; i++) { sprintf(fnbuf,"%s.%d",s,i); if ((stat(fnbuf,&sbuf) == -1) || (sbuf.st_size < FILEMAX)) { fprintf(stderr,"returning, fnbuf = %s\n",fnbuf); return; } } /* NOTREACHED */ } -- From under the bar at Callahan's: Chuq Von Rospach {amd70,fortune,hplabs,menlo70}!nsc!chuqui (408) 733-2600 x242 A toast! To absent friends... {clink}