Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site mit-eddie.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxl!houxm!ihnp4!mit-eddie!mp From: mp@mit-eddie.UUCP (Mark Plotnick) Newsgroups: net.news Subject: Re: Wanted: news batching with compression Message-ID: <1474@mit-eddie.UUCP> Date: Fri, 23-Mar-84 16:47:36 EST Article-I.D.: mit-eddi.1474 Posted: Fri Mar 23 16:47:36 1984 Date-Received: Sun, 25-Mar-84 08:55:13 EST References: <149@forcm5.UUCP> <952@qubix.UUCP> Organization: MIT, Cambridge, MA Lines: 161 Here's a way to get news compression done. Don't expect it to be elegant, it only took half an hour. There are two new filters, pnews to compact the news and unews to uncompact it. First, the compacting: pnews for Berkeley systems: #!/bin/sh # pnews for berkeley systems PATH=$PATH:/usr/local/lib/news export PATH TMP=/tmp/pn$$ rm -f $TMP >/dev/null 2>&1 compact > $TMP 2>/dev/null echo "#! unews "`filesize $TMP` cat $TMP rm -f $TMP >/dev/null 2>&1 For USG systems, this may work (I don't have access to a USG system that runs netnews, so this is untested) # pnews for USG PATH=$PATH:/usr/local/lib/news export PATH TMP=/tmp/pn$$ rm -f $TMP $TMP.z >/dev/null 2>&1 cat <&0 >$TMP pack -f $TMP >/dev/null 2>&1 echo "#! unews "`filesize $TMP.z` cat $TMP.z rm -f $TMP $TMP.z >/dev/null 2>&1 The command line in your hourly file should look something like: batch /usr/spool/news/batch/whuxle | pnews | uux - -n -r whuxle\!rnews Oh yes, you need filesize.c: #include #include main(argc, argv) char **argv; { struct stat sbuf; if (stat(argv[1], &sbuf) == -1) printf("0\n"); else printf("%ld\n", sbuf.st_size); } OK, now on the receiving end, you need a slightly more flexible unbatch.c: /* * unbatchnews: extract news in batched format and process it one article * at a time. The format looks like * #! rnews 1234 * article containing 1234 characters * #! rnews 4321 * article containing 4321 characters */ # include # include "defs.h" /* to get RNEWS definition */ static char *sccsid = "@(#)unbatch.c 1.3 4/23/83"; char buf[512]; char *command; #define UNEWS "/usr/local/lib/news/unews" main(ac, av) char **av; { register int c; register FILE *pfn; register long size; char *filename; int pid, wpid, exstat; char *mktemp(); long atol(); /* first, close any extraneous files that uucp may have left open */ for(c=3; c<20;c++) close(c); filename = mktemp("/tmp/unbnewsXXXXXX"); while(fgets(buf, sizeof buf, stdin) != NULL) { while (strncmp(buf, "#! rnews ", 9) && strncmp(buf, "#! unews ", 9)) { fprintf(stderr, "out of sync, skipping %s\n", buf); if (fgets(buf, sizeof buf, stdin) == NULL) exit(0); } command = (strncmp(buf, "#! unews ", 9)==0) ? UNEWS : RNEWS; if (buf[strlen(buf)-1]=='\n') buf[strlen(buf)-1]='\0'; /* no use aggravating atol */ size = atol(buf+9); if(size <= 0) break; pfn = fopen(filename, "w"); while(--size >= 0 && (c = getc(stdin)) != EOF) putc(c, pfn); fclose(pfn); /* * If we got a truncated batch, don't process the * last article; it will probably be received again. */ if (size > 0) break; /* * rnews < filename */ while ((pid = fork()) == -1) { fprintf(stderr, "fork failed, waiting...\r\n"); sleep(60); } if (pid == 0) { close(0); open(filename, 0); execlp(command, command, 0); perror(command); exit(1); } while ((wpid = wait(&exstat)) >= 0 && wpid != pid) ; } unlink(filename); } This new unbatch allows both "rnews" and "unews" markers. I thought of just allowing arbitrary shell commands after the "#!", but this would open up too many security holes. unews on ucb looks like: #!/bin/sh # unews for berkeley systems PATH=$PATH:/usr/local/lib/news export PATH uncompact| rnews On USG, one possibility for unews is: # unews for USG PATH=$PATH:/usr/local/lib/news export PATH ZTMP=/tmp/un$$.z rm -f $ZTMP cat <&0 >$ZTMP pcat $ZTMP | rnews rm -f $ZTMP But note that since this isn't a kernelly-executable file, you'd probably have to replace the execlp in unbatch.c with a call to system() or "sh -c". Mark Plotnick P.S. If you exchange news with 2 or more systems, a MUCH better way of reducing your uucp time would be to implement an ihave/sendme protocol.