1

What happens if I'm trying to set a, say, F_RDLCK lease on a file that is already open for a writing somewhere else.

fcntl(2) says

A read lease can be placed only on a file descriptor that is opened read-only.

Does it mean it should be open read-only system-wise and otherwise fcntl(2) call will fail with, presumingly EACCES? If so, is there any other way to wait for the lease to be possible other than using inotify(7) (IN_CLOSE_WRITE)?

gavv
  • 4,649
  • 1
  • 23
  • 40
Andrian Nord
  • 677
  • 4
  • 11

1 Answers1

1

This call:

fcntl(fd, F_SETLEASE, F_RDLCK)

will fail with EAGAIN ("Resource temporarily unavailable") if underlying file is currently opened for writing in any process.

It corresponds to description in manual page:

EACCES or EAGAIN

Operation is prohibited by locks held by other processes.

If caller itself opened fd for writing (i.e. not with O_RDONLY flag), it's just a special case of this rule and fcntl() also returns EAGAIN.

gavv
  • 4,649
  • 1
  • 23
  • 40