mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-23 11:18:54 +00:00
c04743dac1
ioctlname() to return a pointer to the name rather than print it. This did not show up in testing because truss had its own prototype for ioctlname(), so it would build fine and run fine as long as the program being traced did not issue an ioctl. Teach mkioctls to generate different versions of ioctlname() based on its first command-line argument. Pointed out by: Garrett Cooper <yanegomi@gmail.com>
114 lines
2.5 KiB
Bash
114 lines
2.5 KiB
Bash
#!/bin/sh
|
|
#
|
|
# $FreeBSD$
|
|
#
|
|
# When editing this script, keep in mind that truss also uses it.
|
|
#
|
|
|
|
set -e
|
|
|
|
if [ $# -ne 2 -o \( $1 != "print" -a $1 != "return" \) ]; then
|
|
echo "usage: sh $0 print|return include-dir"
|
|
exit 1
|
|
fi
|
|
|
|
style="$1"
|
|
includedir="$2"
|
|
|
|
LC_ALL=C; export LC_ALL
|
|
|
|
# Build a list of headers that have ioctls in them.
|
|
# XXX should we use an ANSI cpp?
|
|
ioctl_includes=$(
|
|
cd $includedir
|
|
find -H -s * -name '*.h' | grep -v '.*disk.*\.h' | \
|
|
xargs egrep -l \
|
|
'^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO[^a-z0-9_]' |
|
|
awk '{printf("#include <%s>\\n", $1)}'
|
|
)
|
|
|
|
: ${MACHINE=$(uname -m)}
|
|
case "${MACHINE}" in
|
|
*pc98*)
|
|
ioctl_includes="$ioctl_includes#include <sys/diskpc98.h>\\n"
|
|
;;
|
|
*)
|
|
ioctl_includes="$ioctl_includes#include <sys/diskmbr.h>\\n"
|
|
;;
|
|
esac
|
|
|
|
awk -v x="$ioctl_includes" 'BEGIN {print x}' |
|
|
gcc -E -I$1 -dM -DCOMPAT_43TTY - |
|
|
awk -v ioctl_includes="$ioctl_includes" -v style="$style" '
|
|
BEGIN {
|
|
print "/* XXX obnoxious prerequisites. */"
|
|
print "#define COMPAT_43"
|
|
print "#define COMPAT_43TTY"
|
|
print "#include <sys/param.h>"
|
|
print "#include <sys/devicestat.h>"
|
|
print "#include <sys/disklabel.h>"
|
|
print "#include <sys/socket.h>"
|
|
print "#include <sys/time.h>"
|
|
print "#include <sys/tty.h>"
|
|
print "#include <bsm/audit.h>"
|
|
print "#include <net/ethernet.h>"
|
|
print "#include <net/if.h>"
|
|
print "#include <net/if_var.h>"
|
|
print "#include <net/pfvar.h>"
|
|
print "#include <net/route.h>"
|
|
print "#include <netinet/in.h>"
|
|
print "#include <netinet/ip_mroute.h>"
|
|
print "#include <netinet6/in6_var.h>"
|
|
print "#include <netinet6/nd6.h>"
|
|
print "#include <netinet6/ip6_mroute.h>"
|
|
print "#include <stdio.h>"
|
|
print "#include <cam/cam.h>"
|
|
print ""
|
|
print ioctl_includes
|
|
print ""
|
|
if (style == "print") {
|
|
print "void ioctlname(unsigned long val, int decimal);"
|
|
print ""
|
|
print "void"
|
|
print "ioctlname(unsigned long val, int decimal)"
|
|
} else {
|
|
print "const char *ioctlname(unsigned long val);"
|
|
print ""
|
|
print "const char *"
|
|
print "ioctlname(unsigned long val)"
|
|
}
|
|
print "{"
|
|
print "\tconst char *str = NULL;"
|
|
print ""
|
|
}
|
|
|
|
/^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO/ {
|
|
|
|
# find where the name starts
|
|
for (i = 1; i <= NF; i++)
|
|
if ($i ~ /define/)
|
|
break;
|
|
++i;
|
|
#
|
|
printf("\t");
|
|
if (n++ > 0)
|
|
printf("else ");
|
|
printf("if (val == %s)\n", $i);
|
|
printf("\t\tstr = \"%s\";\n", $i);
|
|
}
|
|
END {
|
|
print ""
|
|
if (style == "print") {
|
|
print "\tif (str != NULL)"
|
|
print "\t\tprintf(\"%s\", str);"
|
|
print "\telse if (decimal)"
|
|
print "\t\tprintf(\"%lu\", val);"
|
|
print "\telse"
|
|
print "\t\tprintf(\"%#lx\", val);"
|
|
} else {
|
|
print "\treturn (str);"
|
|
}
|
|
print "}"
|
|
}
|
|
'
|