🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #84484

The mailpost perl script from inn-2.5.3rc1.

#84484
From: Dennis Davis
Date: Tue, 08 Nov 2011 10:40
92 lines
3553 bytes
I've been looking at the mailpost perl script from inn-2.5.3rc1.  As
previously discussed here, the locking has been switched to use a
perl wrapper for INN's shlock program.  So locking the Message-ID
database now looks like:

INN::Utils::Shlock::lock($lockfile, 5) or mailArtAndDie ("cannot create lockfile $lockfile");

...do stuff with the database locked...

INN::Utils::Shlock::unlock($lockfile) or mailArtAndDie ("cannot unlock $lockfile ");

Code similar to the above occurs in a couple of places.

There's a slight problem with the above code.  While doing stuff
with the database locked, error conditions can cause the script to
terminate early.  Typically this is done by calling mailArtAndDie.
This will leave a lock in place, which is untidy.  This isn't a big
problem as the shlock program will detect and remove stale locks.
The simple patches appended below will try to prevent stale locks
being left behind.


--- mailpost.orig	Wed Oct 26 09:48:52 2011
+++ mailpost	Mon Nov  7 10:17:41 2011
@@ -22,15 +22,11 @@
 use strict;
 
 my $debugging = 0 ;
+my $locked = 0 ;
 my $tmpfile ;
 my $tmpfile2 ;
 my $msg ;
 
-END {
-    unlink ($tmpfile) if $tmpfile ;		# in case we die()
-    unlink ($tmpfile2) if $tmpfile2 ;		# in case we die()
-}
-
 my $usage = $0 ;
 $usage =~ s!.*/!! ;
 my $prog = $usage ;
@@ -379,6 +375,7 @@
 
 # Acquire a lock.
 INN::Utils::Shlock::lock($lockfile, 5) or mailArtAndDie ("cannot create lockfile $lockfile");
+$locked = 1;
 
 my %DATABASE ;
 dbmopen(%DATABASE, $Database, 0666) || mailArtAndDie ("can't dbmopen $Database: $!");
@@ -405,6 +402,7 @@
 
 # Unlock.
 INN::Utils::Shlock::unlock($lockfile) or mailArtAndDie ("cannot unlock $lockfile");
+$locked = 0;
 
 ## For crosspost.
 
@@ -431,6 +429,7 @@
 
   # Acquire a lock.
   INN::Utils::Shlock::lock($lockfile, 5) or mailArtAndDie ("cannot create lockfile $lockfile");
+  $locked = 1;
 
   my $umask_bak = umask();
   umask(000);
@@ -445,6 +444,7 @@
 
   # Unlock.
   INN::Utils::Shlock::unlock($lockfile) or mailArtAndDie ("cannot unlock $lockfile");
+  $locked = 0;
 
   if (defined($dup)) {
     syslog("err", "mismatch $newsgroups") if $debugging && $use_syslog;
@@ -597,6 +597,15 @@
   }
   return join ",", @orig ;
 
+}
+
+END {
+    unlink ($tmpfile) if $tmpfile ;		# in case we die()
+    unlink ($tmpfile2) if $tmpfile2 ;		# in case we die()
+    #
+    # in case we bale out, typically by calling mailArtAndDie, while
+    # holding a lock.
+    INN::Utils::Shlock::unlock($lockfile) if $locked ;
 }
 
 =head1 NAME
-- 
Dennis Davis, BUCS, University of Bath, Bath, BA2 7AY, UK
D.H.Davis@bath.ac.uk
Technical Details
Message-ID: <LuC8By.M8s.B.shoe@bath.ac.uk>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20141118.mbox.gz!border1.nntp.dca3.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!goblin3!goblin.stu.neva.ru!nntp-feed.chiark.greenend.org.uk!ewrotcd!bath.ac.uk!unknown

Show Full Headers
Complete Article Headers
Message-ID: <LuC8By.M8s.B.shoe@bath.ac.uk>
Subject: The mailpost perl script from inn-2.5.3rc1.
Date: Tue, 8 Nov 2011 10:40:46 GMT
From: Dennis Davis <D.H.Davis@bath.ac.uk>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20141118.mbox.gz!border1.nntp.dca3.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!goblin3!goblin.stu.neva.ru!nntp-feed.chiark.greenend.org.uk!ewrotcd!bath.ac.uk!unknown
Newsgroups: news.software.nntp
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Sender: unknown@larch.bath.ac.uk (Address not verified)
Organization: BUCS, University of Bath, UK
Originator: ccsdhd@bath.ac.uk (Dennis Davis)
Lines: 91
X-Original-Bytes: 3277