*** input/newsrun.orig Fri Aug 14 13:02:59 1992 --- input/newsrun Thu Oct 1 10:40:16 1992 *************** *** 23,30 **** --- 23,34 ---- hold= case "$1" in -h) hold=y ; shift ;; + -i) ignore=y ; shift ;; esac + # For the daemonized relaynews + seq=0 + # Go to our base of operations. cd $NEWSARTS/in.coming *************** *** 145,163 **** fi done ! # Do it. -r redirects stdout and stderr into logs. -n makes ! # history entries for refused articles; this is right for ! # NNTP-feed sites and doesn't hurt uucp-feed sites unless ! # they refuse a good fraction of what they get. -u tells relaynews ! # to unlink the files that work. ! if test " $list" != " " then ! relaynews -r -n $stale -u $list ! doexplode ! # Deal with the leftovers, if any; mv 2> is simple and quick. ! mv $list bad 2>/dev/null ! # And just in case that didn't work... ! rm -f $list fi sleep 45 # give somebody else a shot at the lock done --- 149,178 ---- fi done ! # If we're running with the relaynews daemon then all we need ! # to do is to mv the batchfile into the daemon directory and ! # let the relaynews daemon take care of the news ! if test -d daemon -a " $ignore" != " y" then ! seq=`expr $seq + 1` ! mv $text daemon/$$.$seq ! else ! # Do it. -r redirects stdout and stderr into logs. -n ! # makes history entries for refused articles; this is ! # right for NNTP-feed sites and doesn't hurt uucp-feed ! # sites unless they refuse a good fraction of what they ! # get. -u tells relaynews to unlink the files that ! # work. ! if test " $list" != " " ! then ! relaynews -r -n $stale -u $list ! doexplode ! # Deal with the leftovers, if any; ! # mv 2> is simple and quick. ! mv $list bad 2>/dev/null ! # And just in case that didn't work... ! rm -f $list ! fi fi sleep 45 # give somebody else a shot at the lock done *** man/relaynews.8.orig Fri Aug 14 13:03:26 1992 --- man/relaynews.8 Thu Oct 1 10:24:05 1992 *************** *** 13,19 **** .SH SYNOPSIS .B \*b/relay/relaynews [ ! .B \-ginrsu ] [ .B \-a --- 13,19 ---- .SH SYNOPSIS .B \*b/relay/relaynews [ ! .B \-ginrsuD ] [ .B \-a *************** *** 35,40 **** --- 35,43 ---- .B \-x excluded-site ] + [ + .B -S spool-dir + ] .SH DESCRIPTION .I Relaynews installs locally *************** *** 102,107 **** --- 105,118 ---- excludes .I excluded-site from the list of netnews neighbours to receive article(s). + .B -D + makes it run in a daemon mode where it loops forever unbatching + any new articles found in the subdirectoy "/daemon" within the incoming + spool directory. + .B -S + makes + .I spool-dir + the incoming spool directory that the daemon mode uses. .PP .B \-g causes *************** *** 344,349 **** --- 355,374 ---- Written by Geoff Collyer at the University of Toronto as part of the C news project. + Modified by David Alden at The Ohio State University (added the Daemon + mode option, Spool directory option, and new signal handling). + .SH SIGNAL HANDLING + .I relaynews + now handles 2 signals differently: + .TP + .B SIGHUP + This "restarts" the relaynews daemon by rereading in the sys file and + reopening the logfiles. Usefull after updating the sys file or after + creating new log files. + .TP + .B SIGTERM + This "terminates" the relaynews daemon after it finishes the current + run through the in.coming spool directory. .SH BUGS An article with a header that does not fit entirely in a static buffer *** man/rnews.8.orig Fri Aug 14 13:03:28 1992 --- man/rnews.8 Thu Oct 1 10:01:49 1992 *************** *** 27,33 **** ] [ file ... ] .br .B \*b/input/newsrun ! [ grades ] .br .B \*b/input/c7decode .br --- 27,35 ---- ] [ file ... ] .br .B \*b/input/newsrun ! [ grades ] [ ! .B \-i ! ] .br .B \*b/input/c7decode .br *************** *** 124,129 **** --- 126,140 ---- .I newsrun will stop processing all but grade 0 and will exit when there is no grade-0 news left. + .PP + .I Newsrun + automatically places batches into the daemon subdirectory (used by + the daemon version of + \fIrelaynews\fR + ) if it exists. If you wish to override this feature and have it + instead start up a + \fIrelaynews\fR + process then you can specify the -i option. .PP Each batch is run through \fIc7decode\fR (if necessary), *** misc/newsdaily.orig Fri Aug 14 13:03:35 1992 --- misc/newsdaily Thu Oct 1 10:01:50 1992 *************** *** 4,10 **** # =()<. ${NEWSCONFIG-@@}>()= . ${NEWSCONFIG-/usr/cnews/ctl/bin/config} ! PATH=$NEWSCTL/bin:$NEWSBIN/maint:$NEWSBIN:$NEWSPATH ; export PATH umask $NEWSUMASK gripes="/tmp/ngrip$$" --- 4,10 ---- # =()<. ${NEWSCONFIG-@@}>()= . ${NEWSCONFIG-/usr/cnews/ctl/bin/config} ! PATH=$NEWSCTL/bin:$NEWSBIN/maint:$NEWSBIN/local:$NEWSBIN:$NEWSPATH; export PATH umask $NEWSUMASK gripes="/tmp/ngrip$$" *************** *** 41,46 **** --- 41,58 ---- mv batchlog batchlog.o && >batchlog fi + # reset relaynews to use new logfiles + if test -f relaynews.pid + then + kill -HUP `cat relaynews.pid` + else + ( + echo " " + echo "Relaynews may not have been running\! Investigate." + echo " " + ) >>$grips + fi + # report any errors sleep 500 # hope that errlog.o is quiescent after this if test -s errlog.o *************** *** 54,59 **** --- 66,77 ---- ) >>$gripes fi + # + # reset nntplink processes to use the new logfile + ( + links -s HUP + ) >>$gripes + # look for input anomalies cd $NEWSARTS/in.coming find . -type f -mtime +1 -print | sed 's;^\./;;' | egrep -v '^bad/' >$tmp *************** *** 79,85 **** # look for output anomalies cd $NEWSARTS/out.going ! find . -type f -name 'togo*' -size +0 -mtime +1 -print >$tmp if test -s $tmp then ( --- 97,103 ---- # look for output anomalies cd $NEWSARTS/out.going ! find . -type f -name 'togo*' -size +0 -mtime +1 -print | grep -v fail >$tmp if test -s $tmp then ( *************** *** 169,175 **** # send it if test -s $gripes then ! mail $gurus <$gripes fi # and do other daily chores --- 187,193 ---- # send it if test -s $gripes then ! Mail -s "newsdaily output" $gurus <$gripes fi # and do other daily chores *** relay/history.c.orig Wed Mar 18 06:16:48 1992 --- relay/history.c Thu Oct 1 10:01:41 1992 *************** *** 194,201 **** if (startlog) { timestamp(stdout, &now); ! if (printf(" %s + %s", sendersite(nullify(art->h.h_path)), ! msgid) == EOF) fulldisk(art, "stdout"); } else now = time(&now); --- 194,201 ---- if (startlog) { timestamp(stdout, &now); ! if (printf(" %s + %s (%s)", sendersite(nullify(art->h.h_path)), ! msgid, art->a_tmpf) == EOF) fulldisk(art, "stdout"); } else now = time(&now); *** relay/history.h.orig Tue Mar 6 00:44:59 1990 --- relay/history.h Thu Oct 1 10:01:42 1992 *************** *** 6,8 **** --- 6,16 ---- #define STARTLOG YES #define NOLOG NO + /* imports from history.c */ + extern char *findfiles(), *gethistory(); + extern boolean alreadyseen(); + extern statust fakehist(), closehist(); + extern void history(), histupdfiles(); + + #define STARTLOG YES + #define NOLOG NO *** relay/makefile.orig Fri Aug 14 13:06:03 1992 --- relay/makefile Thu Oct 1 10:05:50 1992 *************** *** 12,19 **** I=../include BIN=/bin NPROC=2 # -DVOID=int for libc.h & old lint libraries ! DEFINES= -I$(I) -I. -DVOID=int -DFLUSHEVERY=6 #CC=agccped #CC=CC +V COPTS= -O # -pg -g -O --- 12,24 ---- I=../include BIN=/bin NPROC=2 + + INDIR=$(NEWSARTS)/in.coming + PID_FILE=$(NEWSCTL)/relaynews.pid + NEWDEFS= -DINDIR=\"$(INDIR)\" -DPID_FILE=\"$(PID_FILE)\" + # -DVOID=int for libc.h & old lint libraries ! DEFINES= -I$(I) -I. -DVOID=int -DFLUSHEVERY=6 $(NEWDEFS) #CC=agccped #CC=CC +V COPTS= -O # -pg -g -O *** relay/procart.c.orig Fri Mar 27 21:41:51 1992 --- relay/procart.c Thu Oct 1 10:01:44 1992 *************** *** 28,35 **** * emit local time incorrectly labelled as GMT. They really should fix * their software, but in the mean time, a day's slop will prevent their * articles from being dropped. */ ! #define CLOCKSLOP DAY /* * COPYSIZE is the length of a bulk-copying buffer: the bigger the better, --- 28,39 ---- * emit local time incorrectly labelled as GMT. They really should fix * their software, but in the mean time, a day's slop will prevent their * articles from being dropped. + * + * This has been changed to 2 days to deal with the fact that relaynews never + * exits when in the daemon mode - and it only resets its concept of "now" + * after it has been running for a day. */ ! #define CLOCKSLOP (2*DAY) /* * COPYSIZE is the length of a bulk-copying buffer: the bigger the better, *************** *** 357,364 **** --- 361,370 ---- register char *ngs = hdrs->h_ngs; register char *errstr; register time_t date; + register time_t far_fix; static time_t now, datestale; extern time_t getindate(); + extern int daemonize; if (art->a_status&ST_REFUSED) return; /* already rejected */ *************** *** 387,392 **** --- 393,414 ---- prefuse(art); (void) printf("unparsable Date: `%s'\n", hdrs->h_date); } else if (date > now + CLOCKSLOP) { + if (daemonize == YES) { + /* + * If we've gone for a day, now will be old enough to + * make the above comparison die; so let's see if + * we're 1 day since the last time now was set + * (has been DAY ticks or more); if it was, reset now + */ + if (((far_fix = time((time_t *)NULL)) - now) >= DAY) { + now = far_fix; + datestale = now - staledays*DAY; + /* ok, now we have to go and re-test this one + with the new now */ + reject(art); + return; + } + } prefuse(art); (void) printf("Date: too far in the future: `%s'\n", hdrs->h_date); *** relay/relaynews.c.orig Tue Mar 17 09:42:42 1992 --- relay/relaynews.c Thu Oct 1 10:20:19 1992 *************** *** 30,35 **** --- 30,64 ---- * ("I") instead). */ + /* + * IMPORTANT NOTE: + * This program (relaynews) has been modified by David J Alden, + * alden@shape.mps.ohio-state.edu. Please send mail to me if + * you have any problems with relaynews - I'll try to determine + * if it's due to my patches or not and fix the problem if it's + * due to my patches. The new changes are: + * + * New daemon mode: + * relaynews detaches itself from the controlling terminal and + * watches for any new news. There are 2 new signals that it + * uses for daemon mode: + * + * SIGHUP - This "restarts relaynews" by rereading in the + * sys file and reopening the logfiles. Useful + * after updating the sys file or after creating + * new log files. + * SIGTERM - This "terminates relaynews" after it finishes + * the current run through the spool directory. + * + * New flag for working with nntplink: + * relaynews now accepts a new flag in the sys file, "l". This + * works just like "F" - except it doesn't actually create a + * batchfile - it only logs the sysname to the logfile. + * + * Please read the appropriate man page (relaynews(8)) for explanations + * of the new options and flags. + */ + #include #include #include *************** *** 50,56 **** --- 79,124 ---- #include "history.h" #include "transmit.h" + + /* + * Some of the following variables may need to be changed for your system. + */ + + /* + * Is this a USG (SYSV) style system ? Used for signals and daemon mode + */ + #undef USG + + /* + * If your system has instead of then define + * the following. + */ + #undef OLD_DIRECTORY + /* + /* + * How often should relaynews check for a batch file? + */ + #define SLEEP_INTERVAL 1 + + /* + * End of configuration section...Nothing below should need to be changed. + */ + + #ifdef OLD_DIRECTORY + #include + #else + #include + #endif + + #include + #include + + void restart_relaynews(); + void abort_relaynews(); + void resetsys(); + + /* * setuid-root program to set ids to news/news & re-exec rnews with * NEWSPERMS in the environment to break loops. */ *************** *** 74,79 **** --- 142,155 ---- static boolean userealids = NO; static boolean uunlink = NO; static char incsfx[] = "in.coming"; /* need this for -u, alas */ + static int redirlogs = 0; /* redirect n std output streams to logs */ + struct stat dir_timestamp, old_dir_timestamp; + char spooldir[MAXPATH] = INDIR; + int daemonize = NO, use_spooldir = NO; + int reset_relaynews = NO; + int exit_relaynews = NO; + char goodname[MAXPATH]; + char badname[MAXPATH]; /* imports */ extern int optind; /* set by getopt */ *************** *** 98,104 **** char *argv[]; { statust status = ST_OKAY; - int redirlogs = 0; /* redirect n std output streams to logs */ char *origdir = NULL; /* current directory at start */ if (argc > 0) --- 174,179 ---- *************** *** 112,125 **** /* ignore signals (for locking). relaynews runs quickly, so don't worry. */ (void) signal(SIGINT, SIG_IGN); (void) signal(SIGQUIT, SIG_IGN); ! (void) signal(SIGHUP, SIG_IGN); ! (void) signal(SIGTERM, SIG_IGN); (void) signal(SIGPIPE, SIG_IGN); /* we check write returns */ procopts(argc, argv, &origdir, &redirlogs, &okrefusal); (void) morefds(); /* ask Unix for more descriptors */ - newslock(); /* done here due to dbm internal cacheing */ if (redirlogs > 0) { redirectlogs(redirlogs); /* redirect std output streams to logs */ #ifdef MANYERRORS --- 187,199 ---- /* ignore signals (for locking). relaynews runs quickly, so don't worry. */ (void) signal(SIGINT, SIG_IGN); (void) signal(SIGQUIT, SIG_IGN); ! (void) signal(SIGHUP, restart_relaynews); ! (void) signal(SIGTERM, abort_relaynews); (void) signal(SIGPIPE, SIG_IGN); /* we check write returns */ procopts(argc, argv, &origdir, &redirlogs, &okrefusal); (void) morefds(); /* ask Unix for more descriptors */ if (redirlogs > 0) { redirectlogs(redirlogs); /* redirect std output streams to logs */ #ifdef MANYERRORS *************** *** 130,142 **** #endif } getwdandcd(argc, argv, &origdir); - status |= procargs(argc, argv, &origdir); ! status |= synccaches(); /* being cautious: write & close caches */ ! status |= closehist(); ! (void) fflush(stdout); /* log file */ ! (void) fflush(stderr); /* errlog file */ #ifdef notdef #ifdef CSRIMALLOC --- 204,273 ---- #endif } + if (daemonize == YES) { + + #ifdef TIOCNOTTY + int fd; + #endif + int p; + #ifdef PID_FILE + FILE * pidf; + #endif + + if ((p = fork()) < 0) + { + (void) fprintf(stderr, "%s: fork failed\n", progname); + exit(1); + } + if (p != 0) + exit(0); /* parent exit, child continues */ + + #ifdef PID_FILE + if ((pidf=fopen(PID_FILE,"w")) != NULL) { + fprintf(pidf, "%d\n", getpid()); + fclose(pidf); + } + #endif + + #ifdef USG + (void) setpgrp(); + #ifdef TIOCNOTTY + fd = open("/dev/tty", 2); /* disconnect from the tty */ + if (fd >= 0) { + (void) ioctl(fd, (int)TIOCNOTTY, (char *)0); + (void) close(fd); + } + #endif /* TIOCNOTTY */ + #else /* USG */ + (void) setpgrp(0, 0); + #endif /* USG */ + + } + getwdandcd(argc, argv, &origdir); ! do { ! newslock(); ! (void) fseek(stdout,0L,2); /* make sure wee're still at EOF */ ! (void) fseek(stderr,0L,2); /* ditto */ ! ! status |= procargs(argc, argv, &origdir); ! ! status |= synccaches(); /* being cautious: write & close caches */ ! status |= closehist(); ! (void) fflush(stdout); /* log file */ ! (void) fflush(stderr); /* errlog file */ ! ! newsunlock(); ! ! old_dir_timestamp = dir_timestamp; ! ! while ((dir_timestamp.st_ctime == old_dir_timestamp.st_ctime) && ! daemonize && !exit_relaynews) { ! sleep(SLEEP_INTERVAL); ! (void) stat(spooldir, &dir_timestamp); ! } ! } while (daemonize && !exit_relaynews); #ifdef notdef #ifdef CSRIMALLOC *************** *** 149,154 **** --- 280,312 ---- } /* + * Sets a flag to tell relaynews to reload the sys file and if redirlogs + * is true then to go ahead and re-redirect the output to the logs. + */ + void + restart_relaynews() + { + reset_relaynews = YES; + #ifdef USG + (void) signal(SIGHUP, restart_relaynews); + #endif + } + + + /* + * Sets a flag to tell relaynews to exit after processing the next + * article. + */ + void + abort_relaynews() + { + exit_relaynews = YES; + #ifdef USG + (void) signal(SIGTERM, abort_relaynews); + #endif + } + + /* * reset various environmental things for safety: umask, alarm, * environment variables (PATH, IFS), standard file descriptors, * user & group ids. *************** *** 230,237 **** int c, errflg = 0; char *incdir; ! while ((c = getopt(argc, argv, "a:b:d:gino:rsx:u")) != EOF) switch (c) { case 'a': dupsokay = YES; dupsite = optarg; --- 388,405 ---- int c, errflg = 0; char *incdir; ! while ((c = getopt(argc, argv, "DS:a:b:d:gino:rsx:u")) != EOF) switch (c) { + case 'D': /* daemonize it, note that this */ + *redirlogsp = 2; /* implies -r */ + daemonize = YES; + use_spooldir = YES; + strcat(spooldir, "/daemon"); + break; + case 'S': /* Spool directory */ + use_spooldir = YES; + strcpy(spooldir, optarg); + break; case 'a': dupsokay = YES; dupsite = optarg; *************** *** 290,296 **** } if (errflg) { (void) fprintf(stderr, ! "usage: %s [-ginrsu][-d fhlmt][-x site][-o days][-b xrefsite][-a dupsite]\n", progname); exit(1); } --- 458,464 ---- } if (errflg) { (void) fprintf(stderr, ! "usage: %s [-Dginrsu][-d fhlmt][-x site][-o days][-b xrefsite][-a dupsite][-S spooldir]\n", progname); exit(1); } *************** *** 422,436 **** char **argv; char **origdirp; { ! register statust status = ST_OKAY; ! if (optind == argc) ! status |= process(stdin, "(stdin)"); ! else ! for (; optind < argc; optind++) ! status |= relnmprocess(argv[optind], *origdirp); ! nnfree(origdirp); ! return status; } statust --- 590,662 ---- char **argv; char **origdirp; { ! register statust status = ST_OKAY; ! DIR *my_dirp; ! #ifdef OLD_DIRECTORY ! struct direct *dp; ! #else ! struct dirent *dp; ! #endif ! int keep_looping = YES; ! register int isgoodname, i; ! if (use_spooldir) { /* loop through spool dir processing all news */ ! ! my_dirp = opendir(spooldir); ! ! if (my_dirp == (DIR *)NULL) { ! fprintf(stderr, "%s: Spool directory (%s) not found, exiting.\n", ! progname, spooldir); ! exit_relaynews = YES; ! } else ! (void) stat(spooldir, &dir_timestamp); ! ! while (keep_looping && !exit_relaynews) { ! ! keep_looping = NO; ! ! for (dp = readdir(my_dirp); dp != NULL; dp = readdir(my_dirp)) { ! ! if (reset_relaynews) { ! ! resetsys(); ! ! if (redirlogs > 0) ! redirectlogs(redirlogs); /* close & reopen log files */ ! ! reset_relaynews = NO; ! } ! ! if (isdigit(dp->d_name[0])) { ! status = relnmprocess(dp->d_name, spooldir); ! sprintf(goodname, "%s/%s", spooldir, dp->d_name); ! if (status) { ! sprintf(badname, "%s/bad/%s", INDIR, dp->d_name); ! rename(goodname, badname); ! status = 0; ! } else ! unlink(goodname); ! ! keep_looping = YES; ! } ! ! if (exit_relaynews) ! break; ! } ! ! closedir(my_dirp); ! ! } ! } else { /* Act like "original relaynews" */ ! ! if (optind == argc) ! status |= process(stdin, "(stdin)"); ! else ! for (; optind < argc; optind++) ! status |= relnmprocess(argv[optind], *origdirp); ! nnfree(origdirp); ! return status; ! } } statust *** relay/sys.c.orig Mon Dec 30 03:21:58 1991 --- relay/sys.c Thu Oct 1 10:01:47 1992 *************** *** 353,355 **** --- 353,383 ---- { rewsys(fp); } + + + void + resetsys() + { + struct system *nextsys; + + if (firstsys != NULL) { + + for (currsys = firstsys; currsys != NULL; currsys = nextsys) { + nextsys = currsys->sy_next; + /* + * No need to free sy_excl and sy_distr members as they cam from reparse + * and will not be null but will be freed with sy_name and sy_ngs + */ + nnfree(&currsys->sy_name); + nnfree(&currsys->sy_ngs); + nnfree(&currsys->sy_cmd); + nnafree(&currsys); + } + remmysys((struct system *)NULL); + firstsys = NULL; + if (fp != NULL) { + nfclose(fp); + fp = NULL; + } + } + }