Errno Libretto

By Hal Stern, Unix Insider |  Operating Systems

huey% man -s 2 intro

It explains the possible error values and associates them with the
cryptic error messages like "address already in use" printed by the
perror() library routine. The descriptions aren't
exhaustive and some of the errors are entirely non-obvious. Once you
have a feel for the target, examine the routine in question (in this
case, probproc) using trace or truss:

huey% truss -o /tmp/tr.out probproc -a -X -i90

truss dumps its output into the file named by the
-o option. trace, the SunOS 4.1.x
equivalent, doesn't follow forks or trace child processes, but
truss will chase down a thread of execution until it has
exited. Every system call is shown in the truss output,
along with the arguments passed (or at least the first few bytes of
them), the return value, and the value of errno, if it was set. Here's
an edited truss spiel from an attempt to list a
non-existent file:

execve("/usr/bin/ls", 0xEFFFFAE0, 0xEFFFFAEC)  argc = 2
open("/usr/lib/libintl.so.1", O_RDONLY, 035737754720) = 3
ioctl(1, TIOCGWINSZ, 0x00024C84)		Err#22 EINVAL
lstat("xyz", 0xEFFFF9A8)			Err#2 ENOENT
_exit(2)

Note that the process opens up the internationalization library,
libintl.so.1, a good hint that it was linked with
-lintl. ls attempts to get the current
window size using the TIOCGWINSZ ioctl(), but gets an
"invalid argument" because the example was generated on a dial-in line,
not a shelltool or xterm. Searching for the
file information on "xyz" returns a "file not found" error, which is
printed by ls on its way to a non-zero exit.

Understanding errno isn't purely a serious business. One of the more
popular contests at USENIX conferences has been creating new errno names.

Link dink post-shrink

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Answers - Powered by ITworld

ITworld Answers helps you solve problems and share expertise. Ask a question or take a crack at answering the new questions below.

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Ask a Question
randomness