[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[afnog] lockf() and open() : Theoretical Questions
- To: afnog at afnog.org
- Subject: [afnog] lockf() and open() : Theoretical Questions
- From: "Begumisa Gerald M." <beg_g at eahd.or.ug>
- Date: Sat, 26 Jul 2003 16:03:32 +0300 (EAT)
- Content-Type: TEXT/PLAIN; charset=US-ASCII
- Delivered-To: afnog-archive at lists.eahd.or.ug
- Delivered-To: afnog at afnog.org
- List-Archive: <http://listserv4.cfi.co.ug/pipermail/afnog>
- List-Help: <mailto:afnog-request at afnog.org?subject=help>
- List-Id: The AfNOG general discussion list <afnog.afnog.org>
- List-Post: <mailto:afnog at afnog.org>
- List-Subscribe: <http://listserv4.cfi.co.ug/mailman/listinfo/afnog>,<mailto:afnog-request at afnog.org?subject=subscribe>
- List-Unsubscribe: <http://listserv4.cfi.co.ug/mailman/listinfo/afnog>,<mailto:afnog-request at afnog.org?subject=unsubscribe>
- Sender: afnog-bounces at afnog.org
Hi all,
I have two questions:
1) Does anyone know of an implementation of mandatory file locking in
FreeBSD (similar to that provided in linux from the lockf()
interface)? I've read the lockf(3), flock(2) and fcntl(2) man pages
all imply advisory-mode locks.
Is it possible for a process to lock a file (or a section of one) such
that no other process may open/read/write to that file in FreeBSD using
the usual system calls (write(), read() etc...)
2) I was faced with an interesting situation in a program I am writing. I
wanted to open a file, lock it, modify it's contents and close it. I
decided to open it with open() and flags O_RDWR then lock it with
lockf(), read it line by line and modify the required lines whilst
saving the modifications to a temporary file I obtained with tmpfile().
Now here came the problem, how could I delete the contents of the
original file without losing the locks for even the shortest possible
period of time and write back the data from the temporary file.
Does anyone have any ideas on this?
I kind of failed to do that so as a work around I decided to just
open() the first file with flags O_RDONLY in the first case then
close() it and finally open it again with flags O_RDWR (only *then* do
I lock it). I thought this would kind of leave way for race
conditions (or am I wrong)...
Thanks for any help in advance...
Regards,
Gerald.
__________________________________________________
This is the Africa Network Operators' Group(AfNOG)
technical discussion list.
The AfNOG website is: <http://www.afnog.org>