/var/lock/subsys permission denied for root

Hello

I have simple line of code here:

FILE *lockfp = fopen("/var/lock/subsys/processName", "w");

which is denied even running as root. The result is

locking failed for the following reason: Permission denied

How is this possible? Why is this happening?

Thanks for your help

I don't see how that line of code could print that error message. Could you show the rest of it?

Also, do

ls -ld /var/lock/subsys /var/lock/subsys/processName

the file doesn't exist and I am trying to create it. however, for the whole directory, the permissions are:

drwxr-xr-x 2 root root 4096 May 15 14:23 /var/lock/subsys
 

there are no more error messages, thats the only one and the program exists. I have narrowed it down to that one line; if i take it out the program continues to the next section and so forth.

If you take out that line, other things using lockfp ought to complain about that variable not even existing.

And what the rest of the code does is certainly important. There may be bugs that misinterpret its return value, for instance.

Can we please see more of the code?

Also, a df -h just to make sure /var/lock/subsys/ isn't some odd filesystem that even root can't write to.

hmm you are right, I wasn't being logical with my testing.

if I have that line in, both a regular user and root have issues. (by line, i mean the code associated with using that variable as well, which is just a simple if-statement to use lockfp) if i take out that section, the regular user can execute the code but then the root still has the same problem.

thanks, i'll investigate some more.