System call error handling
System calls that fail to complete successfully almost always return a value of -1 to your program.
(If you look through the system calls in Section 2, you will see that there are a few calls for which no return value is defined, but they are the exceptions.)
In addition to the -1 returned to the program, the unsuccessful system call places an integer in an externally declared variable, errno.
In a C program, you can determine the value in errno if your program contains the following statement:
#include <errno.h>
The C language function
perror(3C)
can be used to print an error
message (on stderr) based on the value of errno.
The value in errno is not cleared on successful calls,
so your program should check it only if
the system call returned a -1 indicating an error.
The following list identifies the error numbers and symbolic names defined
in the <errno.h> header file, and described in
intro(2).
1 EPERM-
Not privileged.
Typically this error indicates
an attempt to modify a file in some way forbidden
except to its owner or
a process with the appropriate privilege.
It is also returned for attempts
by ordinary users to do things
allowed only to the super-user.
2 ENOENT-
No such file or directory.
A file name is specified and the file should exist but fails to,
or one of the directories in a path name fails to exist.
3 ESRCH-
No such process.
No process can be found corresponding to the that specified by PID
in thekill orptrace routine.
4 EINTR-
Interrupted system call.
An asynchronous signal (such as interrupt or quit),
which the user has elected to catch,
occurred during a system service routine.
If execution is resumed
after processing the signal,
it will appear as if the interrupted routine call
returned this error condition.
5 EIO-
I/O error.
Some physical I/O error has occurred.
This error may in some cases occur
on a call following the one to which it actually applies.
6 ENXIO-
No such device or address.
I/O on a special file refers to a subdevice which does not
exist,
or exists beyond the limit of the device.
It may also occur when, for example, a tape drive
is not on-line or no disk pack is loaded on a drive.
7 E2BIG-
Arg list too long.
An argument list longer than
ARG_MAX
bytes is presented to a member of the
exec family of routines.
The argument list limit is sum of the size of the argument
list plus the size of the environment's exported shell variables.
8 ENOEXEC-
Exec format error.
A request is made to execute a file
which, although it has the appropriate permissions,
does not start with a valid format (see
a.out(4)).
9 EBADF-
Bad file number.
Either a file descriptor refers to no
open file,
or a
read
[respectively,
write]
request is made to
a file that is open only for writing (respectively, reading).
10 ECHILD-
No child processes.
A
wait routine
was executed by a process that had no existing or unwaited-for child processes.
11 EAGAIN-
Resource is temporarily unavailable.
For example,
the
fork routine
failed because the system's process table is full
or the user is not allowed to create any more
processes.
Or a system call failed because of insufficient memory or swap space.
12 ENOMEM-
Not enough space.
During execution of an
exec,
brk,
or
sbrk routine,
a program asks for more space than the system is able to supply.
This is not a temporary condition; the maximum size is a system parameter.
The error may also occur if the arrangement of text, data, and stack segments requires too many segmentation registers, or
if there is not enough swap space during thefork routine.
13 EACCES-
Permission denied.
An attempt was made to access a file in a way forbidden
by the protection system.
14 EFAULT-
Bad address.
The system encountered a hardware fault in attempting to
use an argument of a routine.
For example,errno potentially may be set toEFAULT
any time a routine that takes a pointer argument is passed an invalid address,
if the system can detect the condition.
Because systems will differ in their ability to reliably detect a bad
address, on some implementations passing a bad address to a routine
will result in undefined behavior.
15 ENOTBLK-
Block device required.
A non-block file was mentioned where a block device was required
(for example, in a call to the
mount routine).
16 EBUSY-
Device busy.
An attempt was made to mount a device that was already mounted or
an attempt was made to dismount a device
on which there is an active file
(open file, current directory, mounted-on file, active text segment).
It will also occur if an attempt is made to enable accounting when it is
already enabled.
The device or resource is currently unavailable.
17 EEXIST-
File exists.
An existing file was mentioned in an inappropriate context
(for example, call to the
link routine).
18 EXDEV-
Cross-device link.
A link to a file on another device
was attempted.
19 ENODEV-
No such device.
An attempt was made to apply an inappropriate
operation to a device
(for example, read a write-only device).
20 ENOTDIR-
Not a directory.
A non-directory was specified where a directory
is required
(for example, in a path prefix or
as an argument to the
chdir routine).
21 EISDIR-
Is a directory.
An attempt was made to write on a directory.
22 EINVAL-
Invalid argument.
An invalid argument was specified
(for example, unmounting a non-mounted device,
mentioning an undefined signal in a call to the
signal
or
kill routine.
Also set by the functions described in the math package (3M).
23 ENFILE-
File table overflow.
The system file table is full (that is, SYS_OPEN
files are open,
and temporarily no more files can be opened).
24 EMFILE-
Too many open files.
No process may have more than
OPEN_MAX
file descriptors open at a time.
25 ENOTTY-
Not a typewriter.
A call was made to theioctl routine specifying a file that
is not a special character device.
26 ETXTBSY-
Text file busy.
An attempt was made to execute a pure-procedure
program that is currently open for writing.
Also an attempt to open for writing or to remove a pure-procedure
program that is being executed.
27 EFBIG-
File too large.
The size of a file exceeded the maximum file size,
FCHR_MAX (see
getrlimit(2)).
28 ENOSPC-
No space left on device.
While writing an ordinary file or creating a directory entry,
there is no free space left on the device.
In thefcntl routine, the setting or removing of record locks on a file
cannot be accomplished because there are no more record entries
left on the system.
29 ESPIPE-
Illegal seek.
A call to the
lseek routine was issued to a pipe.
30 EROFS-
Read-only file system.
An attempt to modify a file or directory
was made
on a device mounted read-only.
31 EMLINK-
Too many links.
An attempt to make more than the maximum number of links,
LINK_MAX,
to a file.
32 EPIPE-
Broken pipe.
A write on a pipe for which there is no process
to read the data.
This condition normally generates a signal;
the error is returned if the signal is ignored.
33 EDOM-
Math argument out of domain of func.
The argument of a function in the math package (3M)
is out of the domain of the function.
34 ERANGE-
Math result not representable.
The value of a function in the math package (3M)
is not representable within machine precision.
35 ENOMSG-
No message of desired type.
An attempt was made to receive a message of a type not existing
on the specified message queue (see
msgop(2)).
36 EIDRM-
Identifier removed.
This error is returned to processes that resume execution due to the removal
of an identifier from the file system's name space (see
msgctl(2),
semctl(2),
and
shmctl(2)).
37 ECHRNG-
Channel number out of range.
38 EL2NSYNC-
Level 2 not synchronized.
39 EL3HLT-
Level 3 halted.
40 EL3RST-
Level 3 reset.
41 ELNRNG-
Link number out of range.
42 EUNATCH-
Protocol driver not attached.
43 ENOCSI-
No CSI structure available.
44 EL2HLT-
Level 2 halted.
45 EDEADLK-
Deadlock condition.
A deadlock situation was detected and avoided.
This error pertains to file and record locking.
46 ENOLCK-
No record locks available.
There are no more locks available.
The system lock table is full (see
fcntl(2)).
60 ENOSTR-
Device not a stream.
A
putmsg orgetmsg
system call was attempted on
a file descriptor that is not aSTREAMS device.
61 ENODATA-
No data available.
62 ETIME-
Timer expired.
The timer set for aSTREAMSioctl call has
expired.
The cause of this error is device
specific and could indicate either a hardware
or software failure, or perhaps a timeout value
that is too short for the specific operation.
The status of theioctl operation is indeterminate.
63 ENOSR-
Out of stream resources.
During a STREAMSopen, either no STREAMS queues or no
STREAMS head data structures were available.
This is a temporary condition; one may recover from it
if other processes release resources.
65 ENOPKG-
Package not installed.
This error occurs when users attempt to use
a system call from a package which has not been installed.
71 EPROTO-
Protocol error.
Some protocol error occurred. This error
is device specific, but is generally not related
to a hardware failure.
77 EBADMSG-
Not a data message.
During aread,getmsg,
orioctlI_RECVFD system call
to aSTREAMS device, something has come to the head of the queue
that cannot be processed. That something depends on the
system call:
read: control information or a passed file descriptor.
getmsg: passed file descriptor.
ioctl: control or data information.
78 ENAMETOOLONG-
File name too long.
The length of the path argument exceedsPATH_MAX, or the
length of a path component exceedsNAME_MAX while
_POSIX_NO_TRUNC is in effect; (see
limits(4)).
79 EOVERFLOW-
Value too large to be stored in data type.
80 ENOTUNIQ-
Name not unique on network.
Given log name not unique.
81 EBADFD-
File descriptor in bad state.
Either a file descriptor refers to no open file or a read request was
made to a file that is open only for writing.
82 EREMCHG-
Remote address changed.
83 ELIBACC-
Cannot access a needed shared library.
Trying toexec ana.out that requires a shared library
and the shared library doesn't exist or
the user doesn't have permission to use it.
84 ELIBBAD-
Accessing a corrupted shared library.
Trying toexec ana.out that requires a shared library
(to be linked in) andexec could not load the shared
library.
The shared library is probably corrupted.
85 ELIBSCN-
.lib section ina.out corrupted
Trying toexec ana.out that requires a shared library
(to be linked in) and there was erroneous data in the.lib
section of thea.out.
The.lib section tellsexec what shared libraries are needed.
Thea.out is probably corrupted.
86 ELIBMAX-
Attempting to link in more shared libraries than system limit.
Trying toexec ana.out that requires more static shared
libraries than is allowed on the current configuration of the system.
See
``Managing system performance''.
87 ELIBEXEC-
Cannotexec a shared library directly.
Attempting toexec a shared library directly.
88 EILSEQ-
Illegal byte sequence.
Handle multiple characters as a single character.
89 ENOSYS-
Operation not applicable.
90 ELOOP-
Number of symbolic links encountered during path name traversal exceedsMAXSYMLINKS
91 ERESTART-
Interrupted system call should be restarted.
92 ESTRPIPE-
Streams pipe error (not externally visible).
93 ENOTEMPTY-
Directory not empty.
94 EUSERS-
Too many users.
Too many users.
95 ENOTSOCK-
Socket operation on non-socket.
Self-explanatory.
96 EDESTADDRREQ-
Destination address required.
A required address was omitted from an operation on a transport endpoint.
Destination address required.
97 EMSGSIZE-
Message too long.
A message sent on a transport provider was larger than the internal message
buffer or some other network limit.
98 EPROTOTYPE-
Protocol wrong type for socket.
A protocol was specified that does not support the semantics
of the socket type requested.
99 ENOPROTOOPT-
Protocol not available.
A bad option or level was specified when getting or setting
options for a protocol.
120 EPROTONOSUPPORT-
Protocol not supported.
The protocol has not been configured into the
system or no implementation for it exists.
121 ESOCKTNOSUPPORT-
Socket type not supported.
The support for the socket type has not been configured
into the system or no implementation for it exists.
122 EOPNOTSUPP-
Operation not supported on transport endpoint.
For example, trying to accept a connection on a datagram
transport endpoint.
123 EPFNOSUPPORT-
Protocol family not supported.
The protocol family has not been configured into the system
or no implementation for it exists. Used for the Internet protocols.
124 EAFNOSUPPORT-
Address family not supported by protocol family.
An address incompatible with the requested protocol was used.
125 EADDRINUSE-
Address already in use.
User attempted to use an address already in use,
and the protocol does not allow this.
126 EADDRNOTAVAIL-
Cannot assign requested address.
Results from an attempt to create a transport endpoint with
an address not on the current machine.
127 ENETDOWN-
Network is down.
Operation encountered a dead network.
128 ENETUNREACH-
Network is unreachable.
Operation was attempted to an unreachable network.
129 ENETRESET-
Network dropped connection because of reset.
The host you were connected to crashed and rebooted.
130 ECONNABORTED-
Software caused connection abort.
A connection abort was caused internal to your host machine.
131 ECONNRESET-
Connection reset by peer.
A connection was forcibly closed by a peer.
This normally results from a loss of the connection on the remote
host due to a timeout or a reboot.
132 ENOBUFS-
No buffer space available.
An operation on a transport endpoint or pipe was not performed
because the system lacked sufficient buffer space or because a
queue was full.
133 EISCONN-
Transport endpoint is already connected.
A connect request was made on an already connected transport endpoint;
or, asendto orsendmsg request on a connected transport
endpoint specified a destination when already connected.
134 ENOTCONN-
Transport endpoint is not connected.
A request to send or receive data was disallowed because the transport
endpoint is not connected and (when sending a datagram) no address
was supplied.
143 ESHUTDOWN-
Cannot send after transport endpoint shutdown.
A request to send data was disallowed because the transport
endpoint had already been shut down.
144 ETOOMANYREFS-
Too many references: cannot splice.
145 ETIMEDOUT-
Connection timed out.
A connect or send request failed because the connected party
did not properly respond after a period of time. (The timeout
period is dependent on the communication protocol.)
146 ECONNREFUSED-
Connection refused.
No connection could be made because the target machine actively
refused it. This usually results from trying to connect to a service
that is inactive on the remote host.
147 EHOSTDOWN-
Host is down.
A transport provider operation failed because the destination host
was down.
148 EHOSTUNREACH-
No route to host.
A transport provider operation was attempted to an unreachable host.
149 EALREADY-
Operation already in progress.
An operation was attempted on a non-blocking object that already had an
operation in progress.
150 EINPROGRESS-
Operation now in progress.
An operation that takes a long time to complete (such as aconnect)
was attempted on a non-blocking object.
151 ESTALE-
Stale NFS file handle.
152 ENOLOAD-
Cannot load required module.
An attempt made to load a module failed.
153 ERELOC-
Relocation error in loading module.
Symbolic referencing error.
154 ENOMATCH-
No symbol is found matching the given spec.
156 EBADVER-
Version number mis-matched.
The version number associated with a module is not supported
by the kernel.
157 ECONFIG-
Configured kernel resource exhausted.
158 ECANCELLED-
Asynchronous I/O cancelled.
Previous topic:
BSD system calls
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004