freebsd-skq/usr.bin/kdump/mksubr
pjd f07ebb8888 Merge Capsicum overhaul:
- Capability is no longer separate descriptor type. Now every descriptor
  has set of its own capability rights.

- The cap_new(2) system call is left, but it is no longer documented and
  should not be used in new code.

- The new syscall cap_rights_limit(2) should be used instead of
  cap_new(2), which limits capability rights of the given descriptor
  without creating a new one.

- The cap_getrights(2) syscall is renamed to cap_rights_get(2).

- If CAP_IOCTL capability right is present we can further reduce allowed
  ioctls list with the new cap_ioctls_limit(2) syscall. List of allowed
  ioctls can be retrived with cap_ioctls_get(2) syscall.

- If CAP_FCNTL capability right is present we can further reduce fcntls
  that can be used with the new cap_fcntls_limit(2) syscall and retrive
  them with cap_fcntls_get(2).

- To support ioctl and fcntl white-listing the filedesc structure was
  heavly modified.

- The audit subsystem, kdump and procstat tools were updated to
  recognize new syscalls.

- Capability rights were revised and eventhough I tried hard to provide
  backward API and ABI compatibility there are some incompatible changes
  that are described in detail below:

	CAP_CREATE old behaviour:
	- Allow for openat(2)+O_CREAT.
	- Allow for linkat(2).
	- Allow for symlinkat(2).
	CAP_CREATE new behaviour:
	- Allow for openat(2)+O_CREAT.

	Added CAP_LINKAT:
	- Allow for linkat(2). ABI: Reuses CAP_RMDIR bit.
	- Allow to be target for renameat(2).

	Added CAP_SYMLINKAT:
	- Allow for symlinkat(2).

	Removed CAP_DELETE. Old behaviour:
	- Allow for unlinkat(2) when removing non-directory object.
	- Allow to be source for renameat(2).

	Removed CAP_RMDIR. Old behaviour:
	- Allow for unlinkat(2) when removing directory.

	Added CAP_RENAMEAT:
	- Required for source directory for the renameat(2) syscall.

	Added CAP_UNLINKAT (effectively it replaces CAP_DELETE and CAP_RMDIR):
	- Allow for unlinkat(2) on any object.
	- Required if target of renameat(2) exists and will be removed by this
	  call.

	Removed CAP_MAPEXEC.

	CAP_MMAP old behaviour:
	- Allow for mmap(2) with any combination of PROT_NONE, PROT_READ and
	  PROT_WRITE.
	CAP_MMAP new behaviour:
	- Allow for mmap(2)+PROT_NONE.

	Added CAP_MMAP_R:
	- Allow for mmap(PROT_READ).
	Added CAP_MMAP_W:
	- Allow for mmap(PROT_WRITE).
	Added CAP_MMAP_X:
	- Allow for mmap(PROT_EXEC).
	Added CAP_MMAP_RW:
	- Allow for mmap(PROT_READ | PROT_WRITE).
	Added CAP_MMAP_RX:
	- Allow for mmap(PROT_READ | PROT_EXEC).
	Added CAP_MMAP_WX:
	- Allow for mmap(PROT_WRITE | PROT_EXEC).
	Added CAP_MMAP_RWX:
	- Allow for mmap(PROT_READ | PROT_WRITE | PROT_EXEC).

	Renamed CAP_MKDIR to CAP_MKDIRAT.
	Renamed CAP_MKFIFO to CAP_MKFIFOAT.
	Renamed CAP_MKNODE to CAP_MKNODEAT.

	CAP_READ old behaviour:
	- Allow pread(2).
	- Disallow read(2), readv(2) (if there is no CAP_SEEK).
	CAP_READ new behaviour:
	- Allow read(2), readv(2).
	- Disallow pread(2) (CAP_SEEK was also required).

	CAP_WRITE old behaviour:
	- Allow pwrite(2).
	- Disallow write(2), writev(2) (if there is no CAP_SEEK).
	CAP_WRITE new behaviour:
	- Allow write(2), writev(2).
	- Disallow pwrite(2) (CAP_SEEK was also required).

	Added convinient defines:

	#define	CAP_PREAD		(CAP_SEEK | CAP_READ)
	#define	CAP_PWRITE		(CAP_SEEK | CAP_WRITE)
	#define	CAP_MMAP_R		(CAP_MMAP | CAP_SEEK | CAP_READ)
	#define	CAP_MMAP_W		(CAP_MMAP | CAP_SEEK | CAP_WRITE)
	#define	CAP_MMAP_X		(CAP_MMAP | CAP_SEEK | 0x0000000000000008ULL)
	#define	CAP_MMAP_RW		(CAP_MMAP_R | CAP_MMAP_W)
	#define	CAP_MMAP_RX		(CAP_MMAP_R | CAP_MMAP_X)
	#define	CAP_MMAP_WX		(CAP_MMAP_W | CAP_MMAP_X)
	#define	CAP_MMAP_RWX		(CAP_MMAP_R | CAP_MMAP_W | CAP_MMAP_X)
	#define	CAP_RECV		CAP_READ
	#define	CAP_SEND		CAP_WRITE

	#define	CAP_SOCK_CLIENT \
		(CAP_CONNECT | CAP_GETPEERNAME | CAP_GETSOCKNAME | CAP_GETSOCKOPT | \
		 CAP_PEELOFF | CAP_RECV | CAP_SEND | CAP_SETSOCKOPT | CAP_SHUTDOWN)
	#define	CAP_SOCK_SERVER \
		(CAP_ACCEPT | CAP_BIND | CAP_GETPEERNAME | CAP_GETSOCKNAME | \
		 CAP_GETSOCKOPT | CAP_LISTEN | CAP_PEELOFF | CAP_RECV | CAP_SEND | \
		 CAP_SETSOCKOPT | CAP_SHUTDOWN)

	Added defines for backward API compatibility:

	#define	CAP_MAPEXEC		CAP_MMAP_X
	#define	CAP_DELETE		CAP_UNLINKAT
	#define	CAP_MKDIR		CAP_MKDIRAT
	#define	CAP_RMDIR		CAP_UNLINKAT
	#define	CAP_MKFIFO		CAP_MKFIFOAT
	#define	CAP_MKNOD		CAP_MKNODAT
	#define	CAP_SOCK_ALL		(CAP_SOCK_CLIENT | CAP_SOCK_SERVER)

Sponsored by:	The FreeBSD Foundation
Reviewed by:	Christoph Mallon <christoph.mallon@gmx.de>
Many aspects discussed with:	rwatson, benl, jonathan
ABI compatibility discussed with:	kib
2013-03-02 00:53:12 +00:00

554 lines
16 KiB
Bash

#!/bin/sh
#
# Copyright (c) 2006 "David Kirchner" <dpk@dpk.net>. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $FreeBSD$
#
# Generates kdump_subr.c
# mkioctls is a special-purpose script, and works fine as it is
# now, so it remains independent. The idea behind how it generates
# its list was heavily borrowed here.
#
# Some functions here are automatically generated. This can mean
# the user will see unusual kdump output or errors while building
# if the underlying .h files are changed significantly.
#
# Key:
# AUTO: Completely auto-generated with either the "or" or the "switch"
# method.
# AUTO - Special: Generated automatically, but with some extra commands
# that the auto_*_type() functions are inappropriate for.
# MANUAL: Manually entered and must therefore be manually updated.
set -e
LC_ALL=C; export LC_ALL
if [ -z "$1" ]
then
echo "usage: sh $0 include-dir"
exit 1
fi
include_dir=$1
#
# Automatically generates a C function that will print out the
# numeric input as a pipe-delimited string of the appropriate
# #define keys. ex:
# S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH
# The XOR is necessary to prevent including the "0"-value in every
# line.
#
auto_or_type () {
local name grep file
name=$1
grep=$2
file=$3
cat <<_EOF_
/* AUTO */
void
$name(intmax_t arg)
{
int or = 0;
printf("%#jx<", (uintmax_t)arg);
_EOF_
egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
$include_dir/$file | \
awk '{ for (i = 1; i <= NF; i++) \
if ($i ~ /define/) \
break; \
++i; \
printf "\tif (!((arg > 0) ^ ((%s) > 0)))\n\t\tif_print_or(arg, %s, or);\n", $i, $i }'
cat <<_EOF_
printf(">");
if (or == 0)
printf("<invalid>%jd", arg);
}
_EOF_
}
#
# Automatically generates a C function used when the argument
# maps to a single, specific #definition
#
auto_switch_type () {
local name grep file
name=$1
grep=$2
file=$3
cat <<_EOF_
/* AUTO */
void
$name(intmax_t arg)
{
switch (arg) {
_EOF_
egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
$include_dir/$file | \
awk '{ for (i = 1; i <= NF; i++) \
if ($i ~ /define/) \
break; \
++i; \
printf "\tcase %s:\n\t\tprintf(\"%s\");\n\t\tbreak;\n", $i, $i }'
cat <<_EOF_
default: /* Should not reach */
printf("<invalid=%jd>", arg);
}
}
_EOF_
}
#
# Automatically generates a C function used when the argument
# maps to a #definition
#
auto_if_type () {
local name grep file
name=$1
grep=$2
file=$3
cat <<_EOF_
/* AUTO */
void
$name(intmax_t arg)
{
_EOF_
egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
$include_dir/$file | \
awk '{ printf "\t"; \
if (NR > 1) \
printf "else " ; \
printf "if (arg == %s) \n\t\tprintf(\"%s\");\n", $2, $2 }'
cat <<_EOF_
else /* Should not reach */
printf("<invalid=%jd>", arg);
}
_EOF_
}
# C start
cat <<_EOF_
#include <stdint.h>
#include <stdio.h>
#include <sys/fcntl.h>
#include <sys/stat.h>
#include <sys/unistd.h>
#include <sys/mman.h>
#include <sys/wait.h>
#define _KERNEL
#include <sys/socket.h>
#undef _KERNEL
#include <netinet/in.h>
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/ptrace.h>
#include <sys/resource.h>
#include <sys/reboot.h>
#include <sched.h>
#include <sys/linker.h>
#define _KERNEL
#include <sys/thr.h>
#undef _KERNEL
#include <sys/extattr.h>
#include <sys/acl.h>
#include <aio.h>
#include <sys/sem.h>
#include <sys/ipc.h>
#include <sys/rtprio.h>
#include <sys/shm.h>
#include <nfsserver/nfs.h>
#include <ufs/ufs/quota.h>
#include <sys/capability.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
#include "kdump_subr.h"
/*
* These are simple support macros. print_or utilizes a variable
* defined in the calling function to track whether or not it should
* print a logical-OR character ('|') before a string. if_print_or
* simply handles the necessary "if" statement used in many lines
* of this file.
*/
#define print_or(str,orflag) do { \\
if (orflag) putchar('|'); else orflag = 1; \\
printf (str); } \\
while (0)
#define if_print_or(i,flag,orflag) do { \\
if ((i & flag) == flag) \\
print_or(#flag,orflag); } \\
while (0)
/* MANUAL */
extern char *signames[]; /* from kdump.c */
void
signame(int sig)
{
if (sig > 0 && sig < NSIG)
printf("SIG%s",signames[sig]);
else
printf("SIG %d", sig);
}
/* MANUAL */
void
semctlname(int cmd)
{
switch (cmd) {
case GETNCNT:
printf("GETNCNT");
break;
case GETPID:
printf("GETPID");
break;
case GETVAL:
printf("GETVAL");
break;
case GETALL:
printf("GETALL");
break;
case GETZCNT:
printf("GETZCNT");
break;
case SETVAL:
printf("SETVAL");
break;
case SETALL:
printf("SETALL");
break;
case IPC_RMID:
printf("IPC_RMID");
break;
case IPC_SET:
printf("IPC_SET");
break;
case IPC_STAT:
printf("IPC_STAT");
break;
default: /* Should not reach */
printf("<invalid=%d>", cmd);
}
}
/* MANUAL */
void
shmctlname(int cmd)
{
switch (cmd) {
case IPC_RMID:
printf("IPC_RMID");
break;
case IPC_SET:
printf("IPC_SET");
break;
case IPC_STAT:
printf("IPC_STAT");
break;
default: /* Should not reach */
printf("<invalid=%d>", cmd);
}
}
/* MANUAL */
void
semgetname(int flag)
{
int or = 0;
if_print_or(flag, IPC_CREAT, or);
if_print_or(flag, IPC_EXCL, or);
if_print_or(flag, SEM_R, or);
if_print_or(flag, SEM_A, or);
if_print_or(flag, (SEM_R>>3), or);
if_print_or(flag, (SEM_A>>3), or);
if_print_or(flag, (SEM_R>>6), or);
if_print_or(flag, (SEM_A>>6), or);
}
/*
* MANUAL
*
* Only used by SYS_open. Unless O_CREAT is set in flags, the
* mode argument is unused (and often bogus and misleading).
*/
void
flagsandmodename(int flags, int mode, int decimal)
{
flagsname(flags);
putchar(',');
if ((flags & O_CREAT) == O_CREAT) {
modename (mode);
} else {
if (decimal) {
printf("<unused>%d", mode);
} else {
printf("<unused>%#x", (unsigned int)mode);
}
}
}
/*
* MANUAL
*
* [g|s]etsockopt's level argument can either be SOL_SOCKET or a value
* referring to a line in /etc/protocols . It might be appropriate
* to use getprotoent(3) here.
*/
void
sockoptlevelname(int level, int decimal)
{
if (level == SOL_SOCKET) {
printf("SOL_SOCKET");
} else {
if (decimal) {
printf("%d", level);
} else {
printf("%#x", (unsigned int)level);
}
}
}
/*
* MANUAL
*
* Used for page fault type. Cannot use auto_or_type since the macro
* values contain a cast. Also, VM_PROT_NONE has to be handled specially.
*/
void
vmprotname (int type)
{
int or = 0;
if (type == VM_PROT_NONE) {
(void)printf("VM_PROT_NONE");
return;
}
if_print_or(type, VM_PROT_READ, or);
if_print_or(type, VM_PROT_WRITE, or);
if_print_or(type, VM_PROT_EXECUTE, or);
if_print_or(type, VM_PROT_COPY, or);
}
_EOF_
auto_or_type "accessmodename" "[A-Z]_OK[[:space:]]+0?x?[0-9A-Fa-f]+" "sys/unistd.h"
auto_switch_type "acltypename" "ACL_TYPE_[A-Z4_]+[[:space:]]+0x[0-9]+" "sys/acl.h"
auto_or_type "capname" "CAP_[A-Z]+[[:space:]]+0x[01248]{16}ULL" "sys/capability.h"
auto_or_type "capfcntlname" "CAP_FCNTL_[A-Z]+[[:space:]]+\(1" "sys/capability.h"
auto_switch_type "extattrctlname" "EXTATTR_NAMESPACE_[A-Z]+[[:space:]]+0x[0-9]+" "sys/extattr.h"
auto_switch_type "fadvisebehavname" "POSIX_FADV_[A-Z]+[[:space:]]+[0-9]+" "sys/fcntl.h"
auto_or_type "flagsname" "O_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/fcntl.h"
auto_or_type "flockname" "LOCK_[A-Z]+[[:space:]]+0x[0-9]+" "sys/fcntl.h"
auto_or_type "getfsstatflagsname" "MNT_[A-Z]+[[:space:]]+[1-9][0-9]*" "sys/mount.h"
auto_switch_type "kldsymcmdname" "KLDSYM_[A-Z]+[[:space:]]+[0-9]+" "sys/linker.h"
auto_switch_type "kldunloadfflagsname" "LINKER_UNLOAD_[A-Z]+[[:space:]]+[0-9]+" "sys/linker.h"
auto_switch_type "lio_listioname" "LIO_(NO)?WAIT[[:space:]]+[0-9]+" "aio.h"
auto_switch_type "madvisebehavname" "_?MADV_[A-Z]+[[:space:]]+[0-9]+" "sys/mman.h"
auto_switch_type "minheritname" "INHERIT_[A-Z]+[[:space:]]+[0-9]+" "sys/mman.h"
auto_or_type "mlockallname" "MCL_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mman.h"
auto_or_type "mmapflagsname" "MAP_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/mman.h"
auto_or_type "mmapprotname" "PROT_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/mman.h"
auto_or_type "modename" "S_[A-Z]+[[:space:]]+[0-6]{7}" "sys/stat.h"
auto_or_type "mountflagsname" "MNT_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mount.h"
auto_switch_type "msyncflagsname" "MS_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mman.h"
auto_or_type "nfssvcname" "NFSSVC_[A-Z0-9]+[[:space:]]+0x[0-9]+" "nfs/nfssvc.h"
auto_switch_type "prioname" "PRIO_[A-Z]+[[:space:]]+[0-9]" "sys/resource.h"
auto_switch_type "ptraceopname" "PT_[[:alnum:]_]+[[:space:]]+[0-9]+" "sys/ptrace.h"
auto_switch_type "quotactlname" "Q_[A-Z]+[[:space:]]+0x[0-9]+" "ufs/ufs/quota.h"
auto_or_type "rebootoptname" "RB_[A-Z]+[[:space:]]+0x[0-9]+" "sys/reboot.h"
auto_or_type "rforkname" "RF[A-Z]+[[:space:]]+\([0-9]+<<[0-9]+\)" "sys/unistd.h"
auto_switch_type "rlimitname" "RLIMIT_[A-Z]+[[:space:]]+[0-9]+" "sys/resource.h"
auto_switch_type "schedpolicyname" "SCHED_[A-Z]+[[:space:]]+[0-9]+" "sched.h"
auto_switch_type "sendfileflagsname" "SF_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h"
auto_or_type "shmatname" "SHM_[A-Z]+[[:space:]]+[0-9]{6}+" "sys/shm.h"
auto_switch_type "shutdownhowname" "SHUT_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h"
auto_switch_type "sigbuscodename" "BUS_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
auto_switch_type "sigchldcodename" "CLD_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
auto_switch_type "sigfpecodename" "FPE_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
auto_switch_type "sigprocmaskhowname" "SIG_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
auto_switch_type "sigillcodename" "ILL_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
auto_switch_type "sigsegvcodename" "SEGV_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
auto_switch_type "sigtrapcodename" "TRAP_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
auto_if_type "sockdomainname" "PF_[[:alnum:]]+[[:space:]]+" "sys/socket.h"
auto_if_type "sockfamilyname" "AF_[[:alnum:]]+[[:space:]]+" "sys/socket.h"
auto_if_type "sockipprotoname" "IPPROTO_[[:alnum:]]+[[:space:]]+" "netinet/in.h"
auto_switch_type "sockoptname" "SO_[A-Z]+[[:space:]]+0x[0-9]+" "sys/socket.h"
auto_switch_type "socktypename" "SOCK_[A-Z]+[[:space:]]+[1-9]+[0-9]*" "sys/socket.h"
auto_or_type "thrcreateflagsname" "THR_[A-Z]+[[:space:]]+0x[0-9]+" "sys/thr.h"
auto_switch_type "vmresultname" "KERN_[A-Z]+[[:space:]]+[0-9]+" "vm/vm_param.h"
auto_or_type "wait4optname" "W[A-Z]+[[:space:]]+[0-9]+" "sys/wait.h"
auto_switch_type "whencename" "SEEK_[A-Z]+[[:space:]]+[0-9]+" "sys/unistd.h"
cat <<_EOF_
/*
* AUTO - Special
* F_ is used to specify fcntl commands as well as arguments. Both sets are
* grouped in fcntl.h, and this awk script grabs the first group.
*/
void
fcntlcmdname(int cmd, int arg, int decimal)
{
switch (cmd) {
_EOF_
egrep "^#[[:space:]]*define[[:space:]]+F_[A-Z0-9_]+[[:space:]]+[0-9]+[[:space:]]*" \
$include_dir/sys/fcntl.h | \
awk 'BEGIN { o=0 } { for (i = 1; i <= NF; i++) \
if ($i ~ /define/) \
break; \
++i; \
if (o <= $(i+1)) \
printf "\tcase %s:\n\t\tprintf(\"%s\");\n\t\tbreak;\n", $i, $i; \
else \
exit; \
o = $(i+1) }'
cat <<_EOF_
default: /* Should not reach */
printf("<invalid=%d>", cmd);
}
putchar(',');
if (cmd == F_GETFD || cmd == F_SETFD) {
if (arg == FD_CLOEXEC)
printf("FD_CLOEXEC");
else if (arg == 0)
printf("0");
else {
if (decimal)
printf("<invalid>%d", arg);
else
printf("<invalid>%#x", (unsigned int)arg);
}
} else if (cmd == F_SETFL) {
flagsname(arg);
} else {
if (decimal)
printf("%d", arg);
else
printf("%#x", (unsigned int)arg);
}
}
/*
* AUTO - Special
*
* The only reason this is not fully automated is due to the
* grep -v RTP_PRIO statement. A better egrep line should
* make this capable of being a auto_switch_type() function.
*/
void
rtprioname(int func)
{
switch (func) {
_EOF_
egrep "^#[[:space:]]*define[[:space:]]+RTP_[A-Z]+[[:space:]]+0x[0-9]+[[:space:]]*" \
$include_dir/sys/rtprio.h | grep -v RTP_PRIO | \
awk '{ for (i = 1; i <= NF; i++) \
if ($i ~ /define/) \
break; \
++i; \
printf "\tcase %s:\n\t\tprintf(\"%s\");\n\t\tbreak;\n", $i, $i }'
cat <<_EOF_
default: /* Should not reach */
printf("<invalid=%d>", func);
}
}
/*
* AUTO - Special
*
* The send and recv functions have a flags argument which can be
* set to 0. There is no corresponding #define. The auto_ functions
* detect this as "invalid", which is incorrect here.
*/
void
sendrecvflagsname(int flags)
{
int or = 0;
if (flags == 0) {
printf("0");
return;
}
printf("%#x<", flags);
_EOF_
egrep "^#[[:space:]]*define[[:space:]]+MSG_[A-Z]+[[:space:]]+0x[0-9]+[[:space:]]*" $include_dir/sys/socket.h | \
awk '{ for (i = 1; i <= NF; i++) \
if ($i ~ /define/) \
break; \
++i; \
printf "\tif(!((flags>0)^((%s)>0)))\n\t\tif_print_or(flags, %s, or);\n", $i, $i }'
cat <<_EOF_
printf(">");
}
/*
* AUTO - Special
*
* Check general codes first, then defer to signal-specific codes.
*/
void
sigcodename(int sig, int code)
{
switch (code) {
_EOF_
egrep "^#[[:space:]]*define[[:space:]]+SI_[A-Z]+[[:space:]]+0(x[0-9abcdef]+)?[[:space:]]*" \
$include_dir/sys/signal.h | grep -v SI_UNDEFINED | \
awk '{ for (i = 1; i <= NF; i++) \
if ($i ~ /define/) \
break; \
++i; \
printf "\tcase %s:\n\t\tprintf(\"%s\");\n\t\tbreak;\n", $i, $i }'
cat <<_EOF_
default:
switch (sig) {
case SIGILL:
sigillcodename(code);
break;
case SIGBUS:
sigbuscodename(code);
break;
case SIGSEGV:
sigsegvcodename(code);
break;
case SIGFPE:
sigfpecodename(code);
break;
case SIGTRAP:
sigtrapcodename(code);
break;
case SIGCHLD:
sigchldcodename(code);
break;
default:
printf("<invalid=%#x>", code);
}
}
}