INN commit: branches/2.5 (4 files)
INN Commit
rra at isc.org
Mon Jul 8 19:28:15 UTC 2013
Date: Monday, July 8, 2013 @ 12:28:15
Author: iulius
Revision: 9504
pullnews: looks for the config file in the running user's 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.
Thanks to Tony Evans for the bug report.
Modified:
branches/2.5/CONTRIBUTORS
branches/2.5/doc/pod/news.pod
branches/2.5/doc/pod/pullnews.pod
branches/2.5/frontends/pullnews.in
-----------------------+
CONTRIBUTORS | 2 -
doc/pod/news.pod | 8 ++++++
doc/pod/pullnews.pod | 5 +--
frontends/pullnews.in | 64 ++++++++++++++++++++++++++++++++++++++++--------
4 files changed, 65 insertions(+), 14 deletions(-)
Modified: CONTRIBUTORS
===================================================================
--- CONTRIBUTORS 2013-07-03 20:08:03 UTC (rev 9503)
+++ CONTRIBUTORS 2013-07-08 19:28:15 UTC (rev 9504)
@@ -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-03 20:08:03 UTC (rev 9503)
+++ doc/pod/news.pod 2013-07-08 19:28:15 UTC (rev 9504)
@@ -39,6 +39,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-03 20:08:03 UTC (rev 9503)
+++ doc/pod/pullnews.pod 2013-07-08 19:28:15 UTC (rev 9504)
@@ -267,10 +267,9 @@
The Perl script itself used to pull news from upstream servers and feed
it to another news server.
-=item I<$HOME>/.pullnews
+=item ~/.pullnews
-The default config file. It is in the running user's home directory
-(normally called F<~/.pullnews>).
+The default config file. It is in the running user's home directory.
=back
Modified: frontends/pullnews.in
===================================================================
--- frontends/pullnews.in 2013-07-03 20:08:03 UTC (rev 9503)
+++ frontends/pullnews.in 2013-07-08 19:28:15 UTC (rev 9504)
@@ -1,6 +1,7 @@
#! /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
@@ -22,7 +23,7 @@
# 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: $HOME/.pullnews to define
+# Uses a simple configuration file: ~/.pullnews 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
@@ -63,11 +64,10 @@
use Getopt::Std;
use IO::Handle;
use POSIX qw(ceil floor);
-use INN::Utils::Shlock;
use strict;
my $usage = $0;
-my $defaultConfig = "$ENV{HOME}/.pullnews";
+my $defaultConfig = (getpwuid($<))[7] . "/.pullnews";
my $defaultPort = 119;
my $defaultHost = "localhost";
my $defaultCheckPoint = 0;
@@ -76,10 +76,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!.*/!!;
@@ -97,7 +121,7 @@
the server. The default is to do nothing.
-c config specify the configuration file instead of the
- default of $ENV{HOME}/.pullnews (also called ~/.pullnews).
+ default of ~/.pullnews (in the running user's home directory).
-C width use width characters for progress (default is $defaultProgressWidth).
@@ -277,11 +301,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) {
@@ -541,7 +580,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