Re: Safe unlocking
From: Vladimir Zolotykh (gsmith_at_eurocom.od.ua)
Date: 11/28/03
- Next message: Vladimir Zolotykh: "Re: Safe unlocking"
- Previous message: Jens.Toerring_at_physik.fu-berlin.de: "Re: Safe unlocking"
- In reply to: Jens.Toerring_at_physik.fu-berlin.de: "Re: Safe unlocking"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 28 Nov 2003 15:18:51 +0200
Jens.Toerring@physik.fu-berlin.de wrote:
> Vladimir Zolotykh <gsmith@eurocom.od.ua> wrote:
>
>>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.
>>
>
> Since when flock() does create a lock file? Unless the flock() function
> is something you wrote yourself instead of using the system call there
> won't be a lock file, the kernel sets some bits in the open file table
> entry for the file. And when your program exits (by whatever way) the
> file gets closed automatically and the lock vanishes leaving no traces.
FLOCK(2) says that flock "Apply or remove an advisory lock on an open file.".
Flock() doesn't create a file, someone must do it as well as open it
before calling flock.
>
> If you really have a lock file you need to get rid of register an
> atexit() function to be called when the function exits (but, of
> course, this won't be called on a SIGKILL signal, but than that's
> a case where also a signal handler woudn't help you).
I am afraid that there is a kind of mistake here. As far as I concerned
atexit works only for normal program termination e.g., via exit(3) or return.
Using Slackware 8.1 (Kernel 2.4.18)
>
> Regards, Jens
>
-- Vladimir Zolotykh
- Next message: Vladimir Zolotykh: "Re: Safe unlocking"
- Previous message: Jens.Toerring_at_physik.fu-berlin.de: "Re: Safe unlocking"
- In reply to: Jens.Toerring_at_physik.fu-berlin.de: "Re: Safe unlocking"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|