strace.c: use *_func_* message printing macros where appropriate
In order to provide some additional bits of information in weird error
cases or just replace existing usages of __func__/literal function name.
* strace.c (detach): Use perror_func_msg() instead of perror_msg().
(startup_attach, open_dummy_desc, startup_child, test_ptrace_seize): Use
perror_func_msg_and_die() instead of perror_msg_and_die().
(test_ptrace_seize): Use error_func_msg_and_die() instead of
error_msg_and_die().
An error returned by asprintf is a poor excuse for dying.
* unwind.c (asprintf_error_str): New string constant.
(sprint_call_or_error): Replace error_msg_and_die() with
perror_func_msg() and usage of asprintf_error_str for a return value.
(queue_print): Free tmp->output line only if it is not
asprintf_error_str.
Since DPRINTF is simply a macro that provides debugging information
along with some information about printing routine call site, now standard
debug_func_* macros are deemed to be a suitable replacement.
strace.c: replace if (debug_flag) ... with suitable debug printing macros
* strace.c (alloc_tcb, droptcb, detach, attach_tcb, test_ptrace_seize,
init, startup_tcb): Replace if (debug_flag) error_msg(...) occurrences
with debug_error_msg(...).
(attach_tcb): Replace if (debug_flag) perror_msg(...) with
debug_perror_msg(...).
(cleanup, startup_tcb): Replace if (debug_flag) error_msg(...)
occurrences with debug_func_msg() in attempt to provide additional
information.
* defs.h (debug_flag): Move the declaration...
* error_prints.h (debug_flag): ... here.
(debug_msg, debug_perror_msg): New macro definitions.
Include <stdbool.h> for the debug_flag declaration.
Masatake YAMATO [Mon, 4 Dec 2017 13:08:14 +0000 (22:08 +0900)]
kvm: decode the argument of KVM_SET_USER_MEMORY_REGION ioctl command
* configure.ac (AC_CHECK_TYPES): Add struct kvm_userspace_memory_region.
* xlat/kvm_mem_flags.in: New file.
* kvm.c: Include print_fields.h.
[HAVE_STRUCT_KVM_USERSPACE_MEMORY_REGION]: Include xlat/kvm_mem_flags.h,
(kvm_ioctl_set_user_memory_region): New function.
(kvm_ioctl) [HAVE_STRUCT_KVM_USERSPACE_MEMORY_REGION]
<KVM_SET_USER_MEMORY_REGION>: Use it.
Dmitry V. Levin [Sun, 3 Dec 2017 00:25:43 +0000 (00:25 +0000)]
tests: robustify attach-p-cmd.test against buggy kernels
From time to time various kernels, old and new, just go nuts
and fail attach-p-cmd.test with the following diagnostics:
12345 --- SIGALRM {si_signo=SIGALRM, si_code=SI_KERNEL} ---
-12345 chdir("attach-p-cmd.test -p") = -1 ENOENT (No such file or directory)
+12345 syscall_4294967295(0xffe60934, 0x1c0, 0xffe60934, 0x1, 0xffe609b4, 0xffe60a58) = -1 (errno 38)
+12345 chdir("attach-p-cmd.test -p") = -1 ENOSYS (Function not implemented)
Let's workaround this kernel madness by rewriting the test
without use of SIGALRM.
* tests/attach-p-cmd.h: New file.
* tests/Makefile.am (EXTRA_DIST): Add attach-p-cmd.h.
* tests/attach-p-cmd-cmd.c: Include "attach-p-cmd.h".
(write_pidfile, wait_for_peer_invocation): New functions.
(main): Use them.
* tests/attach-p-cmd-p.c: Include <time.h> and "attach-p-cmd.h".
(wait_for_peer_invocation, wait_for_peer_termination): New functions.
(main): Use them. Do not raise SIGALRM, use nanosleep after peer
termination.
Dmitry V. Levin [Sat, 2 Dec 2017 22:01:34 +0000 (22:01 +0000)]
tests: robustify ipc_msgbuf.test against broken libc
glibc between commits glibc-2.25~130 and glibc-2.26~740 had broken
msgctl(IPC_RMID) on hppa: this operation always failed with EINVAL
because of inappropriate use of IPC_64 flag. Similar issues were
fixed on other niche architectures. Let's workaround these issues
by skipping the test in case of msgctl(IPC_RMID) failure.
* tests/ipc_msgbuf.c (cleanup): Change return type to int,
return 77 in case of msgctl(IPC_RMID) failure.
(main): Explicitly invoke cleanup() at the end.
strace-log-merge: work around corner cases of strace -ttt parsing
Employing strace -ttt for the logs destined to be fed to
strace-log-merge is ultimately the best solution except for the logs
that pass the following dates:
Thu Jan 1 00:00:09 UTC 1970
Thu Jan 1 00:01:39 UTC 1970
Thu Jan 1 00:16:39 UTC 1970
Thu Jan 1 02:46:39 UTC 1970
Fri Jan 2 03:46:39 UTC 1970
Mon Jan 12 13:46:39 UTC 1970
Sun Apr 26 17:46:39 UTC 1970
Sat Mar 3 09:46:39 UTC 1973
Sun Sep 9 01:46:39 UTC 2001
Sat Nov 20 17:46:39 UTC 2286
Wed Nov 16 09:46:39 UTC 5138
Fri Sep 27 01:46:39 UTC 33658
Sun May 20 17:46:39 UTC 318857
Sat Nov 7 09:46:39 UTC 3170843
Sun Jul 5 01:46:39 UTC 31690708
Sat Jan 25 17:46:39 UTC 316889355
Let's lift this limitation.
* strace-log-merge: Generate numeric-only key for sorting, use sort -n
option.
Dmitry V. Levin [Sat, 25 Nov 2017 01:55:44 +0000 (01:55 +0000)]
mpers: fix cross-compiling
In cross builds, a target version of readelf has to be used
instead of a native one.
* configure.ac (AC_CHECK_TOOL): Add readelf.
* Makefile.am (READELF): New variable.
(mpers-m%.stamp): Pass it to $(srcdir)/mpers.sh.
* m4/mpers.m4 (st_MPERS): Pass READELF environment variable
to $srcdir/mpers_test.sh.
* mpers.sh (READELF): New variable.
Use it instead of readelf.
* maint/ioctls_sym.sh: Likewise.
* NEWS: Mention this fix.
Dmitry V. Levin [Wed, 22 Nov 2017 00:14:52 +0000 (00:14 +0000)]
tests: simplify bpf test a bit
* tests/bpf.c (DEF_BPF_INIT_FIRST): New macro.
(init_BPF_MAP_CREATE_first, init_BPF_MAP_LOOKUP_ELEM_first,
init_BPF_PROG_LOAD_first, init_BPF_OBJ_PIN_first,
init_BPF_PROG_ATTACH_first, init_BPF_PROG_TEST_RUN_first,
init_BPF_PROG_GET_NEXT_ID_first, init_BPF_OBJ_GET_INFO_BY_FD_first):
Use it.
Dmitry V. Levin [Tue, 21 Nov 2017 22:32:31 +0000 (22:32 +0000)]
Simplify union bpf_attr field checks
* configure.ac: Use AC_CHECK_MEMBERS instead of st_CHECK_UNION_BPF_ATTR
for union bpf_attr field checks as the former seems to be enough
for the case.
* m4/st_bpf.m4: Remove.
Dmitry V. Levin [Mon, 20 Nov 2017 00:29:10 +0000 (00:29 +0000)]
Implement decoding of BPF_PROG_TEST_RUN command of bpf syscall
* configure.ac: Check for union bpf_attr.test.duration.
* bpf.c (decode_BPF_PROG_TEST_RUN): New function.
(SYS_FUNC(bpf)) <bpf_cmd_decoders>: Use it.
* NEWS: Mention this.
* tests/bpf.c: Include "print_fields.h".
Add macro guard for BPF_PROG_TEST_RUN decoder test.
[HAVE_UNION_BPF_ATTR_TEST_DURATION] (sample_BPF_PROG_TEST_RUN_attr):
New variable.
[HAVE_UNION_BPF_ATTR_TEST_DURATION] (init_BPF_PROG_TEST_RUN_first,
print_BPF_PROG_TEST_RUN_first, init_BPF_PROG_TEST_RUN_attr,
print_BPF_PROG_TEST_RUN_attr): New functions.
(main) [HAVE_UNION_BPF_ATTR_TEST_DURATION]: Use them.
Dmitry V. Levin [Sun, 19 Nov 2017 23:38:58 +0000 (23:38 +0000)]
bpf: update BPF_MAP_CREATE decoding
Implement decoding of union bpf_attr.numa_node field for BPF_MAP_CREATE
command introduced by linux kernel commit v4.14-rc1~130^2~196^2~1.
* configure.ac: Check for numa_node member of union bpf_attr
instead of inner_map_fd.
(decode_BPF_MAP_CREATE): Add numa_node field to the structure, print it.
* NEWS: Mention this.
* tests/bpf.c: Update macro guards of BPF_MAP_CREATE decoder test.
(init_BPF_MAP_CREATE_first, print_BPF_MAP_CREATE_attr): Update expected
output.
(init_BPF_MAP_CREATE_attr): Initialize numa_node field, update offset.
Dmitry V. Levin [Fri, 17 Nov 2017 11:26:55 +0000 (11:26 +0000)]
Provide fallback definitions for SHM_EXEC constant
Although SHM_EXEC is available in <linux/shm.h> since kernel commit
v2.6.9-rc2~23^2~93^2~78, the glibc version of <sys/shm.h> did not
provide SHM_EXEC until commit glibc-2.10~238.
NETLINK_LIST_MEMBERSHIPS, unlike all other SOL_NETLINK options, requests
not just a single integer but an array of integers. The kernel also
supports a zero optlen NETLINK_LIST_MEMBERSHIPS request.
* net.c (print_uint32): New function.
(print_getsockopt): Add ulen argument, rename len argument to rlen,
<SOL_NETLINK> Handle NETLINK_LIST_MEMBERSHIPS using print_array
and print_uint32.
(SYS_FUNC(getsockopt)): Pass ulen to print_getsockopt.
* tests/sockopt-sol_netlink.c (main): Check NETLINK_LIST_MEMBERSHIPS
decoding.
Dmitry V. Levin [Thu, 16 Nov 2017 00:12:46 +0000 (00:12 +0000)]
net: fix decoding of optval argument of [gs]etsockopt SOL_NETLINK
Tweak the parser to follow the kernel behaviour.
* net.c (print_getsockopt, print_setsockopt) <SOL_NETLINK>: Fetch and
print returned value as integer iff the length is >= sizeof(int),
otherwise print the address.
* NEWS: Mention this.
Dmitry V. Levin [Wed, 15 Nov 2017 16:36:21 +0000 (16:36 +0000)]
net: decode optname argument of [gs]etsockopt for SOL_NETLINK level
* xlat/socknetlinkoptions.in: New file.
* net.c: Include "xlat/socknetlinkoptions.h".
(print_sockopt_fd_level_name) <SOL_NETLINK>: Print name using
socknetlinkoptions.
* NEWS: Metnion this.
* maint/update_copyright_years.sh (MAX_JOBS): New variable, initialize
it to double the CPU count.
<while [ -n "${1:-}" ]; do case "$1" in>: Add -j option parsing.
(jobs, pids): New variables.
<git ls-files -- "$@" | grep -vFx "$IGNORED_FILES" | while read f; do>:
Execute process_file in background, count background jobs and wait
if there are too many.
maint: make gen-contributors-list.sh suitable for generation of CREDITS
Implement various features in order to make it suitable for the
generation of the CREDITS file:
- add an option for including contributor e-mail;
- add an option to read additional list of contributors from stdin;
- add shorthand for referring to the initial commit of the branch;
- document all of the above in a help message.
* maint/gen-contributors-list.sh (print_help): New function.
(script): Rename to SCRIPT.
(SCRIPT_NORM_EMAILS, MATCH_OUT, OUT_EMAILS, OUT_NO_EMAILS, read_stdin,
include_email): New variables.
Add parsing of options, rewrite input processing.
This commit implements the following changes:
- increases the number of concurrent jobs to twice the CPU count;
- creates a circular buffer, so instead of running multiple jobs
at once, the generator tries to keep about the same number of jobs
being run concurrently;
- runs gen_git and gen_make concurrently in order to squeeze in
one more bit of concurrency.
With my deeply scientific measurements, this approach achieves
up to 15% speedup with dash and about 30-40% with bash as /bin/sh
on a 4-core machine.
* xlat/gen.sh (main): Declare pids local variable, append pid of every
run job to it; increase the limit of jobs to ncpus * 2; when the limit
is reached, wait for the first pid in pids instead of resetting jobs
to zero and waiting for all the run jobs; put gen_git and gen_make
into background.
tests: update futex test to accommodate the recent kernel change
Kernel commit v4.14-rc1~162^2~8 refactored futex implementation and
introduced checks for invalid shift sizes. Accommodate this change
by allowing EINVAL in the corresponding futex checks.
* tests/futex.c (CHECK_FUTEX_GENERIC): Reset errno before the syscall.
(main) <wake_ops>: Add err2 field, describe err/err2 fields.
Add EINVAL as a possible errno to the checks that contain invalid
shift values.
Update return value check so it checks that values are strictly
as expected.