Dmitry V. Levin [Wed, 14 Jun 2017 23:32:45 +0000 (23:32 +0000)]
netlink: refactor decode_nlmsg_type
* netlink.c (decode_nlmsg_type_default, decode_nlmsg_type_netfilter):
New functions.
(nlmsg_types_decoder_t): New typedef.
(nlmsg_types): Add decoder field.
(decode_nlmsg_type): Use it.
Dmitry V. Levin [Tue, 13 Jun 2017 21:00:04 +0000 (21:00 +0000)]
v4l2: fix preprocessor checks
Fix checks for struct v4l2_window.global_alpha and struct
v4l2_sdr_format.buffersize.
* v4l2.c (print_v4l2_format_fmt): Do not assume that
HAVE_STRUCT_V4L2_WINDOW_GLOBAL_ALPHA and
HAVE_STRUCT_V4L2_SDR_FORMAT_BUFFERSIZE are defined.
* tests/ioctl_v4l2.c (init_v4l2_format, dprint_ioctl_v4l2): Likewise.
Masatake YAMATO [Sun, 11 Jun 2017 07:42:28 +0000 (16:42 +0900)]
socketeutils: extend receive_responses further
This is the second patch in series of implementing NETLINK_GENERIC
protocol decoder.
This change allows passing of opaque user data to the callback function.
* socketutils.c (receive_responses): Change the type of proto_name
argument from "const char *" to "void *" to allow passing
of arbitrary data to the callback function.
Rename proto_name to opaque_data, make it the last argument.
Pass it to the callback function as the last argument.
(inet_parse_response, unix_parse_response, netlink_parse_response):
Change the type of proto_name argument from "const char *" to "void *",
rename it to opaque_data, make it the last argument.
Introduce a local variable proto_name to convert the type
of opaque_data argument from "void *" to "const char *".
(unix_get, inet_get, netlink_get): Cast the protocol name from
"const char *" to "void *" for passing to the callback function.
Signed-off-by: Masatake YAMATO <yamato@redhat.com> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
JingPiao Chen [Wed, 7 Jun 2017 15:35:19 +0000 (23:35 +0800)]
tests: add check for decoding netlink get and new flags
* tests/netlink_route.c (test_nlmsg_flags): New function, checks
decoding of NETLINK_ROUTE get and new flags.
(main): Use it.
* tests/netlink_sock_diag.c (test_nlmsg_flags): New function, checks
decoding of NETLINK_SOCK_DIAG get flags.
(main): Use it.
* tests/netlink_xfrm.c: (test_nlmsg_flags): New function, checks
decoding of NETLINK_XFRM get and new flags.
(main): Use it.
JingPiao Chen [Thu, 8 Jun 2017 01:02:22 +0000 (09:02 +0800)]
netlink: implement generic nlmsg_flags decoding
* netlink.c: Include "xlat/netlink_get_flags.h"
and "xlat/netlink_new_flags.h".
(decode_nlmsg_flags): New function.
(print_nlmsghdr): Use it.
* xlat/netlink_get_flags.in: New file.
* xlat/netlink_new_flags.in: Likewise.
Co-authored-by: Fabien Siron <fabien.siron@epita.fr> Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
This change removes the trace_syscall function. Now, the code that uses
syscall.c trace functions is expected to check whether it is a syscall
entry or exit (with entering(tcp)/exiting(tcp)) itself, and then make
an appropriate sequence of function calls.
* defs.h: Update comment on TCB_INSYSCALL.
(trace_syscall): Remove prototype.
(syscall_entering_decode, syscall_entering_trace,
syscall_entering_finish, syscall_exiting_decode, syscall_exiting_trace,
syscall_exiting_finish): New prototypes.
* strace.c (trace_syscall): New static replacement for old trace_syscall.
* syscall.c (trace_syscall): Remove.
(trace_syscall_entering): Split into ...
(syscall_entering_decode, syscall_entering_trace,
syscall_entering_finish): ... new functions.
(trace_syscall_exiting): Split into ...
(syscall_exiting_decode, syscall_exiting_trace,
syscall_exiting_finish): ... new functions.
* tests/tests.h (create_nl_socket): Rename to create_nl_socket_ext,
add a string argument.
(create_nl_socket): New macro wrapper around create_nl_socket_ext.
* tests/create_nl_socket.c (create_nl_socket): Rename
to create_nl_socket_ext, add a string argument, include it
in diagnostic messages.
Dmitry V. Levin [Sat, 3 Jun 2017 23:19:49 +0000 (23:19 +0000)]
netlink: implement generic nlmsg_type decoding
Implement a pluggable mechanism of nlmsg_type decoding.
Add decoding of NETLINK_SOCK_DIAG types.
* linux/sock_diag.h (SOCK_DESTROY): New macro.
* xlat/nl_sock_diag_types.in: New file.
* netlink.c: Include xlat/nl_sock_diag_types.h.
(get_fd_nl_family, decode_nlmsg_type): New functions.
(print_nlmsghdr): Use them for nlmsg_type decoding.
Dmitry V. Levin [Sat, 3 Jun 2017 22:56:32 +0000 (22:56 +0000)]
netlink: add netlink family argument to printers and decoders
* netlink.c (NL_FAMILY_ERROR, NL_FAMILY_DEFAULT): New constants.
(print_nlmsghdr): Add netlink family argument, change return type
to int, return family.
(decode_nlmsghdr_with_payload, decode_nlmsgerr, decode_payload): Add
netlink family argument. All callers updated.
Fabien Siron [Wed, 22 Jun 2016 13:51:49 +0000 (13:51 +0000)]
socketutils.c: introduce cache_inode_details
cache_inode_details gives a way to obtain cache information without
printing it.
* socketutils.c (cache_and_print_inode_details): Rename
to cache_inode_details. Do not print cached information.
(inet_parse_response, unix_parse_response, netlink_parse_response):
Use cache_inode_details instead of cache_and_print_inode_details.
(inet_print, unix_print, netlink_print): Call
print_sockaddr_by_inode_cached.
Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
Dmitry V. Levin [Sun, 4 Jun 2017 17:03:44 +0000 (17:03 +0000)]
Move netlink_protocols definition from net.c to netlink.c
The side effect of #include "xlat/netlink_protocols.h" is
NETLINK_* constants properly defined in that header file.
While net.c does not use these constants itself, netlink.c
is going to need them soon.
JingPiao Chen [Fri, 5 May 2017 10:21:17 +0000 (18:21 +0800)]
netlink: decode NLMSG_DONE messages
* netlink.c (decode_payload): Decode NLMSG_DONE messages.
* tests/netlink_protocol.c (test_nlmsg_done): New function
for checking decoding of NLMSG_DONE messages.
(main): Use it.
Dmitry V. Levin [Sat, 3 Jun 2017 17:52:24 +0000 (17:52 +0000)]
Unexport print_sockaddr_by_inode_cached
Change print_sockaddr_by_inode to be the only function exposed,
hide print_sockaddr_by_inode_cached as a part of implementation.
* defs.h (print_sockaddr_by_inode_cached): Remove prototype.
(print_sockaddr_by_inode): Add struct tcb * and descriptor arguments.
* socketutils.c (print_sockaddr_by_inode_cached): Make static.
(print_sockaddr_by_inode): Rename to print_sockaddr_by_inode_uncached,
make static.
(print_sockaddr_by_inode): New function.
* util.c (printfd): Update to use new print_sockaddr_by_inode.
This change decouples waiting for next event from reacting to it. This
makes the control flow easier to understand, and serves as a preparation
for implementing a pull-style API for LuaJIT.
* strace.c (enum trace_event): New enum.
(trace): Split into ...
(next_event, dispatch_event): ... new functions.
(main): Use them.
Dmitry V. Levin [Sat, 27 May 2017 18:58:31 +0000 (18:58 +0000)]
Enable coverage when strace is self terminated by signal
The data collected by -fprofile-arcs during program run is saved
on program exit. When program is terminated by signal, the data
is not saved. However, libgcov provides an interface to dump
the data at runtime.
* m4/ax_code_coverage.m4 (AX_CODE_COVERAGE): Add -DENABLE_COVERAGE_GCOV
to CODE_COVERAGE_CPPFLAGS.
* strace.c [ENABLE_COVERAGE_GCOV] (__gcov_flush): New prototype.
(main) [ENABLE_COVERAGE_GCOV]: Call __gcov_flush() before raise()
and sigprocmask() calls that might cause program termination.
Dmitry V. Levin [Sat, 27 May 2017 15:58:54 +0000 (15:58 +0000)]
Do not reset SIGCHLD handler in tracees to SIG_DFL
While strace resets SIGCHLD handler to the default action so that
waitpid definitely works without losing track of children, tracees
should not inherit this change.
* strace.c (struct exec_params): Add child_sa field.
(init): When setting SIGCHLD handler to SIG_DFL, save the old handler.
(exec_or_die): Restore SIGCHLD handler if it was different from SIG_DFL
at startup.
* NEWS: Mention this change.
Dmitry V. Levin [Sat, 27 May 2017 10:00:43 +0000 (10:00 +0000)]
Fix unblocking of signals in interactive mode
In interactive mode (-I2), those signals that were blocked at startup
will remain blocked for the whole period of strace execution.
* strace.c (empty_set): Rename to start_set. All users changed.
(init): Initialize start_set and blocked_set to the set of currently
blocked signals.
(startup_attach, trace): Use SIG_SETMASK instead of SIG_BLOCK.
* NEWS: Mention this change.
Dmitry V. Levin [Mon, 22 May 2017 10:48:13 +0000 (10:48 +0000)]
Fix decoding of sgetmask and ssetmask syscalls
Old ssetmask syscall takes an argument and returns a value of type int.
Old sgetmask syscall may return an error.
* signal.c (SYS_FUNC(ssetmask)): Explicitly convert the argument
and return value to unsigned int, print it using sprint_old_sigmask_val.
(SYS_FUNC(sgetmask)): Do not print the mask in case of syserror.
* tests/sxetmask.c: New file.
* tests/gen_tests.in (sxetmask): New entry.
* tests/pure_executables.list: Add sxetmask.
* tests/.gitignore: Likewise.
* NEWS: Mention this fix.
On some architectures old sigsuspend syscall takes the signal mask from
the 3rd argument, on some from the 1st. And, if it wasn't peculiar
enough, the signal mask is passed by value on all architectures except
mips where it's passed by reference.
* signal.c (SYS_FUNC(sigsuspend)): Take the signal mask from the last
argument.
* linux/alpha/syscallent.h (sigsuspend): Set nargs to 1.
* linux/crisv10/syscallent.h: Likewise.
* linux/mips/syscallent-o32.h: Likewise.
* linux/powerpc/syscallent.h: Likewise.
* linux/powerpc64/syscallent.h: Likewise.
* linux/sh/syscallent.h: Likewise.
* linux/sh64/syscallent.h: Likewise.
* linux/sparc/syscallent.h: Likewise.
* linux/sparc64/syscallent.h: Likewise.
* tests/sigsuspend.c: New file.
* tests/gen_tests.in (sigsuspend): New entry.
* tests/pure_executables.list: Add sigsuspend.
* tests/.gitignore: Likewise.
* NEWS: Mention this fix.
Recently added tests based on pure_executables.list are quite slow
by their nature, the one minute default timeout is no longer enough
for some of not so fast architectures.
* tests/init.sh (TIMEOUT_DURATION): Raise from 60 to 120.
* v4l2.c: Include "xlat/v4l2_tuner_types.h", "xlat/v4l2_tuner_capabilities.h",
"xlat/v4l2_tuner_rxsubchanses.h", and "xlat/v4l2_tuner_audmodes.h".
(print_v4l2_tuner): New function. Add decoding for VIDIOC_G/S_TUNER's arg.
(v4l2_ioctl): Add new cases for decoding VIDIOC_G/S_TUNER's arg.
* xlat/v4l2_tuner_types.in: Add V4L2_TUNER_RADIO and
V4L2_TUNER_ANALOG_TV introduced by linux kernel commit
2.5.46~39^2~23^2~4.
Add V4L2_TUNER_DIGITAL_TV introduced by linux kernel
commit v2.6.11-rc4~55^2~20.
Add V4L2_TUNER_ADC and V4L2_TUNER_RF introduced by linux kernel commit
v3.15-rc1~85^2~215.
Add V4L2_TUNER_SDR introduced by linux kernel commit v4.4-rc1~118^2~17
(as the replacement of V4L2_TUNER_ADC).
* xlat/v4l2_tuner_capabilities.in: Add V4L2_TUNER_CAP_LOW,
V4L2_TUNER_CAP_NORM, V4L2_TUNER_CAP_STEREO, V4L2_TUNER_CAP_LANG2,
V4L2_TUNER_CAP_SAP, and V4L2_TUNER_CAP_LANG1 introduced by linux kernel
commit 2.5.46~39^2~23^2~4.
Add V4L2_TUNER_CAP_HWSEEK_BOUNDED and V4L2_TUNER_CAP_HWSEEK_WRAP
introduced by linux kernel commit v3.6-rc1~28^2~306.
Add V4L2_TUNER_CAP_RDS introduced by linux commit v2.6.32-rc1~679^2~189.
Add V4L2_TUNER_CAP_RDS_BLOCK_IO and V4L2_TUNER_CAP_RDS_CONTROLS
introduced by linux kernel commit v2.6.37-rc1~64^2~110.
Add V4L2_TUNER_CAP_FREQ_BANDS introduced by linux kernel commit
v3.6-rc1~28^2~46.
Add V4L2_TUNER_CAP_HWSEEK_PROG_LIM introduced by linux kernel commit
v3.6-rc1~28^2~40.
Add V4L2_TUNER_CAP_1HZ introduced by linux kernel commit
v3.15-rc1~85^2~214.
* xlat/v4l2_tuner_audmodes.in: Add V4L2_TUNER_MODE_MONO,
V4L2_TUNER_MODE_STEREO, V4L2_TUNER_MODE_LANG2, V4L2_TUNER_MODE_SAP, and
V4L2_TUNER_MODE_LANG1 introduced by linux kernel commit
2.5.46~39^2~23^2~4.
Add V4L2_TUNER_MODE_LANG1_LANG2 introduced by linux kernel commit
v2.6.17-rc1~739^2~9.
* xlat/v4l2_tuner_rxsubchanses.in: Add V4L2_TUNER_SUB_MONO,
V4L2_TUNER_SUB_STEREO, V4L2_TUNER_SUB_LANG2, V4L2_TUNER_SUB_SAP, and
V4L2_TUNER_SUB_LANG1 introduced by linux kernel commit
2.5.46~39^2~23^2~4.
Add V4L2_TUNER_SUB_RDS introduced by linux kernel commit
v2.6.32-rc1~679^2~189.