I don’t mean locking the file!

What I want to achieve is that all other threads should access the file without any problem, but in some circumstances I want to fail calls which are accessing that file through fd like dup2(2), ftruncate(2), etc. One option is to make a wrapper for all such functions like dup2(2), that will first check if to allow fd or no and then call the real dup2(2). But its a long task to do it with every sys call using fd.

Maybe if there is a solution to password protect a file so that it can only be accessed when specified password is given.

My library is being injected to anonymous process so I don’t have control over the caller and I observe that anonymous process doesn’t check fd before using it. It ends up using the fd my library is using.

Kindly don’t complain about the design issues. Please just focus on problem.