advisory file locks in linux - do they work?
Jeff Gibson
jgibson at spscommerce.com
Wed Apr 13 02:07:20 EST 2011
Hi - I'm trying to verify if OpenSSH/SFTP will in fact lock files with
advisory file locking in Linux. I can test locking with the linux
"flock" command to verify that file locking does work - but when I
upload or download a file with SFTP it will not detect a lock. I'm
asking about Linux specifically because about a year ago I was doing a
similar process in Solaris 9 and it seemed to work.
OS'n I've tried this on-
RHEL5.5 with OpenSSH 5.6p1 (compiled)
Ubuntu 10.10 with OpenSSH 5.5p1
Test
# get 100MB testfile from remote box via sftp
(sftp to remote host, get testfile)
# While that's running use the following command to check for the lock:
flock -xn testfile -c "echo test > testfile"
#flock command returns an exit status of 0. Expected result is 1
(failure). Test "test" is in testfile
Control Test
# Open a stream of data to testfile and set exclusive advisory lock
flock -xn testfile -c "cat /dev/random > testfile"
# Test for lock by trying to set another exclusive lock
flock -xn testfile -c "echo test > testfile"
Result is 1 (failure because the file is locked. Text "test" is not in
testfile.)
USENET - sorry for the double post, apparently you don't forward to the
email list?
More information about the openssh-unix-dev
mailing list