INN commit: trunk (3 files)

INN Commit rra at isc.org
Sun May 24 09:12:10 UTC 2020


    Date: Sunday, May 24, 2020 @ 02:12:09
  Author: iulius
Revision: 10375

rnews:  add -b flag to back up badly formatted articles

This new -b flag to rnews permits saving rejected articles in the "bad"
sub-directory of <pathincoming>.  Otherwise, rnews just logs and discards
any articles that are rejected or cannot be parsed for some reason.

This feature was previously available only via the compile-time option
DO_RNEWS_SAVE_BAD.

Thanks to Herbert Xu for the proposal of making it easily available.

Modified:
  trunk/doc/pod/news.pod
  trunk/doc/pod/rnews.pod
  trunk/frontends/rnews.c

-------------------+
 doc/pod/news.pod  |    7 +++++++
 doc/pod/rnews.pod |   30 +++++++++++++++++++-----------
 frontends/rnews.c |   46 +++++++++++++++++++++++++---------------------
 3 files changed, 51 insertions(+), 32 deletions(-)

Modified: doc/pod/news.pod
===================================================================
--- doc/pod/news.pod	2020-05-24 08:12:23 UTC (rev 10374)
+++ doc/pod/news.pod	2020-05-24 09:12:09 UTC (rev 10375)
@@ -24,6 +24,13 @@
 if you had not already set the I<html_css_url> parameter in previous
 INN versions.  Thanks to Richard Kettlewell for the patch.
 
+=item *
+
+Added new B<-b> flag to B<rnews> to save rejected articles in the F<bad>
+sub-directory of I<pathincoming> (as set in F<inn.conf>).  Otherwise,
+B<rnews> just logs and discards any articles that are rejected or cannot
+be parsed for some reason.
+
 =back
 
 =head1 Changes in 2.6.3

Modified: doc/pod/rnews.pod
===================================================================
--- doc/pod/rnews.pod	2020-05-24 08:12:23 UTC (rev 10374)
+++ doc/pod/rnews.pod	2020-05-24 09:12:09 UTC (rev 10375)
@@ -4,7 +4,7 @@
 
 =head1 SYNOPSIS
 
-B<rnews> [B<-NUv>] [B<-h> I<host>] [B<-P> I<port>] [B<-rS> I<server>]
+B<rnews> [B<-bNUv>] [B<-h> I<host>] [B<-P> I<port>] [B<-rS> I<server>]
 [I<file>]
 
 =head1 DESCRIPTION
@@ -15,10 +15,11 @@
 generally use inews(1) instead.  It is also used to process spooled
 messages created by, for example, B<nnrpd> while B<innd> is not available.
 
-The message is read from I<file> if given, or standard input if no file is
-given.  Articles are sent to the server given in the B<-r> or B<-S>
-command line options if given, otherwise to the server set via
-I<nnrpdposthost> in F<inn.conf>, otherwise to the local server.
+The message is read from I<file> if given, spooled files (with the B<-U>
+flag) or standard input if no file is given.  Articles are sent to
+the server given in the B<-r> or B<-S> command line options if given,
+otherwise to the server set via I<nnrpdposthost> in F<inn.conf>,
+otherwise to the local server.
 
 When sent over UUCP, Usenet articles are typically collected in a single
 batch to reduce the UUCP overhead.  Batches can also be compressed to
@@ -71,16 +72,18 @@
 
 =back
 
-By default, B<rnews> will log and discard any articles that are rejected
-by the server or cannot be parsed by B<rnews> for some reason (such as a
-missing header).  This default can be changed when compiling INN by
-setting DO_RNEWS_SAVE_BAD in F<include/inn/options.h>.  There is no way to
-change it at runtime, unfortunately.
-
 =head1 OPTIONS
 
 =over 4
 
+=item B<-b>
+
+By default, B<rnews> will log and discard any articles that are rejected
+by the server or cannot be parsed by B<rnews> for some reason (such
+as a missing header).  If B<-b> is given, rejected articles will also
+be backed up in the F<bad> sub-directory of I<pathincoming> (as set
+in F<inn.conf>).
+
 =item B<-h> I<host>
 
 If B<-h> is given, B<rnews> will log the message ID and I<host> via syslog
@@ -121,6 +124,11 @@
 again.  It's a good idea to run this periodically out of cron to pick up
 any articles spooled due to temporary server unavailability.
 
+=item B<-v>
+
+Enable verbose mode, with more traces, notably logging the reason why
+articles are rejected by the server.
+
 =back
 
 =head1 BUGS

Modified: frontends/rnews.c
===================================================================
--- frontends/rnews.c	2020-05-24 08:12:23 UTC (rev 10374)
+++ frontends/rnews.c	2020-05-24 09:12:09 UTC (rev 10375)
@@ -34,7 +34,8 @@
 } HEADER;
 
 
-static bool	Verbose;
+static bool     Verbose = false;
+static bool     backupBad = false;
 static const char	*InputFile = "stdin";
 static char	*UUCPHost;
 static char	*PathBadNews = NULL;
@@ -164,11 +165,9 @@
 Reject(const char *article, size_t length UNUSED, const char *reason,
        const char *arg)
 {
-#if	defined(DO_RNEWS_SAVE_BAD)
     char *filename;
     FILE *F;
     int fd;
-#endif	/* defined(DO_RNEWS_SAVE_BAD) */
 
 #if __GNUC__ > 4
 # pragma GCC diagnostic ignored "-Wformat-nonliteral"
@@ -189,24 +188,26 @@
 	fprintf(stderr, " [%.40s...]\n", article);
     }
 
-#if	defined(DO_RNEWS_SAVE_BAD)
-    filename = concat(PathBadNews, "/XXXXXX", (char *) 0);
-    fd = mkstemp(filename);
-    if (fd < 0) {
-        warn("cannot create temporary file");
-        return;
+    if (backupBad) {
+        filename = concat(PathBadNews, "/XXXXXX", (char *) 0);
+        fd = mkstemp(filename);
+        if (fd < 0) {
+            warn("cannot create temporary file");
+            free(filename);
+            return;
+        }
+        F = fdopen(fd, "w");
+        if (F == NULL) {
+            warn("cannot fdopen %s", filename);
+            free(filename);
+            return;
+        }
+        if (fwrite(article, 1, length, F) != length)
+            warn("cannot fwrite to %s", filename);
+        if (fclose(F) == EOF)
+            warn("cannot close %s", filename);
+        free(filename);
     }
-    F = fdopen(fd, "w");
-    if (F == NULL) {
-        warn("cannot fdopen %s", filename);
-	return;
-    }
-    if (fwrite(article, 1, length, F) != length)
-        warn("cannot fwrite to %s", filename);
-    if (fclose(F) == EOF)
-        warn("cannot close %s", filename);
-    free(filename);
-#endif	/* defined(DO_RNEWS_SAVE_BAD) */
 }
 
 
@@ -890,11 +891,14 @@
     /* Parse JCL. */
     fd = STDIN_FILENO;
     mode = '\0';
-    while ((i = getopt(ac, av, "h:P:NUvr:S:")) != EOF)
+    while ((i = getopt(ac, av, "bh:NP:r:S:Uv")) != EOF)
 	switch (i) {
 	default:
 	    die("usage error");
 	    /* NOTRTEACHED */
+        case 'b':
+            backupBad = true;
+            break;
 	case 'h':
 	    UUCPHost = *optarg ? optarg : NULL;
 	    break;



More information about the inn-committers mailing list