Possible reasons for resuming a linux EINVAL call

I am trying to make a system call in my source code as follows.

int file; file = open(argv[index], O_RDONLY); 

Where the command line argument is the path to the binary on my file system. But this call causes an EINVAL error. I checked the availability of the file and the necessary permissions to access it.

Any suggestions regarding the circumstances under which the EINVAL error will be rejected.

+4
source share
3 answers

Reason for failure:

There were two processes (process-1 and process-2) that ran in close sequel and tried to open this binary. Since my system (embedded device) crashes after this open call, the debugs that were broken were incorrect, and this made me suspect process-1. But the actual culprit is process-2, which opened the binary with the O_RDWR flag. But my file system (network connection) was mounted as a read-only file system .

Supports to pay attention to:

When updating perror print , this should be the correct cause of the problem: read-only file system . Therefore, my original description of perror should be the unclean value of any of the previous erroneous calls. One study is to use perror with caution to avoid parsing an error message.

Possible circumstances: an EINVAL error will be selected :

An open call will show EINVAL if we use O_SYNC (or) related flags for a file that we should not use. I do this based on documentation, as previously mentioned by Rafe.

+2
source

The official documentation suggests that this is because your open() implementation does not support synchronized I / O for the file you are trying to open.

+1
source

If you are sure that argv[index] really contains the file name and that O_RDONLY not redefined in any way ( O_RDONLY should be 0), check your syslog using the dmesg and make sure nothing funky happened in the kernel.

+1
source

All Articles