Skip Menu |
 

To: krb5-bugs@MIT.EDU
Subject: profile library update leaves window with no file
From: Ken Raeburn <raeburn@MIT.EDU>
Date: Tue, 07 Jan 2003 00:09:36 -0500
The update process for a profile file (via profile_flush_file_data)
works by renaming the old version out of the way and then renaming the
new one into place. This means it's possible for another process (or
another thread, perhaps) to look and find the file doesn't exist. The
window is small, but should be closed.

Under UNIX, it's easy. Create a hard link to the old file with the
backup filename, then rename the new file into place; UNIX filesystem
semantics guarantee that the filename will be valid at all times.

I'm not sure what can be done on Windows to close this (ahem) window;
I'm not familiar enough with the relevant Windows semantics.

Ken

P.S. This is unrelated to the data-sharing changes Miro wrote.
From: raeburn@mit.edu
Subject: CVS Commit
Try to do atomic file swap on UNIX when updating profile.

* prof_file.c (make_hard_link): New function.
(profile_flush_file_data): Use it to attempt a safe profile file replacement.


To generate a diff of this commit:



cvs diff -r1.124 -r1.125 krb5/src/util/profile/ChangeLog
cvs diff -r1.27 -r1.28 krb5/src/util/profile/prof_file.c
Looks fixed for UNIX; can we do anything better for Windows?
[raeburn - Thu Jun 5 20:00:20 2003]:

Show quoted text
> Looks fixed for UNIX; can we do anything better for Windows?

On an NTFS file system we could probably use a similar trick. We can
use the CreateHardLink() call to create a temp name for the original
file; then CreateHardLink() the new file to the original name; and
finally delete the new file.

However, this will only work on NTFS.

- Jeff