🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #84216

Re: Mail-to-News

#84216
From: Dennis Davis
Date: Mon, 25 Jul 2011 15:15
84 lines
3554 bytes
In the referenced article, =?ISO-8859-1?Q?Julien_=C9LIE?= <iulius@nom-de-mon-site.com.invalid> writes:
>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)?

Many apologies, I misled you.  OpenBSD *does* have fcntl(2) and
flock(2).  Don't know how I manged to think fcntl(2) wasn't
available.  I they're all closely related, I expect fcntl(2) to be
also available on the other *BSD systems.

...

>> 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; };

That's one way of making conditional use of INN::Utils::Shlock::unlock,
and by inference conditional use of INN's shlock program.

Some time ago I was trying to set up locking in shell scripts.  I
used the code below.  I'm sure I got this idea from Cnews, it relies
on hard-linking being an atomic event on Unix systems to avoid race
conditions.  This, or similar code, is readily translated to perl
and would give a primitive form of locking for stand-alone programs
such as signcontrol.


cd $fetchesdir || exit 1

# Primitive locking, to avoid straying into the gunsights of some
# running program...
pid=$$
lockname=LOCK_FETCH
lock_temp=$lockname.$pid
trap "$rm -f $lock_temp; trap 0" 0 1 2 15
$echo $pid > $lock_temp || exit 1

tries=
while :
do
  if $ln $lock_temp $lockname 2> /dev/null
  then
    $rm -f $lock_temp
    trap "$rm -f $lockname; trap 0" 0 1 2 15
    break
  fi
  tries=$(($tries + 1))
  [ $tries -gt $max ] && exit 1
  $sleep $sleeptime
done

# Got a lock, proceed as normal.



>As for pullnews:

...

That looks good.
-- 
Dennis Davis, BUCS, University of Bath, Bath, BA2 7AY, UK
D.H.Davis@bath.ac.uk
Technical Details
Message-ID: <LowADL.6K1.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!border1.nntp.ams3.giganews.com!border1.nntp.ams2.giganews.com!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!feeder.news-service.com!aioe.org!news.stack.nl!feeds.news.ox.ac.uk!news.ox.ac.uk!bath.ac.uk!ccsdhd
References: <iuaorh$gbt$1@n102.xanadu-bbs.net> <ivvjd7$c15$1@news.trigofacile.com> <LoJ8po.KpC.B.larch@bath.ac.uk> <j0i3oa$k8a$1@news.trigofacile.com>

Show Full Headers
Complete Article Headers
Message-ID: <LowADL.6K1.B.larch@bath.ac.uk>
Subject: Re: Mail-to-News
Date: Mon, 25 Jul 2011 15:15:21 GMT
From: ccsdhd@bath.ac.uk (Dennis Davis)
References: <iuaorh$gbt$1@n102.xanadu-bbs.net> <ivvjd7$c15$1@news.trigofacile.com> <LoJ8po.KpC.B.larch@bath.ac.uk> <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!border1.nntp.ams3.giganews.com!border1.nntp.ams2.giganews.com!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!feeder.news-service.com!aioe.org!news.stack.nl!feeds.news.ox.ac.uk!news.ox.ac.uk!bath.ac.uk!ccsdhd
Newsgroups: news.software.nntp
Organization: BUCS, University of Bath, UK
Lines: 83
X-Original-Bytes: 3208