🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #84901

Re: The mailpost perl script from inn-2.5.3rc1.

#84901
From: Julien ÉLIE
Date: Mon, 28 May 2012 18:38
112 lines
4278 bytes
Hi Dennis,

Sorry for my very late reply.
I have just managed to have a look at it.


>> INN::Utils::Shlock would then keep track of still used lock files during
>> the run of a Perl script (through an array because several lock files
>> can exist at the same time for a script).
>> Then, it would be enough to add INN::Utils::Shlock::releaselocks() in an
>> END section in all the Perl scripts using this module.
>
> That's a much better idea.  Why didn't I think of it :-(
>
> The patches below are for INN::Utils::Shlock and are a quick
> and dirty attempt to implement this functionality.  I haven't
> added anything to the manul page, although this does need a few
> descriptive lines.

OK, many thanks for your suggestion.

I also changed the unlock() function to delete successfully released 
lock files from the %lockfiles hash.
Otherwise, we might get into concurrent accesses (when instance #1 of a 
script exits, it calls releaselocks() and could erase a possible valid 
lock file of instance #2 of the same script running at the same time).

Suggested change is:

  sub unlock {
      my $lockfile = shift;
-    return unlink $lockfile;
+    if (unlink $lockfile) {
+        delete $lockfiles{$lockfile};
+        return 1;
+    } else {
+        return 0;
+    }
  }



> + ##
> + ## Attempt to unlock any leftover locks.
> + ##
> + sub releaselocks {
> +     my $key;
> +     foreach $key (keys(%lockfiles)) {
> +         unlock($key);
> +     }
> +     undef(%lockfiles);
> +     return 1;
> + }

I modified the return value so as to obtain additional information.

+##
+##  Attempts to unlock any leftover locks.
+##  Returns the number of removed locks.
+##
+sub releaselocks {
+    my $key;
+    my $count = 0;
+
+    foreach $key (keys(%lockfiles)) {
+        $count += unlock($key);
+    }
+
+    undef(%lockfiles);
+    return $count;
+}


And also:

-our @EXPORT_OK = qw(lock unlock);
+our @EXPORT_OK = qw(lock unlock releaselocks);


Documentation:

Instead of calling unlock(I<lockfile>), the releaselocks()
function can be called.  It removes any leftover locks, which is useful
when several different locks are used.  Another possible use is to call
it in an END code block:

     END {
         # In case we bail out, while holding a lock.
         INN::Utils::Shlock::releaselocks();
     }


=item releaselocks()

Removes all the lock files previously created by calling the
lock(I<lockfile>) function.

This function returns the number of removed lock files.






I hope that's fine for you.  It will be shipped with INN 2.5.3.
Thanks again for your useful feedback about the 2.5.3rc1 version 
(release candidate).

-- 
Julien ÉLIE

« Etna : lave dévalante. »
Technical Details
Message-ID: <jq0gnp$khj$1@news.trigofacile.com>
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!goblin2!goblin3!goblin.stu.neva.ru!news.matabio.net!jeffrey.matabio.net!news.trigofacile.com!.POSTED.aaubervilliers-652-1-9-100.w81-249.abo.wanadoo.fr!not-for-mail
References: <LuC8By.M8s.B.shoe@bath.ac.uk> <ja1blc$13g$1@news.trigofacile.com> <LutCsG.JCt.B.shoe@bath.ac.uk>

Show Full Headers
Complete Article Headers
Message-ID: <jq0gnp$khj$1@news.trigofacile.com>
Subject: Re: The mailpost perl script from inn-2.5.3rc1.
Date: Mon, 28 May 2012 20:38:48 +0200
From: Julien ÉLIE <iulius@nom-de-mon-site.com.invalid>
References: <LuC8By.M8s.B.shoe@bath.ac.uk> <ja1blc$13g$1@news.trigofacile.com> <LutCsG.JCt.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!goblin2!goblin3!goblin.stu.neva.ru!news.matabio.net!jeffrey.matabio.net!news.trigofacile.com!.POSTED.aaubervilliers-652-1-9-100.w81-249.abo.wanadoo.fr!not-for-mail
Newsgroups: news.software.nntp
Organization: TrigoFACILE -- http://www.trigofacile.com/
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 28 May 2012 18:38:49 +0000 (UTC)
Injection-Info: news.trigofacile.com;
 posting-host="aaubervilliers-652-1-9-100.w81-249.abo.wanadoo.fr:81.249.224.100";
 logging-data="21043"; mail-complaints-to="abuse@trigofacile.com"
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.7; fr; rv:1.9.2.28)
 Gecko/20120306 Thunderbird/3.1.20
In-Reply-To: <LutCsG.JCt.B.shoe@bath.ac.uk>
Lines: 111
X-Original-Bytes: 3998