Safe unlocking
From: Vladimir Zolotykh (gsmith_at_eurocom.od.ua)
Date: 11/28/03
- Next message: those who know me have no need of my name: "Re: Safe unlocking"
- Previous message: phn_at_icke-reklam.ipsec.nu: "Re: How to use tar to do increamental backup"
- Next in thread: those who know me have no need of my name: "Re: Safe unlocking"
- Reply: those who know me have no need of my name: "Re: Safe unlocking"
- Reply: Jens.Toerring_at_physik.fu-berlin.de: "Re: Safe unlocking"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 28 Nov 2003 12:14:01 +0200
Hi,
Suppose my program starts with creating and locking the file as the
follows:
if ((fd = open(file_name, O_CREAT | O_WRONLY | O_EXCL, 0644)) < 0
|| flock (fd, LOCK_EX | LOCK_NB) < 0)
abort();
Actually this is C++ program and creating and removing lock file and
its locking implemented as constructor and destructor. When the
program terminates properly all works fine and lock file successfully
removed. The problem arises when the program is terminated by a
signal. For example if the program is terminated by SIGSEGV or SIGABRT
the destructor is not called and the lock file remains locked after
the program termination.
If I knew in advance that the signal would be SIGSEGV, I would use my
signal handler function for SIGSEGV. I think that you'll readily agree
that calling SIGNAL(2) for each possible signal number would be rather
clumsy.
Therefore my question: what is the sure-fire way to remove lock file
come well, come ill?
Thanks in advance
-- Vladimir Zolotykh
- Next message: those who know me have no need of my name: "Re: Safe unlocking"
- Previous message: phn_at_icke-reklam.ipsec.nu: "Re: How to use tar to do increamental backup"
- Next in thread: those who know me have no need of my name: "Re: Safe unlocking"
- Reply: those who know me have no need of my name: "Re: Safe unlocking"
- Reply: Jens.Toerring_at_physik.fu-berlin.de: "Re: Safe unlocking"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|