🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #84211

Re: Mail-to-News

#84211
From: Julien ÉLIE
Date: Sun, 24 Jul 2011 21:44
112 lines
4430 bytes
Hi Dennis,

> The *BSD systems, OpenBSD at least, have flock(2) but not fnctl(2).
> Solarix has fnctl(2) but *not* flock(2), other than in the SunOS/BSD
> Compatibility Library Functions, which aren't really usable for
> me.  This is a potential problem when installing INN on Solaris as
> several of the perl scripts use the flock perl function.  Including
> the mailpost script which I want to use.

Does it also affect fcntl() used in our C code (on *BSD systems)?

For instance:

innfeed/endpoint.c
-> int newfd = fcntl(fd, F_DUPFD, stdioFdMax + 1);

lib/fdflags.c
-> fcntl(fd, F_SETFD, flag ? (oflag | FD_CLOEXEC) : (oflag & ~FD_CLOEXEC));

lib/lockfile.c
-> status = fcntl(fd, block ? F_SETLKW : F_SETLK, &fl);



And for flock():

storage/buffindexed/shmem.c
-> if( flock( fd, LOCK_EX ) < 0 ) {



> Patches to mailpost are given below in case they're of use to anyone
> else.

OK, thanks.  I obtain a similar patch with INN::Utils::Shlock.



> The pullnews and signcontrol perl scripts that come with INN also use
> flock; I suppose I should also look at these scripts.

Unfortunately, signcontrol does not currently use any INN variables.
(It is designed to work as a stand-alone program.)
Directly adding INN::Utils::Shlock would be weird.  Maybe a solution based on your
LockFile::Simple example would be best.  This time using:
 eval { require INN::Utils::Shlock; import INN::Utils::Shlock;
        $use_shlock = 1; };



As for pullnews:

--- frontends/pullnews.in	(révision 9281)
+++ frontends/pullnews.in	(copie de travail)
@@ -68,8 +68,7 @@
 use Getopt::Std;
 use IO::Handle;
 use POSIX qw(ceil floor);
-use Fcntl;
-use Fcntl qw(:flock);
+use INN::Utils::Shlock;
 use strict;
 
 my $usage = $0;
@@ -275,23 +274,15 @@
 }
 open(LOG, $logFile) || die "can't open logfile ($logFile)!: $!\n";
 
+# Forces a flush after each write or print.
 my $oldfh = select;
 $| = 1; select LOG; $| = 1; select $oldfh;
 
 my $lockfile = $groupFile . '.pid';
-sysopen (LOCK, "$lockfile", O_RDWR | O_CREAT, 0700) ||
-    die "can't create lock file ($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";
-}
+# Acquire a lock.
+INN::Utils::Shlock::lock($lockfile) or die "cannot create lockfile $lockfile\n";
 
-print LOCK "$$\n";
-
 print LOG scalar(localtime(time)), " start\n\n" unless $quiet;
 
 if (@groupsToGet && ! $quiet) {
@@ -550,8 +541,8 @@
 }
 
 sub cleanLock {
-    flock (LOCK, LOCK_UN);
-    unlink $lockfile if defined $lockfile;
+    # Unlock.
+    INN::Utils::Shlock::unlock($lockfile) if defined $lockfile;
 }
 
 sub bail {





-- 
Julien ÉLIE

« Ce n'est pas en tournant le dos aux choses qu'on leur fait face. »
  (Pierre Dac)
Technical Details
Message-ID: <j0i3oa$k8a$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!num2.nntp.dca.giganews.com!num1.nntp.dca.giganews.com!number.nntp.dca.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!goblin2!goblin.stu.neva.ru!weretis.net!feeder4.news.weretis.net!news.trigofacile.com!.POSTED.aaubervilliers-552-1-18-32.w92-141.abo.wanadoo.fr!not-for-mail
References: <iuaorh$gbt$1@n102.xanadu-bbs.net> <iufpeq$qgh$1@n102.xanadu-bbs.net> <LnLzu6.6IE.B.larch@bath.ac.uk> <ivvjd7$c15$1@news.trigofacile.com> <LoJ8po.KpC.B.larch@bath.ac.uk>

Show Full Headers
Complete Article Headers
Message-ID: <j0i3oa$k8a$1@news.trigofacile.com>
Subject: Re: Mail-to-News
Date: Sun, 24 Jul 2011 23:44:42 +0200
From: Julien ÉLIE <iulius@nom-de-mon-site.com.invalid>
References: <iuaorh$gbt$1@n102.xanadu-bbs.net> <iufpeq$qgh$1@n102.xanadu-bbs.net> <LnLzu6.6IE.B.larch@bath.ac.uk> <ivvjd7$c15$1@news.trigofacile.com> <LoJ8po.KpC.B.larch@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!num2.nntp.dca.giganews.com!num1.nntp.dca.giganews.com!number.nntp.dca.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!goblin2!goblin.stu.neva.ru!weretis.net!feeder4.news.weretis.net!news.trigofacile.com!.POSTED.aaubervilliers-552-1-18-32.w92-141.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
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 24 Jul 2011 21:44:42 +0000 (UTC)
Injection-Info: news.trigofacile.com;
 posting-host="aaubervilliers-552-1-18-32.w92-141.abo.wanadoo.fr:92.141.81.32";
 logging-data="20746"; mail-complaints-to="abuse@trigofacile.com"
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.7; fr;
In-Reply-To: <LoJ8po.KpC.B.larch@bath.ac.uk>
Lines: 111