Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
A privileged program should always check to see whether system calls and library functions succeed, and whether they return expected values. (This is true for all programs, of course, but is especially important for privileged programs.) Various system calls can fail, even for a program running as root. For example, fork() may fail if the system-wide limit on the number of processes is encountered, an open() for writing may fail on a read-only file system, or chdir() may fail if the target directory doesn’t exist.
Even where a system call succeeds, it may be necessary to check its result. For example, where it matters, a privileged program should check that a successful open() has not returned one of the three standard file descriptors: 0, 1, or 2.