Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Linux fopen() mistery. Help required.

kalbikalbi Member Posts: 1

I'm having problems with fopen() call in Linux.

I have shared library (created by myself) that implements some file operations:
int lib_func(char* file_name) {
fd = fopen(file_name, "r");
if(!fd) {... exit with error ...}
do something useful using fd
Also I have two programs (pr1 and pr2) that use that library and they call lib_func(): lib_func("/dir/dir/file");

Here is the mystery:
- if I run pr1 from command line, lib_func() is called successfully and file is accessed as required;
- if I run pr2 as daemon, lib_func() is called but fopen() fails with ERRNO=2 (No such file or directory).
How can I fix it to run with pr2?

What I have checked so far:
1. I start pr1 and pr2 strictly in different times (no simultaneous running).
2. File in question exists (I can view it, copy it, delete it from shell).
3. Path to file is absolute.
4. No compile warnings/errors.
5. pr2 is in userspace.
6. Both processes are running from root user and have rights for the file access (777).
7. SELinux is in permissive mode (no effect on system operation).
8. No other process is blocking the file.

Any ideas?

Sign In or Register to comment.