Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: nospam@zk3.dec.com (Eric Werme - replace nospam with werme)
Subject: Re: flock/lockf under DU
Date: 1998/10/30	[thread overview]
Message-ID: <71ce9q$opb$1@nntpd.lkg.dec.com> (raw)
In-Reply-To: 36397876.693A0DB2@na.astro.it

Massimo Gais <mgais@na.astro.it> writes:

>I'd like to now what's the best function to call under DU (4.0)
>between flock() and lockf();

I tell everyone to use fcntl() as I can never remember what the others
do.

Lessee...

From lockf(3)
  The lockf() function locks and unlocks sections of an open file.  Unlike
  the fcntl() function, however, its interface is limited to setting only
  write (exclusive) locks.

  Although the lockf() and fcntl() functions are different, the implementa-
  tions are fully integrated.  Therefore, locks obtained from one function
  are honored and enforced by the other lock function.

So, flock(2) _in currently shipping code_ is separate:

  The flock() interface is not part of any UNIX standard.  Therefore, if you
  are designing and writing applications to be portable across platforms,
  DIGITAL recommends that you use the fcntl() file locking interface instead
  of flock().

Internally, flock does VFS-level locking, i.e., the real file system is
not told of what's happening.  This makes flock useleess on NFS files
if multiple systems are involved.

_However_, in the next major release, the flock interface will
call the fcntl-style locking routines and _will_ work over NFS.

Still, please use fcntl....  BTW, lockf(3) is a libc routine that calls
fcntl(2).

>I have to fopen() the mail spoolfile for reading, but if I 
>another process has already locked with flock() the fopen()
>simple doesn't care...

Both locking styles are "advisory locking"  Mandatory locking is
available on local file systems.  See chmod(2).  I am in the camp
that says mandatory locking is the work of the devil.  Don't use it.
Trying to make this work over NFS would result in massive confusion
because someone on a NFS client could lock a file on the server.  Either
lock state would have to be preserved over reboots or reboots could
only be done when the client releases the lock.

>I was thinking this way because DU should be a BSD-derivative Unix, 
>so it should at first use flock(), not lockf().

Solaris supports flock(), but does fcntl-style locking.
flock(2) was written before BSD shipped NFS.  OSF/1 came with
the Univ. of Guelph NFS, but we replaced that with Sun's ONC NFS.  OSF
put in a lot of SysVisms.  I'd recommend you stick to Posix calls
whereever possible.
--
<>    Eric (Ric) Werme     <> The above is unlikely to contain   <>
<>    ROT-13 addresses:    <> official claims or policies of     <>
<>   <jrezr@mx3.qrp.pbz>   <> Compaq Computer Corp.              <>
<> <jrezr@plorecbegny.arg> <>  http://www.cyberportal.net/werme  <>



  reply	other threads:[~1998-10-30  5:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-10-30  5:00 flock/lockf under DU Massimo Gais
1998-10-30  5:00 ` Eric Werme - replace nospam with werme [this message]
1998-11-15  5:00   ` Mike harrelson
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox