#
# errinfo - report on syscall failures and print errno error messages.
# Written using Perl and DTrace (Solaris 10 03/05)
#
# When system calls fail, an errno variable is set to convay a meaningful
# message to the end user - so long as the program does something with it
# (eg, "ls" printing "No such file or directory"). This program fetches
# and prints details for all syscall failures along with their message,
# whether the failing program is already printing this info or not.
#
# $Id: errinfo 3 2007-08-01 10:50:08Z brendan $
#
# USAGE: errinfo [-ch] [-p PID] [-n name]
#
# -c # counts - aggregate style
# -p PID # examine this PID only
# -n name # examine processes with this name only
# eg,
# errinfo # default output - snoop event style
# errinfo -n ssh # examine "ssh" processes only
# errinfo -cn ssh # examine "ssh" using counts
#
# FIELDS:
# EXEC Program name (truncated)
# SYSCALL System call name
# ERR Value of errno
# DESC Description of errno message
#
#
# COPYRIGHT: Copyright (c) 2005, 2006 Brendan Gregg.
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License"). You may not use this file except in compliance
# with the License.
#
# See the License for the specific language governing permissions
# and limitations under the License.
#
# CDDL HEADER END
#
# Author: Brendan Gregg [Sydney, Australia]
#
# 18-Apr-2005 Brendan Gregg Created this.
# 20-Apr-2006 " " Last update.
#
#
# Defaults
#
$FILTER = "";
$COUNT = 0;
#
# Command line arguments
#
#
# Load errno descriptions
#
}
#
# Declare DTrace script
#
$dtrace = <<END;
/usr/sbin/dtrace -n '
#pragma D option quiet
syscall:::return
/errno != 0 && pid != \$pid $FILTER/
{
\@Errs[execname, probefunc, errno] = count();
}
dtrace:::END {
printa("%s %s %d %\@d\\n", \@Errs);
}'
END
} else { # snoop style
$dtrace = <<END;
/usr/sbin/dtrace -n '
#pragma D option quiet
#pragma D option switchrate=5hz
syscall:::return
/errno != 0 && pid != \$pid $FILTER/
{
printf("%s %s %d\\n", execname, probefunc, errno);
}'
END
}
#
# Cleanup on signals
#
#
# Run DTrace, process output
#
if ($COUNT) {
$header = 1;
} else {
}
### Open DTrace
### Process DTrace output
### Print count header
"EXEC","SYSCALL","ERR","COUNT","DESC");
$header = 0;
}
### Split data
### Fetch errno description
### Print output line
} else {
}
}
#
# Triggered by signals
#
}
#
# Usage message
#
print STDERR <<ENDUSAGE;
eg,
errinfo # default output - snoop event style
-c # counts - aggregate style
-p 871 # examine PID 871 only
-n ssh # examine processes with the name "ssh" only
-cn ssh # examine "ssh" using counts
ENDUSAGE
exit(1);
}