[PATCH] net: add more sockopt options
Mike Frysinger
vapier at gentoo.org
Sun Feb 16 07:24:47 UTC 2014
On Wednesday, February 05, 2014 06:40:05 Dmitry V. Levin wrote:
> On Fri, Jan 31, 2014 at 01:27:14AM -0500, Mike Frysinger wrote:
> > On Thursday, January 30, 2014 22:13:29 Mike Frysinger wrote:
> > > what would help i think with maintaining these files is a little macro
> > > that
> > >
> > > i use in other projects of mine:
> > > #define Q(x) { x, #x },
> > >
> > > then the lists become:
> > > static const struct xlat domains[] = {
> > > Q(PF_UNSPEC)
> > > Q(PF_LOCAL)
> > > Q(PF_UNIX)
> > > ...
> > > };
> >
> > blah i'm dumb and forgot about the #ifdef part. it's still a bit cleaner
> > though:
> >
> > --- a/mem.c
> > +++ b/mem.c
> >
> > static const struct xlat mmap_prot[] = {
> >
> > - { PROT_NONE, "PROT_NONE", },
> > - { PROT_READ, "PROT_READ" },
> > - { PROT_WRITE, "PROT_WRITE" },
> > - { PROT_EXEC, "PROT_EXEC" },
> > + XLAT(PROT_NONE),
> > + XLAT(PROT_NONE),
> > + XLAT(PROT_READ),
> > + XLAT(PROT_WRITE),
> > + XLAT(PROT_EXEC),
>
> I've automatically converted most of xlat structures to this XLAT form.
looks great. the ifdef stuff still annoys me. we can't really define
fallbacks to random values since any value is possible with these things.
what if we created like .xlat.in files ? a script would take care of
generating the full contents. see the crazy idea below.
-mike
From f1bfe7571a2d1b9eca6018e585348080baf4adcb Mon Sep 17 00:00:00 2001
From: Mike Frysinger <vapier at gentoo.org>
Date: Sun, 16 Feb 2014 01:59:20 -0500
Subject: [PATCH] generate xlat structs
---
Makefile.am | 6 ++
bootstrap | 3 +
net.c | 254
+------------------------------------------------------
xlat/addrfams.in | 41 +++++++++
xlat/domains.in | 41 +++++++++
xlat/gen.sh | 96 +++++++++++++++++++++
6 files changed, 189 insertions(+), 252 deletions(-)
create mode 100755 bootstrap
create mode 100644 xlat/addrfams.in
create mode 100644 xlat/domains.in
create mode 100755 xlat/gen.sh
diff --git a/Makefile.am b/Makefile.am
index a9d2ff0..65cc52b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -14,6 +14,8 @@ ACLOCAL_AMFLAGS = -I m4
AM_CFLAGS = $(WARN_CFLAGS)
AM_CPPFLAGS = -I$(srcdir)/$(OS)/$(ARCH) -I$(srcdir)/$(OS) -I$(builddir)/$(OS)
+include xlat/Makemodule.am
+
strace_SOURCES = \
aio.c \
bjm.c \
@@ -213,6 +215,9 @@ EXTRA_DIST = \
strace-log-merge \
strace.spec \
syscallent.sh \
+ $(XLAT_INPUT_FILES) \
+ $(XLAT_HEADER_FILES) \
+ xlat/gen.sh \
xlate.el
.PHONY: srpm
@@ -226,6 +231,7 @@ $(srcdir)/.version:
dist-hook:
$(AM_V_GEN)echo $(VERSION) > $(distdir)/.tarball-version
+ $(AM_V_GEN)$(distdir)/xlat/gen.sh
today = $(shell date +%Y-%m-%d)
version_regexp = $(subst .,\.,$(VERSION))
diff --git a/bootstrap b/bootstrap
new file mode 100755
index 0000000..196d8e4
--- /dev/null
+++ b/bootstrap
@@ -0,0 +1,3 @@
+#!/bin/sh
+./xlat/gen.sh
+exec autoreconf -f -i
diff --git a/net.c b/net.c
index f09d1dd..a772df0 100644
--- a/net.c
+++ b/net.c
@@ -94,258 +94,8 @@
# define PF_UNSPEC AF_UNSPEC
#endif
-static const struct xlat domains[] = {
-#ifdef PF_UNSPEC
- XLAT(PF_UNSPEC),
-#endif
-#ifdef PF_LOCAL
- XLAT(PF_LOCAL),
-#endif
-#ifdef PF_UNIX
- XLAT(PF_UNIX),
-#endif
-#ifdef PF_INET
- XLAT(PF_INET),
-#endif
-#ifdef PF_AX25
- XLAT(PF_AX25),
-#endif
-#ifdef PF_IPX
- XLAT(PF_IPX),
-#endif
-#ifdef PF_APPLETALK
- XLAT(PF_APPLETALK),
-#endif
-#ifdef PF_NETROM
- XLAT(PF_NETROM),
-#endif
-#ifdef PF_BRIDGE
- XLAT(PF_BRIDGE),
-#endif
-#ifdef PF_ATMPVC
- XLAT(PF_ATMPVC),
-#endif
-#ifdef PF_X25
- XLAT(PF_X25),
-#endif
-#ifdef PF_INET6
- XLAT(PF_INET6),
-#endif
-#ifdef PF_ROSE
- XLAT(PF_ROSE),
-#endif
-#ifdef PF_DECnet
- XLAT(PF_DECnet),
-#endif
-#ifdef PF_NETBEUI
- XLAT(PF_NETBEUI),
-#endif
-#ifdef PF_SECURITY
- XLAT(PF_SECURITY),
-#endif
-#ifdef PF_KEY
- XLAT(PF_KEY),
-#endif
-#ifdef PF_NETLINK
- XLAT(PF_NETLINK),
-#endif
-#ifdef PF_ROUTE
- XLAT(PF_ROUTE),
-#endif
-#ifdef PF_PACKET
- XLAT(PF_PACKET),
-#endif
-#ifdef PF_ASH
- XLAT(PF_ASH),
-#endif
-#ifdef PF_ECONET
- XLAT(PF_ECONET),
-#endif
-#ifdef PF_ATMSVC
- XLAT(PF_ATMSVC),
-#endif
-#ifdef PF_RDS
- XLAT(PF_RDS),
-#endif
-#ifdef PF_SNA
- XLAT(PF_SNA),
-#endif
-#ifdef PF_IRDA
- XLAT(PF_IRDA),
-#endif
-#ifdef PF_PPPOX
- XLAT(PF_PPPOX),
-#endif
-#ifdef PF_WANPIPE
- XLAT(PF_WANPIPE),
-#endif
-#ifdef PF_LLC
- XLAT(PF_LLC),
-#endif
-#ifdef PF_CAN
- XLAT(PF_CAN),
-#endif
-#ifdef PF_TIPC
- XLAT(PF_TIPC),
-#endif
-#ifdef PF_BLUETOOTH
- XLAT(PF_BLUETOOTH),
-#endif
-#ifdef PF_IUCV
- XLAT(PF_IUCV),
-#endif
-#ifdef PF_RXRPC
- XLAT(PF_RXRPC),
-#endif
-#ifdef PF_ISDN
- XLAT(PF_ISDN),
-#endif
-#ifdef PF_PHONET
- XLAT(PF_PHONET),
-#endif
-#ifdef PF_IEEE802154
- XLAT(PF_IEEE802154),
-#endif
-#ifdef PF_CAIF
- XLAT(PF_CAIF),
-#endif
-#ifdef PF_ALG
- XLAT(PF_ALG),
-#endif
-#ifdef PF_NFC
- XLAT(PF_NFC),
-#endif
-#ifdef PF_VSOCK
- XLAT(PF_VSOCK),
-#endif
- XLAT_END
-};
-const struct xlat addrfams[] = {
-#ifdef AF_UNSPEC
- XLAT(AF_UNSPEC),
-#endif
-#ifdef AF_LOCAL
- XLAT(AF_LOCAL),
-#endif
-#ifdef AF_UNIX
- XLAT(AF_UNIX),
-#endif
-#ifdef AF_INET
- XLAT(AF_INET),
-#endif
-#ifdef AF_AX25
- XLAT(AF_AX25),
-#endif
-#ifdef AF_IPX
- XLAT(AF_IPX),
-#endif
-#ifdef AF_APPLETALK
- XLAT(AF_APPLETALK),
-#endif
-#ifdef AF_NETROM
- XLAT(AF_NETROM),
-#endif
-#ifdef AF_BRIDGE
- XLAT(AF_BRIDGE),
-#endif
-#ifdef AF_ATMPVC
- XLAT(AF_ATMPVC),
-#endif
-#ifdef AF_X25
- XLAT(AF_X25),
-#endif
-#ifdef AF_INET6
- XLAT(AF_INET6),
-#endif
-#ifdef AF_ROSE
- XLAT(AF_ROSE),
-#endif
-#ifdef AF_DECnet
- XLAT(AF_DECnet),
-#endif
-#ifdef AF_NETBEUI
- XLAT(AF_NETBEUI),
-#endif
-#ifdef AF_SECURITY
- XLAT(AF_SECURITY),
-#endif
-#ifdef AF_KEY
- XLAT(AF_KEY),
-#endif
-#ifdef AF_NETLINK
- XLAT(AF_NETLINK),
-#endif
-#ifdef AF_ROUTE
- XLAT(AF_ROUTE),
-#endif
-#ifdef AF_PACKET
- XLAT(AF_PACKET),
-#endif
-#ifdef AF_ASH
- XLAT(AF_ASH),
-#endif
-#ifdef AF_ECONET
- XLAT(AF_ECONET),
-#endif
-#ifdef AF_ATMSVC
- XLAT(AF_ATMSVC),
-#endif
-#ifdef AF_RDS
- XLAT(AF_RDS),
-#endif
-#ifdef AF_SNA
- XLAT(AF_SNA),
-#endif
-#ifdef AF_IRDA
- XLAT(AF_IRDA),
-#endif
-#ifdef AF_PPPOX
- XLAT(AF_PPPOX),
-#endif
-#ifdef AF_WANPIPE
- XLAT(AF_WANPIPE),
-#endif
-#ifdef AF_LLC
- XLAT(AF_LLC),
-#endif
-#ifdef AF_CAN
- XLAT(AF_CAN),
-#endif
-#ifdef AF_TIPC
- XLAT(AF_TIPC),
-#endif
-#ifdef AF_BLUETOOTH
- XLAT(AF_BLUETOOTH),
-#endif
-#ifdef AF_IUCV
- XLAT(AF_IUCV),
-#endif
-#ifdef AF_RXRPC
- XLAT(AF_RXRPC),
-#endif
-#ifdef AF_ISDN
- XLAT(AF_ISDN),
-#endif
-#ifdef AF_PHONET
- XLAT(AF_PHONET),
-#endif
-#ifdef AF_IEEE802154
- XLAT(AF_IEEE802154),
-#endif
-#ifdef AF_CAIF
- XLAT(AF_CAIF),
-#endif
-#ifdef AF_ALG
- XLAT(AF_ALG),
-#endif
-#ifdef AF_NFC
- XLAT(AF_NFC),
-#endif
-#ifdef AF_VSOCK
- XLAT(AF_VSOCK),
-#endif
- XLAT_END
-};
+#include "xlat/domains.h"
+#include "xlat/addrfams.h"
static const struct xlat socktypes[] = {
XLAT(SOCK_STREAM),
XLAT(SOCK_DGRAM),
diff --git a/xlat/addrfams.in b/xlat/addrfams.in
new file mode 100644
index 0000000..a869574
--- /dev/null
+++ b/xlat/addrfams.in
@@ -0,0 +1,41 @@
+AF_UNSPEC
+AF_LOCAL
+AF_UNIX
+AF_INET
+AF_AX25
+AF_IPX
+AF_APPLETALK
+AF_NETROM
+AF_BRIDGE
+AF_ATMPVC
+AF_X25
+AF_INET6
+AF_ROSE
+AF_DECnet
+AF_NETBEUI
+AF_SECURITY
+AF_KEY
+AF_NETLINK
+AF_ROUTE
+AF_PACKET
+AF_ASH
+AF_ECONET
+AF_ATMSVC
+AF_RDS
+AF_SNA
+AF_IRDA
+AF_PPPOX
+AF_WANPIPE
+AF_LLC
+AF_CAN
+AF_TIPC
+AF_BLUETOOTH
+AF_IUCV
+AF_RXRPC
+AF_ISDN
+AF_PHONET
+AF_IEEE802154
+AF_CAIF
+AF_ALG
+AF_NFC
+AF_VSOCK
diff --git a/xlat/domains.in b/xlat/domains.in
new file mode 100644
index 0000000..bb216ba
--- /dev/null
+++ b/xlat/domains.in
@@ -0,0 +1,41 @@
+PF_UNSPEC
+PF_LOCAL
+PF_UNIX
+PF_INET
+PF_AX25
+PF_IPX
+PF_APPLETALK
+PF_NETROM
+PF_BRIDGE
+PF_ATMPVC
+PF_X25
+PF_INET6
+PF_ROSE
+PF_DECnet
+PF_NETBEUI
+PF_SECURITY
+PF_KEY
+PF_NETLINK
+PF_ROUTE
+PF_PACKET
+PF_ASH
+PF_ECONET
+PF_ATMSVC
+PF_RDS
+PF_SNA
+PF_IRDA
+PF_PPPOX
+PF_WANPIPE
+PF_LLC
+PF_CAN
+PF_TIPC
+PF_BLUETOOTH
+PF_IUCV
+PF_RXRPC
+PF_ISDN
+PF_PHONET
+PF_IEEE802154
+PF_CAIF
+PF_ALG
+PF_NFC
+PF_VSOCK
diff --git a/xlat/gen.sh b/xlat/gen.sh
new file mode 100755
index 0000000..781b88b
--- /dev/null
+++ b/xlat/gen.sh
@@ -0,0 +1,96 @@
+#!/bin/sh
+
+usage() {
+ cat <<EOF
+Usage: $0 <input> <output>
+
+Generate xlat header files from <input> (a file or dir of files) and write
+the generated headers to <output>.
+EOF
+ exit 1
+}
+
+gen_header() {
+ local input="$1" output="$2" name="$3"
+ local line
+ echo "generating ${output}"
+ (
+ echo "/* Generated by $0 from $1; do not edit. */"
+ echo "const struct xlat ${name}[] = {"
+ while read line ; do
+ case ${line} in
+ "/"|"#"|"")
+ echo "${line}"
+ ;;
+ *)
+ echo "#ifdef ${line}"
+ echo " XLAT(${line}),"
+ echo "#endif"
+ ;;
+ esac
+ done < "${input}"
+ echo " XLAT_END"
+ echo "};"
+ ) >"${output}"
+}
+
+gen_make() {
+ local output="$1"
+ local name
+ shift
+ echo "generating ${output}"
+ (
+ printf "XLAT_INPUT_FILES = "
+ printf 'xlat/%s.in ' "$@"
+ echo
+ printf "XLAT_HEADER_FILES = "
+ printf 'xlat/%s.h ' "$@"
+ echo
+ for name; do
+ printf '$(top_srcdir)/xlat/%s.h: $(top_srcdir)/xlat/%s.in
$(top_srcdir)/xlat/gen.sh\n' \
+ "${name}" "${name}"
+ echo ' $(AM_V_GEN)$(top_srcdir)/xlat/gen.sh $< $@'
+ done
+ ) >"${output}"
+}
+
+gen_git() {
+ local output="$1"
+ shift
+ echo "generating ${output}"
+ (
+ printf '/%s\n' .gitignore Makemodule.am
+ printf '/%s.h\n' "$@"
+ ) >"${output}"
+}
+
+main() {
+ case $# in
+ 0) set -- "${0%/*}" "${0%/*}" ;;
+ 2) ;;
+ *) usage ;;
+ esac
+
+ local input="$1"
+ local output="$2"
+ local name
+
+ if [ -d "${input}" ]; then
+ local f name names
+ for f in "${input}"/*.in; do
+ name=${f##*/}
+ name=${name%.in}
+ gen_header "${f}" "${output}/${name}.h" "${name}" &
+ names="${names} ${name}"
+ done
+ gen_git "${output}/.gitignore" ${names}
+ gen_make "${output}/Makemodule.am" ${names}
+ wait
+ else
+ name=${input##*/}
+ name=${name%.in}
+ gen_header "${input}" "${output}" "${name}"
+ fi
+}
+
+main "$@"
--
1.8.5.5
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20140216/5e50831b/attachment.bin>
More information about the Strace-devel
mailing list