Part 2 of 7 · 2 min read
The report
Think of a delivery driver who cannot enter a building. The cause may be a locked front gate, a closed office door, a missing pass, or a road that leads to the wrong address. The driver's note "could not get in" says little, and the note "the gate was locked" says a lot. The analogy stops in one place: a driver has a person to ask, while a program has only one number, the error code.
In plain words: A team reports: "The report job runs as nobody and says Permission denied for /tmp/l8/l10/cs/proj/private/report.txt. The file is world-readable." The method is to read the exact error first, because the kernel uses different codes for different refusals, and then to test each cause in turn. The table lists the usual codes for a failed open.
| Error | Text | Usual cause | Page of this level |
|---|---|---|---|
| EACCES | Permission denied | A mode bit, an access list, or a policy refused it | 2, 6 |
| EPERM | Operation not permitted | A missing capability, or a seccomp filter | 4, 6 |
| ENOENT | No such file or directory | The name does not exist in this process's view | 6 |
| EMFILE | Too many open files | A resource limit | 6 |
| EROFS | Read-only file system | A write to a read-only mount | 6 (Level 9) |
A worked example. The report job fails with Permission denied, which is EACCES. That points to the file modes and the policy, and rules out a limit (EMFILE), a filter (usually EPERM) and a missing name (ENOENT). The next steps follow the EACCES path.
The key lines. Always capture the code before changing anything. strace -e trace=openat shows it with the name of the call that failed, in one line.
errno
errno is the number that a failed system call leaves for the program, and each number has a standard name such as EACCES or ENOENT. It tells which kind of refusal happened, so it is the first piece of evidence in any access problem.
Example: open that returns -1 with errno set to EACCES (13) prints "Permission denied".
Check yourself: 1. Which error code means "the name does not exist in this view"? 2. Which two causes usually give EPERM? 3. Why capture the error before changing anything?