INN commit: trunk (4 files)

INN Commit rra at isc.org
Fri Jul 26 20:28:05 UTC 2013


    Date: Friday, July 26, 2013 @ 13:28:04
  Author: iulius
Revision: 9511

pullnews:  looks for the config file in the right home directory

After commits [9304] and [9330], INN 2.5.3 broke the legacy behaviour of
pullnews looking for its configuration file in the running user's home
directory.  Adding INN::Config changed the $HOME environment variable
to the news user's home directory (in fact the pathnews parameter set
in inn.conf).
Besides, pullnews was no longer useable outside INN.

Fixed these issues by:
- making INN::Config and INN::Utils::Shlock optional.  If these Perl
modules are not present, pullnews falls back to its legacy handle of locks
(that is unfortunately broken in Solaris);
- setting the home directory to the one of the running user (or to pathdb
if pullnews is run by the news user).

Thanks to Tony Evans for the bug report.

Modified:
  trunk/CONTRIBUTORS
  trunk/doc/pod/news.pod
  trunk/doc/pod/pullnews.pod
  trunk/frontends/pullnews.in

-----------------------+
 CONTRIBUTORS          |    2 -
 doc/pod/news.pod      |   27 ++++++++++++-----
 doc/pod/pullnews.pod  |   26 +++++++++++-----
 frontends/pullnews.in |   74 +++++++++++++++++++++++++++++++++++++++---------
 4 files changed, 99 insertions(+), 30 deletions(-)

Modified: CONTRIBUTORS
===================================================================
--- CONTRIBUTORS	2013-07-22 03:26:55 UTC (rev 9510)
+++ CONTRIBUTORS	2013-07-26 20:28:04 UTC (rev 9511)
@@ -275,4 +275,4 @@
 Lars Magne Ingebrigtsen, Sam Varshavchik, Matthew Vernon, Ian Jackson,
 Edmund H. Ramm, Raphael Barrois, Bo Lindbergh, Matthias Meyser,
 Dennis Preiser, Paolo Amoroso, Dennis Davis, River Tarnell, Jochen Schmitt,
-Tim Fardell, Remco Rijnders, David Binderman
+Tim Fardell, Remco Rijnders, David Binderman, Tony Evans

Modified: doc/pod/news.pod
===================================================================
--- doc/pod/news.pod	2013-07-22 03:26:55 UTC (rev 9510)
+++ doc/pod/news.pod	2013-07-26 20:28:04 UTC (rev 9511)
@@ -8,11 +8,13 @@
 =item *
 
 The name and location of the B<pullnews> configuration file have changed.
-It is now F<pullnews.marks> in I<pathdb> (instead of F<.pullnews>
-in I<pathnews>).  If you use B<pullnews>, you need to manually move the
-configuration file; otherwise, it will no longer work.  Note that the B<-c>
-flag passed to B<pullnews> allows to specify another configuration file,
-if need be.
+It is now F<pullnews.marks>, located in I<pathdb> when B<pullnews> is
+run as the news user, or otherwise in the running user's home directory.
+This file was previously stored in F<.pullnews> in the running user's
+home directory (even for the news user).  If you use B<pullnews>, you
+need to manually move and rename the configuration file; otherwise,
+it will no longer work.  Note that the B<-c> flag passed to B<pullnews>
+allows to specify another configuration file, if need be.
 
 =item *
 
@@ -107,8 +109,11 @@
 
 =item *
 
-The name and location of the B<pullnews> configuration file is now
-F<pullnews.marks> in I<pathdb> (instead of F<.pullnews> in I<pathnews>).
+The name of the B<pullnews> configuration file is now F<pullnews.marks>
+located in I<pathdb> when B<pullnews> is run as the news user, or
+otherwise in the running user's home directory.  It was previously
+stored in F<.pullnews> in the running user's home directory (even for
+the news user).
 
 =item *
 
@@ -163,6 +168,14 @@
 
 =item *
 
+Fixed a regression that occurred in S<INN 2.5.3> regarding the path used
+by default by B<pullnews> for its configuration file.  Instead of looking
+in the running user's home directory, it was looking in the I<pathnews>
+directory parametered in F<inn.conf>.  Thanks to Tony Evans for the
+bug report.
+
+=item *
+
 Fixed a Perl warning in B<inncheck>; using C<defined(@array)> has been
 deprecated since S<Perl 5.16>.
 

Modified: doc/pod/pullnews.pod
===================================================================
--- doc/pod/pullnews.pod	2013-07-22 03:26:55 UTC (rev 9510)
+++ doc/pod/pullnews.pod	2013-07-26 20:28:04 UTC (rev 9511)
@@ -20,9 +20,13 @@
 
 =head1 DESCRIPTION
 
-B<pullnews> reads a config file named F<pullnews.marks> in I<pathdb> as set
-in F<inn.conf>, and connects to the upstream servers given there as a reader
-client.  By default, it connects to all servers listed in the configuration
+B<pullnews> reads a config file named F<pullnews.marks>, and connects
+to the upstream servers given there as a reader client.  This file is
+looked for in I<pathdb> when B<pullnews> is run as the user set in
+I<runasuser> in F<inn.conf> (which is by default the C<news> user);
+otherwise, this file is looked for in the running user's home directory.
+
+By default, B<pullnews> connects to all servers listed in the configuration
 file, but you can limit B<pullnews> to specific servers by listing them
 on the command line:  a whitespace-separated list of server names can be
 specified, like I<from-server> for one of them.  For each server it connects
@@ -46,10 +50,12 @@
 
 =item B<-c> I<config>
 
-Normally, the config file is stored in F<pullnews.marks> in I<pathdb>.
-If B<-c> is given, I<config> will be used as the config file instead.
-This is useful if you're running B<pullnews> as a system user on an automated
-basis out of cron or as an individual user, rather than the news user.
+Normally, the config file is stored in F<pullnews.marks> in I<pathdb>
+when B<pullnews> is run as the news user, or otherwise in the running
+user's home directory.  If B<-c> is given, I<config> will be used as
+the config file instead.  This is useful if you're running B<pullnews>
+as a system user on an automated basis out of cron or as an individual
+user, rather than the news user.
 
 See L<CONFIG FILE> below for the format of this file.
 
@@ -267,9 +273,11 @@
 The Perl script itself used to pull news from upstream servers and feed
 it to another news server.
 
-=item I<pathdb>/pullnews.marks
+=item I<pathdb>/pullnews.marks or ~/pullnews.marks
 
-The default config file.
+The default config file.  It is stored in F<pullnews.marks> in I<pathdb>
+when B<pullnews> is run as the news user, or otherwise in the running
+user's home directory.
 
 =back
 

Modified: frontends/pullnews.in
===================================================================
--- frontends/pullnews.in	2013-07-22 03:26:55 UTC (rev 9510)
+++ frontends/pullnews.in	2013-07-26 20:28:04 UTC (rev 9511)
@@ -1,10 +1,11 @@
 #! /usr/bin/perl -w
-# fixscript will replace this line with code to load INN::Config
-#
+# use lib '@LIBPERLDIR@'; use INN::Config;
+# If running inside INN, uncomment the above and point to INN::Config.
+# 
 # Author:       James Brister <brister at vix.com> -- berkeley-unix --
 # Start Date:   Sat, 10 Oct 1998 21:40:11 +0200
 # Project:      INN
-# File:         pullnews.pl
+# File:         pullnews
 # RCSId:        $Id$
 #
 # History:
@@ -22,7 +23,8 @@
 #               machines (in the guise of a reader), and pulls over articles 
 #               and feeds them to a downstream server (in the guise of a feeder).
 #
-#               Uses a simple configuration file:  <pathdb>/pullnews.marks to define
+#               Uses a simple configuration file:  <pathdb>/pullnews.marks when
+#               run as the news user, or otherwise ~/pullnews.marks, to define
 #               which machines to pull articles from and which groups at each
 #               machine to pull over.  There is also support for more specific
 #               configurations like cross-posted newsgroups to kill, thanks to
@@ -48,7 +50,8 @@
 #
 
 # If you have INN and the script is able to successfully include your
-# INN::Config module, the value of $INN::Config::pathdb will override it.
+# INN::Config module, the value of $INN::Config::pathdb will override it
+# if pullnews is run as the news user.
 my $pathdb = $ENV{HOME};
 
 require 5.004;
@@ -67,11 +70,10 @@
 use Getopt::Std;
 use IO::Handle;
 use POSIX qw(ceil floor);
-use INN::Utils::Shlock;
 use strict;
 
 my $usage = $0;
-$pathdb = $INN::Config::pathdb if $INN::Config::pathdb;
+$pathdb = $INN::Config::pathdb if $INN::Config::pathdb && $INN::Config::runasuser && $INN::Config::runasuser eq getpwuid($<);
 my $defaultConfig = "${pathdb}/pullnews.marks";
 my $defaultPort = 119;
 my $defaultHost = "localhost";
@@ -81,10 +83,34 @@
 my $defaultRetryTime = 1;
 my $defaultProgressWidth = 50;
 my $defaultMaxArts;
+my $lockfile;
 
+# Check whether pullnews is run inside INN.
+my $use_inn_shlock = 0;
+eval {
+    require INN::Utils::Shlock;
+    import INN::Utils::Shlock;
+    $use_inn_shlock = 1;
+};
+
+# In case pullnews is run outside INN, fall back to call flock(2)
+# and its corresponding Perl function instead of shlock (a program
+# shipped with INN).
+# Note that this Perl function does not work as expected on all
+# existing systems (for instance on Solaris).
+if (not $use_inn_shlock) {
+    use Fcntl;
+    use Fcntl qw(:flock);
+}
+
 END {
     # In case we bail out, while holding a lock.
-    INN::Utils::Shlock::releaselocks();
+    if ($use_inn_shlock) {
+        INN::Utils::Shlock::releaselocks();
+    } elsif (defined $lockfile) {
+        flock (LOCK, LOCK_UN);
+        unlink $lockfile;
+    }
 }
 
 $usage =~ s!.*/!!;
@@ -101,8 +127,10 @@
                 group.  When fraction is 1.0, pull all the articles on
                 the server.  The default is to do nothing.
 
-  -c config     specify the configuration file
-                (default is ${pathdb}/pullnews.marks).
+  -c config     specify the configuration file instead of the default
+                file located in ${pathdb}/pullnews.marks when run as the news
+                user, or otherwise in ~/pullnews.marks (the running user's home
+                directory).
 
   -C width      use width characters for progress (default is $defaultProgressWidth).
 
@@ -282,11 +310,26 @@
 my $oldfh = select;
 $| = 1; select LOG; $| = 1; select $oldfh;
 
-my $lockfile = $groupFile . '.pid';
+$lockfile = $groupFile . '.pid';
 
 # Acquire a lock.
-INN::Utils::Shlock::lock($lockfile) or die "cannot create lockfile $lockfile\n";
+if ($use_inn_shlock) {
+    INN::Utils::Shlock::lock($lockfile) or die "cannot create lockfile $lockfile\n";
+} else {
+    sysopen (LOCK, "$lockfile", O_RDWR | O_CREAT, 0700)
+        or die "cannot create lockfile $lockfile: $!\n";
+    $oldfh = select; select LOCK; $| = 1; select $oldfh;
 
+    if (!flock (LOCK, LOCK_EX | LOCK_NB)) {
+        seek LOCK, 0, 0;
+        my $otherpid = <LOCK>;
+        chomp $otherpid;
+        die "Another pullnews (pid: $otherpid) seems to be running.\n";
+    }
+
+    print LOCK "$$\n";
+}
+
 print LOG scalar(localtime(time)), " start\n\n" unless $quiet;
 
 if (@groupsToGet && ! $quiet) {
@@ -546,7 +589,12 @@
 
 sub cleanLock {
     # Unlock.
-    INN::Utils::Shlock::unlock($lockfile) if defined $lockfile;
+    if ($use_inn_shlock) {
+        INN::Utils::Shlock::unlock($lockfile) if defined $lockfile;
+    } else {
+        flock (LOCK, LOCK_UN);
+        unlink $lockfile if defined $lockfile;
+    }
 }
 
 sub bail {



More information about the inn-committers mailing list