[net.news] readnews questions

neal@denelcor.UUCP (Neal Weidenhofer) (03/07/84)

**************************************************************************

	A couple of questions/gripes about readnews and associated topics:
	
	1.	Why does "U" (unsubscribe) take so long -- sometimes
		> 25 min (on a moderately loaded pdp-11/44)?
		
	2.	I am trying to split my news reading into two parts --
		"work" and "personal".  To do this, I created a couple
		shell scripts that look like:
		
			cp x .newsrc
			readnews
			cp .newsrc x
		
		The problem is that the second cp USUALLY doesn't work --
		after I exit readnews and get my prompt back, x is
		unchanged.  About one time in ten, x is updated properly.
		I can (and do) always redo the cp by hand and it works
		then.  Can anyone help?
		
			Regards,
				Neal Weidenhofer
				Denelcor, Inc.
				<hao|csu-cs|brl-bmd>!denelcor!neal

dmmartindale@watcgl.UUCP (Dave Martindale) (03/08/84)

The U command itself takes almost no time.  But finding the first article
in the next group may take a long time indeed if it is a group you haven't
been reading regularly.  Readnews looks for articles in ascending sequence
one at a time.  If the next group is net.unix-wizards and the first unexpired
article on your machine is number 5000, and you haven't read anything in
this group before, it will look for article 1, then 2, then 3, until it
finally gets to 5000.  You may wait a long time.

A quick-and-dirty fix is to grep unix-wizards in /usr/lib/news/active;
the number is the highest-received article to date; say it's 6000.
Then find the unix-wizards line in your .newsrc and alter it to read

	net.unix-wizards: 1-5900

Ugh.  I believe someone posted some code to deal with this, but we don't
have it installed here either.  A reasonable way to handle this is to have
readnews read the directory, build a bit map of articles which do exist,
invert the map to become a set of articles which don't exist, and then
or this into the bit map obtained from the user's .newsrc so that all
the non-existent articles appear to have been read.  I don't have time
to implement it though.

	Dave Martindale

dave@utcsrgv.UUCP (Dave Sherman) (03/08/84)

~|	From: neal@denelcor.UUCP (Neal Weidenhofer)
~|	1.	Why does "U" (unsubscribe) take so long -- sometimes
~|		> 25 min (on a moderately loaded pdp-11/44)?

It doesn't.  I suspect what's happening is that after the U, you're moving
on to a newsgroup where, for one reason or another (e.g., new user,
faulty .newsrc), readnews is trying to start at a low numbered
article while the next valid article is high-numbered (in a busy
newsgroup). It tries to open every consecutively numbered file until
it finds one which works. Hence the delay. An easy fix (for you) is to
change your .newsrc. There has also been a fix posted to the net.

~|	2.	I am trying to split my news reading into two parts --
~|		"work" and "personal".  To do this, I created a couple
~|		shell scripts that look like:
~|			cp x .newsrc
~|			readnews
~|			cp .newsrc x
~|		The problem is that the second cp USUALLY doesn't work --
~|		after I exit readnews and get my prompt back, x is
~|		unchanged.  About one time in ten, x is updated properly.

There's a much better way. I use it so my wife can read a few
newsgroups. Create a file in your bin (call it "pnews" for
personal news if you like) which contains:

	echo Personal news coming up...
	HOME=/u4/dave/pnews
	NEWSRC=/u4/dave/pnews/.newsrc
	NEWSBOX=/u4/dave/pnews
	NAME="<if you want a different name for postings>"
	export HOME NAME NEWSBOX NEWSRC
	readnews

Then create a subdirectory pnews. Presto - you have a directory
in which you can run separate news. As an added bonus, all saved
articles will go into that directory, so you can isolate your personal
from work-related files. Now run pnews, and unsubscribe to all
work-related groups. In your regular readnews, unsubscribe to
all non-work-related groups.

Hope this helps. Let me know if it works for you.



Dave Sherman
Toronto
-- 
 {allegra,cornell,decvax,ihnp4,linus,utzoo}!utcsrgv!dave

rees@apollo.uucp (Jim Rees) (03/19/84)

Here is the version of getnextart(), in readr.c, for news 2.10 or
later, to read the directory instead of trying to open each article.
This will make readnews faster for new users.  I don't remember now
who wrote this originally.  It had a bug or two having to do with
newsgroups with 0 articles in them, which I have fixed.

/*
 * Find the next article we want to consider, if we're done with
 * the last one, and show the header.
 */
getnextart(minus)
int minus;
{
	int noaccess = 0;
	struct direct dir;
	long nextnum, tnum;
	long atol();

	if (minus)
		goto nextart2;	/* Kludge for "-" command. */

	if (bit == obit)	/* Return if still on same article as last time */
		return 0;

	sigtrap = FALSE;

nextart:
	dgest = 0;
	if (bit < 1 && !rflag)
		bit = 1;

	/* If done with this newsgroup, find the next one. */
	while (ngsize <= 0 || ((long) bit > ngsize) || (rflag && bit < 1)) {
		int i;
		if (i=nextng()) {
			if (actdirect == BACKWARD) {
				fprintf(ofp, "Can't back up.\n");
				actdirect = FORWARD;
				continue;
			} 
			else if (rfq++ || pflag || cflag)
				return 1;
		}
		if (rflag)
			bit = ngsize + 1L;
		else
			bit = -1;
		if (uflag) {
			long now;
			time(&now);
			if (now - timelastsaved > 5*60 /* 5 minutes */) {
				printf("[Saving .newsrc]\n");
				fflush(stdout);
				writeoutrc();
				timelastsaved = now;
			}
		}
	}

nextart2:
#ifdef DEBUG
	fprintf(stderr, "article: %s/%d\n", groupdir, bit);
#endif
	if (rcreadok)
		rcreadok = 2;	/* have seen >= 1 article */
	sprintf(filename, "%s/%d", dirname(groupdir), bit);
	if (rfq && goodone[0])
		strcpy(filename, goodone);
	if (sigtrap) {
		if (sigtrap == SIGHUP)
			return 1;
		if (!rcreadok)
			xxit(0);
		fprintf(ofp, "Abort (n)?  ");
		fflush(ofp);
		gets(bfr);
		if (*bfr == 'y' || *bfr == 'Y')
			xxit(0);
		sigtrap = FALSE;
	}
#ifdef DEBUG
	fprintf(stderr, "filename = '%s'\n", filename);
#endif
	/* Decide if we want to show this article. */
	if (bit <= 0 || access(filename, 4)) {
#ifdef apollo
		/* Make sure we can still get at the spool directory */
		struct stat stbuf;

		if (stat(SPOOL, &stbuf) < 0) {
			fprintf(ofp, "Net failure has made news temporarily unavailable.\n");
			fprintf(ofp, "Do you want to quit (q) or try again (<RET>)? ");
			fflush(ofp);
			gets(bfr);
			if (*bfr == 'q' || *bfr == 'Q') {
				writeoutrc();
				xxit(0);
			} else
				goto nextart2;
		}
#endif
		/* since there can be holes in legal article numbers, */
		/* we wait till we hit 5 consecutive bad articles */
		/* before we haul off and scan the directory */
		if (++noaccess < 5)
			goto badart;
		noaccess = 0;
		fp = fopen(dirname(groupdir), "r");
		if (fp == NULL) {
#ifdef	DEBUG
	fprintf(stderr, "can't open groupdir (%s)\n", dirname(groupdir));
#endif
			goto badart;
		}
		nextnum = rflag ? 0 : ngsize;
		while (fread(&dir, sizeof(dir), 1, fp) == 1) {
			if (!dir.d_ino)
				continue;
			tnum = atol(dir.d_name);
#ifdef	DEBUG
	fprintf(stderr, "art %s (%ld) next %ld\n", dir.d_name, tnum, nextnum);
#endif	DEBUG
			if (tnum <= 0)
				continue;
			if (rflag ? (tnum > nextnum && tnum < bit)
				  : (tnum < nextnum && tnum > bit))
				nextnum = tnum;
		}
		if (rflag ? (nextnum >= bit) : (nextnum <= bit))
			goto badart;
		do {
			clear(bit);
			nextbit();
		} while (rflag ? (nextnum < bit) : (nextnum > bit));
		obit = -1;
		abs = FALSE;
		fclose(fp);
		goto nextart;
	} else
		noaccess = 0;
	if (ignorenews
	|| ((fp = fopen(filename, "r")) == NULL)
	|| (hread(&h, fp, TRUE) == NULL)
	|| (!rfq && !select(&h, abs))) {
	badart:
#ifdef DEBUG
		fprintf(stderr, "Bad article '%s'\n", filename);
#endif
		if (fp != NULL) {
			fclose(fp);
			fp = NULL;
		}
		clear(bit);
		obit = -1;
		nextbit();
		abs = FALSE;
		goto nextart;
	}
	abs = FALSE;
	actdirect = FORWARD;
	news = TRUE;
	hdr();
	if ((cflag && !lflag && !eflag) || pflag)
		tprint(fp, ofp, FALSE);
	if (cflag || lflag || eflag || pflag) {
		itsbeenseen(h.ident);
		sigtrap = FALSE;
		fclose(fp);
		fp = NULL;
	}
	obit = bit;
	return 0;
}

hansen@pegasus.UUCP (Tony L. Hansen) (03/30/84)

When you add in the new getnextart() routine to readr.c, it may or may not
be necessary to also add

	#include "ndir.h"

in front of it. I had to on my site to get it to work right. This may have
been obvious to many people, but I thought I'd mention it just in case it
wasn't.

					Tony Hansen
					pegasus!hansen

neal@denelcor.UUCP (Neal Weidenhofer) (04/06/84)

**************************************************************************

	Many thanks to all of those who offered help and suggestions with
the problems I had with readnews.  Here is what I found out.

1.	Unsubscribe was slow because I was working with a clean .newsrc
file.  Whenever our version of readnews goes to a group that isn't
mentioned in .newsrc, it tries to open (or stat--I heard both and I
haven't had the time to check) each file by number until it finds one that
exists.  As it turned out, the group I was trying to unsubscribe which
took 25 minutes was net.jobs.  Net.jobs is followed by net.jokes with
somewhat more than 5000 expired entries.  Now I know how long it takes
to do 5000 unsuccessful opens (or stats).

	A fix for this problem has been posted (not by me).

2.	The reason the "cp .newsrc x" was failing in the shell script
immediately after readnews is apparently the fact that readnews forks
a new process to update .newsrc and exits so that the terminal is freed
sooner.  In any case, the NEWSRC environment variable did the trick for
me.  Ln would probably have worked also but this is cleaner.

	Thanks again and I apologize for taking so long to answer.
	
			Regards,
				Neal Weidenhofer
				Denelcor, Inc.
				<hao|csu-cs|brl-bmd>!denelcor!neal