exfile / file locking

Phil Mayers p.mayers at imperial.ac.uk
Tue Jul 25 14:29:03 CEST 2017

On 25/07/17 12:48, Alan DeKok wrote:

> Because the traditional POSIX APIs are utter shit.


> If a process opens a file multiple times, and does fcntl() lock on
> one file descriptor, closing any OTHER file descriptor on that file
> causes the lock to go away.

Sure, that's well documented (as opposed to well understood ;o), and the 
mutex use is fine (necessary, as you've noted).

What I don't understand is why the code open()s to one FD but returns a 
dup()d FD to the caller. This seems to accomplish nothing - you're still 
paying for a context switch on the dup() and it's frankly hard for me to 
believe that saving the open() is worth the extra code complexity, but 
I'm assuming there's a reason.

Unless I'm missing something, the mutex around the exfile isn't 
dependent on the dup()ing of the FD?

More information about the Freeradius-Devel mailing list