summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* print_ifindex: fix IFNAME_QUOTED_SZ definitionesyr/5.15Eugene Syromyatnikov2021-12-012-1/+5
| | | | | | | | | | | | | | | sizeof(IFNAMSIZ) instead of IFNAMSIZ was mistakenly used for IFNAME_QUOTED_SZ initial definition in commit v4.23~87 "print_ifindex: respect xlat style settings". * src/print_ifindex.c (IFNAME_QUOTED_SZ): Use IFNAMSIZ instead of sizeof(IFNAMSIZ). * NEWS: Mention it. Reported-by: Paulo Andrade <pandrade@redhat.com> Suggested-by: Paulo Andrade <pandrade@redhat.com> Fixes: v4.23~87 "print_ifindex: respect xlat style settings" References: https://bugzilla.redhat.com/show_bug.cgi?id=2028146
* tests: move keyctl syscalls of keyctl tests into a subprocessDmitry V. Levin2021-12-012-12/+32
| | | | | | | | | | | | | | | | | | | | For some mysterious reason, this helps to workaround the following resource starvation issue on some systems: $ ./keyctl >/dev/null && /bin/true -sh: fork: retry: Resource temporarily unavailable -sh: fork: retry: Resource temporarily unavailable -sh: fork: retry: Resource temporarily unavailable -sh: fork: retry: Resource temporarily unavailable -sh: fork: Resource temporarily unavailable * tests/keyctl.c: Include <sys/wait.h>. (pid): New variable. (do_keyctl): Update expected output. (main): Fork a subprocess and move all keyctl syscalls there, update expected output. * tests/gen_tests.in (keyctl, keyctl-Xabbrev, keyctl-Xraw, keyctl-Xverbose): Add options: -f --signal='!chld'.
* tests/keyctl.c: make all global variables staticDmitry V. Levin2021-12-011-2/+2
| | | | * tests/keyctl.c (nul_terminated_buf, buf_in_arg): Add static qualifier.
* Update copyright headersDmitry V. Levin2021-12-0121-20/+21
| | | | | Headers updated automatically using maint/update_copyright_years.sh script.
* Fix preprocessor indentationDmitry V. Levin2021-12-013-14/+14
| | | | | | | | | Indent the C preprocessor directives to reflect their nesting using the following script: $ cppi -l $(git grep -El '^[[:space:]]*#[[:space:]]*(if|ifdef|ifndef|elif|else|endif|define|pragma)[[:space:]]' src tests |grep -v '\.sh$') |while read f; do cppi < "$f" > "$f".cppi; mv "$f".cppi "$f" done
* Fix typos found using codespell toolDmitry V. Levin2021-12-012-2/+2
| | | | | * debian/changelog.in: Replace "archictectures" with "architectures". * tests/cur_audit_arch.h: Replace "arcitectures" with "architectures".
* tests: fix net-sockaddr test on older systemsDmitry V. Levin2021-12-011-2/+1
| | | | | | | * tests/net-sockaddr.c (check_ipx): Explicitly initialize ipx->sipx_zero before use. Fixes: v5.14-96-g8352a541f "sockaddr: print struct sockaddr_ipx.sipx_zero if it is non-zero"
* tests: robustify ioctl_hdio testsDmitry V. Levin2021-12-011-4/+6
| | | | | | * tests/ioctl_hdio.c (main): Do not assume 0xdeadbeef is an inaccessible pointer because sometimes this address is accessible, create an inaccessible pointer and use it instead of 0xdeadbeef.
* tests: disable tests for invalid msgctl and semctl commands on glibc >= 2.28Dmitry V. Levin2021-12-012-2/+12
| | | | | | | | | | | | | | | | | | | | Starting with commit glibc-2.32.9000-149-gbe9b0b9a012780a403a2, glibc skips msgctl syscall invocations and returns EINVAL for invalid msgctl commands. Likewise, starting with commit glibc-2.32.9000-147-ga16d2abd496bd974a882, glibc skips semctl syscall invocations and returns EINVAL for invalid semctl commands. These changes were later backported to vendor packages, e.g.: * Thu Mar 18 2021 Carlos O'Donell <carlos@redhat.com> - 2.28-153 - Support SEM_STAT_ANY via semctl. Return EINVAL for unknown commands to semctl, msgctl, and shmctl. (#1912670) * tests/ipc_msg.c [GLIBC_PREREQ_GE(2, 28)] (TEST_MSGCTL_BOGUS_CMD): Define to 0. * tests/ipc_sem.c [GLIBC_PREREQ_GE(2, 28)] (TEST_SEMCTL_BOGUS_CMD): Likewise.
* upoken: workaround buggy process_vm_writevDmitry V. Levin2021-12-011-5/+2
| | | | | | | | | The upoken implementation assumed that process_vm_writev could perform partial writes, but in older Linux kernel versions (my guess is in Linux before v3.15) process_vm_writev could not do partial writes properly. * src/ucopy.c (upoken): Fall back to upoken_pokedata when process_vm_writev fails with EFAULT or EIO.
* gcc_compat.h: bump required GCC version for diagnostic workaroundsEugene Syromyatnikov2021-11-301-2/+2
| | | | | | | | Diagnostic push/pop pragmas were added only in gcc 4.6. * src/gcc_compat.h [!GNUC_PREREQ(4, 6)] (DIAG_PUSH_IGNORE_OVERRIDE_INIT, DIAG_POP_IGNORE_OVERRIDE_INIT, DIAG_PUSH_IGNORE_NONNULL, DIAG_POP_IGNORE_NONNULL): Define as empty.
* sttaic_assert: disable -Wnested-externs when the fallback is usedEugene Syromyatnikov2021-11-301-0/+5
| | | | | | | | The fallback is only used with old compilers, and their diagnostics is less useful anyway. * src/static_assert.h [!HAVE_STATIC_ASSERT && !HAVE__STATIC_ASSERT && __GNUC__]: Disable "-Wnested-externs" diagnostics.
* tests/sockaddr_xlat: explicitly nest anonymous union member initialisationEugene Syromyatnikov2021-11-301-7/+11
| | | | | | | | | | | | Unfortunately, gcc 4.4.7 from RHEL 6 does not support designated initialisation of members of anonymous unions/structs without additional nesting brackets. * tests/sockaddr_xlat.c (check_ieee802154): Add curly brackets around short_addr/hwaddr field initialisation, prepend with pan_id field initialisation where needed. Complements: v5.14-167-g87ba9609f "sockaddr: implement decoding of AF_IEEE802154 socket addresses"
* socketutils: fix protocol lookup in get_sockaddr_by_inode_lookupDmitry V. Levin2021-11-301-3/+3
| | | | | | | | | | | | | | If getfdproto() fails to obtain system.sockprotoname attribute, it returns SOCK_PROTO_UNKNOWN. When this happens, get_sockaddr_by_inode_lookup() receives no hints about the protocol number and falls back to iterating over the protocols table. Apparently, it failed to implement this properly. * src/socketutils.c (get_sockaddr_by_inode_lookup): When iterating over protocols table, pass data from protocols[i] instead of protocols[SOCK_PROTO_UNKNOWN] to protocols[i].get(). Fixes: v4.25~37 "socketutils: store more information in protocols table"
* exec_or_die: fix race conditionDmitry V. Levin2021-11-291-1/+2
| | | | | * src/strace.c (exec_or_die): Repeat wait() invocation while it fails with EINTR.
* tests/count-f.c: fix race conditionDmitry V. Levin2021-11-291-1/+6
| | | | * tests/count-f.c (main): Allow waitpid() to fail with EINTR.
* tests/attach-f-p.c: fix race conditionDmitry V. Levin2021-11-291-2/+5
| | | | * tests/attach-f-p.c (thread): Allow read() to fail with EINTR.
* m4: fix st_SELINUX checkDmitry V. Levin2021-11-291-20/+16
| | | | | | | * m4/st_selinux.m4: Make sure selinux support is enabled only if all expected functions are provided by libselinux. Fixes: v5.12~49 "Implement --secontext[=full] option to display SELinux contexts"
* NEWS: mention --decode-fds={socket,dev,pidfd} behaviour fixEugene Syromyatnikov2021-11-291-0/+2
| | | | Complements: v5.14-193-g8d83c8270 "Do not decode fd path unless --decode-fds=path is specified"
* Document AT_FDCWD path decoding featureEugene Syromyatnikov2021-11-292-1/+8
| | | | | | | | * doc/strace.1.in (-e decode-fds, -y): Mention that current working directory is printed on AT_FDCWD occurrence in addition to fd path decoding. * NEWS: Mention it. Complements: v5.14-199-g48de116c2 "Print cwd path for AT_FDCWD when -y (--decode-fd=path) option is used"
* tests: check corner cases of AT_FDCWD path decodingRenaud Métrich2021-11-294-0/+109
| | | | | | | | | * tests/at_fdcwd-pathmax.c: New file. * tests/.gitignore: Add at_fdcwd-pathmax. * tests/pure_executables.list: Likewise. * tests/gen_tests.in (at_fdcwd-pathmax): New test. Co-authored-by: Dmitry V. Levin <ldv@strace.io>
* Print cwd path for AT_FDCWD when -y (--decode-fd=path) option is usedRenaud Métrich2021-11-2813-46/+147
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When syscalls use AT_FDCWD (e.g. openat()), the corresponding current working directory is not always obvious, one might need to search back for chdir() syscalls in the process or some of its parents. With this change, the current working directory corresponding to AT_FDCWD is printed when -y (--decode-fd=path) option is used, e.g.: openat(AT_FDCWD</home/rmetrich/GIT/strace>, "/lib64/libselinux.so.1" ...) * src/open.c: Include "number_set.h". (print_dirfd) <fd == AT_FDCWD>: Print the current working directory of tracee when DECODE_FD_PATH is set. * tests/dev-yy.c [!PRINT_AT_FDCWD_PATH] (PRINT_AT_FDCWD_PATH): New macro. (main): Update expected output. * tests/dev--decode-fds-all.c (PRINT_DEVNUM): New macro. Include "dev-yy.c" instead of "dev--decode-fds-dev.c". * tests/dev--decode-fds-dev.c (PRINT_AT_FDCWD_PATH): New macro. * tests/dev--decode-fds-path.c (PRINT_AT_FDCWD_PATH): Likewise. * tests/faccessat.c (AT_FDCWD_FMT, AT_FDCWD_ARG): New macros. (tests_with_existing_file, main): Update expected output. * tests/faccessat2.c (YFLAG): New macro. (main): Update expected output. * tests/fsconfig.c (test_fsconfig_set_path): Update expected output. * tests/fspick.c (main): Likewise. * tests/mount_setattr.c (main): Likewise. * tests/move_mount.c (main): Likewise. * tests/open_tree.c (main): Likewise. * tests/openat2.c (YFLAG, AT_FDCWD_FMT, AT_FDCWD_ARG): New macros. (main): Update expected output. Co-authored-by: Dmitry V. Levin <ldv@strace.io> Resolves: https://github.com/strace/strace/issues/194
* tests: fix bpf-obj_get_info_by_fd-prog-v expected outputEugene Syromyatnikov2021-11-281-1/+3
| | | | | | | | | | | Since we cannot reliably predict the value of xlated_prog_len field returned by the kernel, do not hard-code it. * tests/bpf-obj_get_info_by_fd.c (main): Print the value of the xlated_prog_len field returned by the kernel instead of hard-coding an expected value. Fixes: v5.14-46-g835c65c0e "bpf: fix bpf_prog_info.map_ids array printing"
* Make --decode-pids usage more in line with --decode-fdsEugene Syromyatnikov2021-11-283-0/+36
| | | | | | | | | | | | | | Enable -e decode-pids syntax and document it in the man page. * src/filter_qualify.c (qual_options): Add "decode-pid" and "decode-pids" that associated with qualify_decode_pid decoder. * tests/options-syntax.test: Add option syntax checks for --decode-pids and -e decode-pids. * doc/strace.1.in (.BI "\-e " expr): Document decode-pids/decode-pid as a possible argument. (.SS Output format): Document -e decode-pids/--decode-pids. Complements: v5.14-184-gbac60e6a0 "Use traditional parser for --decode-pids option"
* src/strace.c: remove Yflag_qualEugene Syromyatnikov2021-11-281-2/+1
| | | | | | | | | | It is used only once, contrary to {y,q,t}flag_qual variables. * src/strace.c (init) <Yflag_qual>: Remove. (init) <case 'Y'>: Replace Yflag_qual with "comm" in the argument to qualify_decode_pid. Complements: v5.14-180-g255a59247 "Implement -Y/--decode-pids=comm option for printing command names for PIDs"
* tests: remove ATTRIBUTE_ALLOC_SIZE from tail_alloc and tail_memdupDmitry V. Levin2021-11-283-44/+2
| | | | | | | | | | | | | | Many tests are intentionally feeding their target syscalls with garbage. Unfortunately, the compiler stands in the way, issuing tons of -Warray-bounds and -Wstringop-overread warnings when it is aware of the amount of memory allocated by tail_alloc and tail_memdup. * m4/st_broken_cc.m4: Remove. * configure.ac: Remove st_BROKEN_CC invocation. * tests/tests.h (tail_alloc, tail_memdup): Remove ATTRIBUTE_ALLOC_SIZE attribute. Resolves: https://github.com/strace/strace/issues/203
* tests: add shebang where necessaryAlex Xu (Hello71)2021-11-284-0/+4
| | | | | | | | | | | | musl does not implement the shell fallback for execvp, causing tests to fail. It is also good practice to provide a shebang anyway. * tests/qual_fault-syscall.test: Add shebang. * tests/qual_inject-error-signal-syscall.test: Likewise. * tests/qual_inject-retval-syscall.test: Likewise. * tests/qual_inject-signal-syscall.test: Likewise. Resolves: https://github.com/strace/strace/issues/202
* Do not decode fd path unless --decode-fds=path is specifiedDmitry V. Levin2021-11-2713-17/+58
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this change, --decode-fds with any argument would result to the file path corresponding to the file descriptor being printed even when the descriptor type does not match the type specified by the --decode-fds argument. After this change, the file path corresponding to the file descriptor will be printed only when --decode-fds argument is not specified or contains "path". * src/util.c (print_quoted_string_in_angle_brackets): New function. (printfd_pid): Use it to print the file path when DECODE_FD_PATH is set. * tests/dev--decode-fds-all.c: New file. * tests/dev--decode-fds-none.c: Likewise. * tests/net--decode-fds-all-netlink.c: Likewise. * tests/pidfd_open--decode-fd-all.c: Likewise. * tests/pidfd_open--decode-fd-none.c: Likewise. * tests/dev--decode-fds-socket.c: Include "dev--decode-fds-none.c" instead of "dev-yy.c". (PRINT_DEVNUM): Remove. * tests/dev-yy.c: Add PRINT_PATH support. * tests/net--decode-fds-dev-netlink.c: Include "net--decode-fds-none-netlink.c" instead of net-yy-netlink.c. (PRINT_SOCK): Remove. * tests/pidfd_open--decode-fd-socket.c: Include "pidfd_open--decode-fd-none.c" instead of "pidfd_open-y.c". * tests/.gitignore: Add dev--decode-fds-all, dev--decode-fds-none, net--decode-fds-all-netlink, pidfd_open--decode-fd-all, and pidfd_open--decode-fd-none. * tests/pure_executables.list: Likewise. * tests/gen_tests.in (dev--decode-fds-all, dev--decode-fds-none, net--decode-fds-all-netlink, pidfd_open--decode-fd-all, pidfd_open--decode-fd-none): New tests. (dev--decode-fds-socket): Update argument for -a option. (net--decode-fds-dev-netlink): Add -a option. Reported-by: Renaud Métrich <rmetrich@redhat.com> Fixes: v5.6~168 "strace: add a long option alias for -y"
* Move printing of angle brackets from printfd_pid to individual printersDmitry V. Levin2021-11-273-51/+41
| | | | | | | | | | | | | | | | This is required by the follow-up change. * src/defs.h (print_sockaddr_by_inode): Remove. * src/socketutils.c (print_sockaddr_by_inode_cached, print_sockaddr_by_inode_uncached, print_sockaddr_by_inode): Likewise. (get_sockaddr_by_inode_uncached): Rename to get_sockaddr_by_inode_lookup, implement get_sockaddr_by_inode_uncached on top of it. * src/util.c (printsocket): Rewrite using get_sockaddr_by_inode instead of print_sockaddr_by_inode, print angle brackets around the output string. (printdev, printpidfd): Print angle brackets around the output string. (printfd_pid): Do not print angle brackets around the output string.
* doc/strace.1: elaborate on support of multiple PIDs as a -p argumentEugene Syromyatnikov2021-11-251-1/+8
| | | | | | | | | | | While it was mentioned that -p "`pidof PROG`" syntax is supported, it was not explicitly stated what characters can be used as separators (like newline, which is used by pgrep, as noted in process_opt_p_list). * doc/strace.1.in (.SS Startup): Explicitly mention that multiple PIDs can be provided as an argument to a single -p option; list all supported separator characters; mention possible -p "$(pgrep PROG)" syntax.
* pidns: reorder struct translate_id_params fieldsEugene Syromyatnikov2021-11-251-7/+7
| | | | | | | | | | | Moving output fields after input ones reduces the structure size by whopping 25 percents (from 32 down to 24 bytes) on 64-bit systems, and also makes the order of the fields a bit more natural. * src/pidns.c (struct translate_id_params) <result_id, pd>: Move to the end of the structure. (translate_pid) <tip>: Reorder field initialisation in order with the field order.
* src/linux/x32/syscallent.h: add TSD flag to execve#64 and execveat#64Eugene Syromyatnikov2021-11-251-2/+2
| | | | | | | They are to be always traced with seccomp-bpf, similarly to their x32 counterparts. Fixes: v5.3~36 "Add seccomp filter syscall flag"
* tests: check diagnostics that -k has no effect with -cDmitry V. Levin2021-11-241-1/+7
| | | | * tests/options-syntax.test: Check strace -c -k diagnostics.
* Fix formatting of --decode-pids=comm outputDmitry V. Levin2021-11-233-14/+19
| | | | | | | | | | | Do not print an extra space between the pid number and the comm string when the number is less than 10000. * src/strace.c (printleader) <print_pid_pfx && len>: Print pid using %u format instead of %-5u. * tests/strace--decode-pids-comm.c (do_default_action): Update expected output. * tests/strace-p1-Y-p.c (main): Likewise.
* tests: check that -p pid1 -Y -p pid2 prints /proc/$pid1/comm properlyDmitry V. Levin2021-11-225-0/+92
| | | | | | | | | * tests/strace-p1-Y-p.c: New file. * tests/strace-p-Y-p2.c: Likewise. * tests/strace-p-Y-p.test: New test. * tests/.gitignore: Add strace-p1-Y-p and strace-p-Y-p2. * tests/Makefile.am (check_PROGRAMS): Likewise. (MISC_TESTS): Add strace-p-Y-p.test.
* Refactor printleader to reduce code duplicationDmitry V. Levin2021-11-211-31/+24
| | | | | | * src/strace.c (print_comm_str): New function. (printleader, print_pid_comm): Use it to print command names obtained from /proc/$pid/comm.
* Use traditional parser for --decode-pids optionDmitry V. Levin2021-11-207-32/+47
| | | | | | | | | | | | | | | | | | | | | | Use the same method of handling --decode-pids arguments as for other options with bitset arguments. This enables such options syntax as --decode-pids=comm,pidns and --decode-pids=all. * src/defs.h (pid_decoding, pid_decoding_flags): Remove. (maybe_printpid_comm): Rename to print_pid_comm. * src/filter_qualify.c (decode_pid_set): New variable. (decode_pid_str_to_uint): New function. (qualify_decode_pid): Rewrite using qualify_tokens. * src/filter_seccomp.c (traced_by_seccomp): Use decode_pid_set instead of pid_decoding. * src/pidns.c (printpid_translation): Likewise. * src/number_set.h (decode_pid_bits): New enum. (decode_pid_set): New variable declaration. * src/strace.c (pid_decoding): Remove. (printleader, maybe_load_task_comm, init): Use decode_pid_set instead of pid_decoding. (maybe_printpid_comm): Likewise, rename to print_pid_comm. * tests/options-syntax.test: Update expected output.
* Properly escape strings printed by -Y/--decode-pids=comm optionDmitry V. Levin2021-11-142-17/+54
| | | | | | | | | | | | | Command names obtained from /proc/$pid/comm can contain arbitrary symbols and therefore require proper escaping. * src/strace.c (printleader): Print tcp->comm using print_quoted_string_ex. (maybe_printpid_comm): Print the data obtained from load_pid_comm using print_quoted_string_ex. * tests/strace--decode-pids-comm.c (do_default_action): Check it. Resolves: https://github.com/strace/strace/issues/191
* Extend -Y option to decode PIDs in arguments and return valuesMasatake YAMATO2021-11-144-12/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | This change extends -Y/--decode-pids=comm option. In addition to the information printed before this change, command names would be printed also for PIDs appeared in syscall arguments and return values. For example: getppid() = 3781395<strace> getpid() = 3781398<a.out> pidfd_open(1<systemd>, 0) = 3<pid:1<systemd>> NOTE: The code printing the pid in printclockname() is not changed in this commit. CLOCKID_TO_FD macro used in printclockname() was removed from the kernel, so printclockname() may change drastically in the near future. * src/defs.h (maybe_printpid_comm): New function declaration. * src/strace.c (maybe_printpid_comm): New function printing command name for the given PID. * src/pidns.c (printpid_translation): Call `maybe_printpid_comm'. * tests/strace--decode-pids-comm.c (do_default_action): Update expected output. Signed-off-by: Masatake YAMATO <yamato@redhat.com> Co-authored-by: Dmitry V. Levin <ldv@strace.io>
* tests: add tests for -Y/--decode-pids=comm optionMasatake YAMATO2021-11-145-0/+110
| | | | | | | | | | | | | * tests/strace--decode-pids-comm.c: New file. * tests/strace-Y-0123456789.c: Likewise. * tests/gen_tests.in (strace-Y-0123456789, strace--decode-pids-comm): New tests. * tests/Makefile.am (CHECK_PROGRAMS): Add strace-Y-0123456789 and strace--decode-pids-comm. * tests/.gitignore: Likewise. Signed-off-by: Masatake YAMATO <yamato@redhat.com> Co-authored-by: Dmitry V. Levin <ldv@strace.io>
* Implement -Y/--decode-pids=comm option for printing command names for PIDsMasatake YAMATO2021-11-144-5/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In some applications like qemu-kvm, threads change their command names to indicate their roles in the application. Users can access the command name via /proc/$pid/comm. The command name can be a great hint to understand the application behavior. This change introduces -Y/-decode-pids=comm option that enables printing command names where PIDs appear. For example (without -Y option): [pid 254329] ioctl(18, KVM_RUN <unfinished ...> [pid 254332] ioctl(21, KVM_RUN <unfinished ...> [pid 254331] ioctl(20, KVM_RUN <unfinished ...> [pid 254330] ioctl(19, KVM_RUN <unfinished ...> [pid 254309] poll([{fd=9, events=POLLOUT}], 1, 0) = 1 ... [pid 254309] poll([{fd=9, events=POLLOUT}], 1, 0) = 1 ... (with -Y option): [pid 254329<CPU 0/KVM>] ioctl(18, KVM_RUN <unfinished ...> [pid 254332<CPU 3/KVM>] ioctl(21, KVM_RUN <unfinished ...> [pid 254331<CPU 2/KVM>] ioctl(20, KVM_RUN <unfinished ...> [pid 254330<CPU 1/KVM>] ioctl(19, KVM_RUN <unfinished ...> [pid 254309<qemu-system-x86>] poll([{fd=9, events=POLLOUT}], 1, 0) = 1 ... [pid 254309<qemu-system-x86>] poll([{fd=9, events=POLLOUT}], 1, 0) = 1 ... This change considers only PIDs in the prefixes of trace lines. Printing command names for PIDs in arguments and return values will be implemented in a follow-up commit. * doc/strace.1.in (.SS Output format): Document -Y and --decode-pids=comm options. * src/strace.c (usage): Describe -Y and --decode-pids=comm options. (printleader): Print the command name for the given tcb. (init): Add -Y/--decode-pids=comm option. Call `qualify_decode_pid' when one of the options is given. Call `maybe_load_task_comm' to handle the case the options are given after -p option. * src/filter_qualify.c (qualify_decode_pid): Set PID_DECODING_COMM and PID_DECODING_NS_TRANSLATION flags to pid_decoding if "comm" is given. * NEWS: Mention this change. Enabling PID_DECODING_NS_TRANSLATION for "comm" argument is Suggested-by: Ákos Uzonyi <uzonyi.akos@gmail.com>. Signed-off-by: Masatake YAMATO <yamato@redhat.com> Co-authored-by: Dmitry V. Levin <ldv@strace.io>
* Load /proc/$pid/comm into struct tcbMasatake YAMATO2021-11-1432-80/+137
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In preparation for the forthcoming -Y/--decode-pids=comm option. Load the content of /proc/$pid/comm to `comm', a newly introduced member of struct tcb. The loading is done when A. a tcb is initialized, B. execve or execveat is called, and C. prctl(PR_SET_NAME,...) is called. Limitation: this change is not enough for handling the case that someone writes a value to /proc/$pid/comm directly. (e.g. running echo "foo" > /proc/$pid/comm) * src/defs.h (struct tcb): New member `comm'. (enum pid_decoding_flags): Add PID_DECODING_COMM as a new flag. (PROC_COMM_LEN): New macro. (maybe_load_task_comm): New function declaration. * src/strace.c (strip_trailing_newlines): New function. (load_task_comm): New function loading the contents of /proc/$pid/comm into struct tcb.comm. (maybe_load_pid_comm): New function. (alloctcb): Call it for initializing the `comm' member. * src/syscall.c: Include <linux/prctl.h>. (syscall_exiting_decode): Call maybe_load_task_comm(). * src/sysent.h (COMM_CHANGE): New macro. * src/sysent_shorthand_defs.h (CC): Likewise. * src/sysent_shorthand_undefs.h (CC): Undefine. * src/linux/32/syscallent.h: Add CC flag to syscalls changing /proc/$pid/comm. * linux/64/syscallent.h: Likewise. * linux/alpha/syscallent.h: Likewise. * linux/arm/syscallent.h: Likewise. * linux/avr32/syscallent.h: Likewise. * linux/bfin/syscallent.h: Likewise. * linux/hppa/syscallent.h: Likewise. * linux/i386/syscallent.h: Likewise. * linux/ia64/syscallent.h: Likewise. * linux/m68k/syscallent.h: Likewise. * linux/microblaze/syscallent.h: Likewise. * linux/mips/syscallent-n32.h: Likewise. * linux/mips/syscallent-n64.h: Likewise. * linux/mips/syscallent-o32.h: Likewise. * linux/powerpc/syscallent.h: Likewise. * linux/powerpc64/syscallent.h: Likewise. * linux/s390/syscallent.h: Likewise. * linux/s390x/syscallent.h: Likewise. * linux/sh/syscallent.h: Likewise. * linux/sh64/syscallent.h: Likewise. * linux/sparc/syscallent.h: Likewise. * linux/sparc64/syscallent.h: Likewise. * linux/x32/syscallent.h: Likewise. * linux/x86_64/syscallent.h: Likewise. * linux/xtensa/syscallent.h: Likewise. * src/filter_seccomp.c (traced_by_seccomp): Force tracing syscalls marked with `COMM_CHANGE' if `PID_DECODING_COMM' flag is set in `pid_decoding'. Signed-off-by: Masatake YAMATO <yamato@redhat.com> Co-authored-by: Dmitry V. Levin <ldv@strace.io>
* Introduce --decode-pids=pidns as an alias for --pidns-translationMasatake YAMATO2021-11-148-5/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In preparation for the forthcoming -Y/--decode-pids=comm option. * doc/strace.1.in (.SS Output format): Document --decode-pids=pidns option. * src/defs.h (pidns_translation): Remove. (pid_decoding): New variable declaration. (enum pid_decoding_flags): New enum. (qualify_decode_pid): New function prototype. * src/strace.c (pidns_translation): Remove. (pid_decoding): New variable. (usage): Describe --decode-pids=pidns option. (init) <enum>: Add GETOPT_QUAL_DECODE_PID. <longopts>: Add --decode-pids as a long option. <case GETOPT_PIDNS_TRANSLATION>: Call qualify_decode_pid to update pid_decoding indirectly. <case GETOPT_QUAL_DECODE_PID>: New condition. * src/filter_qualify.c (qualify_decode_pid): New function. * src/pidns.c (printpid_translation): Refer to pid_decoding as the replacement for pidns_translation. * tests/init.sh (test_pidns_run_strace): Replace --pidns-translation with --decode-pids=pidns. * tests/options-syntax.test: Check invalid --decode-pids argument. * NEWS: Mention this change. Making --decode-pids option a super set of --pidns-translation option is Suggested-by: by Eugene Syromyatnikov <evgsyr@gmail.com>. Signed-off-by: Masatake YAMATO <yamato@redhat.com> Co-authored-by: Dmitry V. Levin <ldv@strace.io>
* Use printpid for printing pid of pidfdMasatake YAMATO2021-11-141-1/+5
| | | | | | | | * src/util.c (printpidfd): Use printfd instead of PRINT_VAL_D. Suggested-by: Ákos Uzonyi <uzonyi.akos@gmail.com> Signed-off-by: Masatake YAMATO <yamato@redhat.com>
* hdio: improve HDIO supportSrikavin Ramkumar2021-11-1310-12/+759
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add decoders for HDIO_DRIVE_RESET, HDIO_GET_32BIT, HDIO_GET_ACOUSTIC, HDIO_GET_ADDRESS, HDIO_GET_BUSSTATE, HDIO_GET_DMA, HDIO_GET_IDENTITY, HDIO_GET_KEEPSETTINGS, HDIO_GET_MULTCOUNT, HDIO_GET_NICE, HDIO_GET_NOWERR, HDIO_GET_UNMASKINTR, HDIO_GET_WCACHE, HDIO_OBSOLETE_IDENTITY, HDIO_SCAN_HWIF, HDIO_SET_32BIT, HDIO_SET_ACOUSTIC, HDIO_SET_ADDRESS, HDIO_SET_BUSSTATE, HDIO_SET_DMA, HDIO_SET_KEEPSETTINGS, HDIO_SET_MULTCOUNT, HDIO_SET_NICE, HDIO_SET_NOWERR, HDIO_SET_PIO_MODE, HDIO_SET_UNMASKINTR, HDIO_SET_WCACHE, and HDIO_UNREGISTER_HWIF. [ldv: note that HDIO compat has never been supported by the kernel, so adjust HDIO ioctl decoder and its tests accordingly.] * maint/gen/defs/hdio.def: New file. * src/gen/gen_hdio.c: New generated file. * src/gen/generated.h: Likewise. * src/Makefile.am (libstrace_a_SOURCES): Add gen/generated.h and gen/gen_hdio.c. * src/hdio.c: Include "gen/generated.h". (hdio_ioctl): Call var_ioctl_HDIO for unimplemented commands. * src/xlat/hdio_busstates.in: New file. * src/xlat/hdio_ide_nice.in: Likewise. * tests/ioctl_hdio.c: Add tests for newly implemented commands. * NEWS: Mention this change. Resolves: https://github.com/strace/strace/issues/131 Co-authored-by: Dmitry V. Levin <ldv@strace.io>
* maint/gen: use print_xint_array_member to print uint32_t arraysDmitry V. Levin2021-11-131-1/+1
| | | | | * maint/gen/defs/common.def (ptr[in, array[uint32_t, $1]]): Replace print_uint_array_member with print_xint_array_member.
* maint/gen: use printflags64 and printxval64 instead of 32-bit versionsDmitry V. Levin2021-11-131-2/+2
| | | | | | | This is necessary to print 64-bit integer types properly. * maint/gen/codegen.c (generate_printer): Use printflags64 instead of printflags, use printxval64 instead of printxval.
* maint/gen: cleanupDmitry V. Levin2021-11-1315-435/+708
| | | | | | | | | | | | | | | | | | | | | | * maint/gen/xmalloc.c: New file. * maint/gen/xmalloc.h: Likewise. * maint/gen/Makefile: Rewrite. * maint/gen/codegen.c: Add copyright header, wrap very long lines, use CLEANUP_FREE, xstrdup, and xasprintf. * maint/gen/ast.c: Add copyright header, wrap very long lines, use xstrdup. * maint/gen/ast.h: Add copyright header, wrap very long lines. * maint/gen/deflang.h: Add copyright header and include guard, wrap very long lines, add attributes to prototypes. * maint/gen/lex.l: Add copyright header, wrap very long lines, fix warnings, use xstrdup. * maint/gen/parse.y: Add copyright header, wrap very long lines, fix warnings. * maint/gen/preprocess.c: Add copyright header, wrap very long lines. * maint/gen/preprocess.h: Include "ast.h". * maint/gen/symbols.c: Wrap very long lines, use xasprintf. * maint/gen/symbols.h: Wrap very long lines. * maint/gen/defs/common.def: Add copyright header.
* maint: add a definition-based syscall decoder generatorSrikavin Ramkumar2021-11-1314-0/+3001
| | | | | | | | | | | | | | | | | | | | Implement a code generation tool capable of parsing system call definitions and generating system call decoders. * maint/gen/.gitignore: New file. * maint/gen/Makefile: Likewise. * maint/gen/README.md: Likewise. * maint/gen/ast.c: Likewise. * maint/gen/ast.h: Likewise. * maint/gen/codegen.c: Likewise. * maint/gen/deflang.h: Likewise. * maint/gen/defs/common.def: Likewise. * maint/gen/lex.l: Likewise. * maint/gen/parse.y: Likewise. * maint/gen/preprocess.c: Likewise. * maint/gen/preprocess.h: Likewise. * maint/gen/symbols.c: Likewise. * maint/gen/symbols.h: Likewise.
* rtnl_link: implement IFLA_AF_SPEC decoding for AF_BRIDGEEugene Syromyatnikov2021-11-128-13/+391
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It is special with relation to the others as it employs a completely different structure, disregarding the existing one. * src/xlat/rtnl_ifla_af_spec_bridge_attrs.in: New file. * src/xlat/rtnl_ifla_af_spec_bridge_vlan_tunnel_info_attrs.in: Likewise. * src/xlat/rtnl_ifla_bridge_flags.in: Likewise. * src/xlat/rtnl_ifla_bridge_modes.in: Likewise. * src/defs.h (nl_bridge_vlan_flags): New declaration. * src/rtnl_link.c: Include <linux/if_bridge.h>, "xlat/rtnl_ifla_af_spec_bridge_attrs.h", "xlat/rtnl_ifla_af_spec_bridge_vlan_tunnel_info_attrs.h", "xlat/rtnl_ifla_bridge_flags.h", and "xlat/rtnl_ifla_bridge_modes.h". (decode_ifla_bridge_flags, decode_ifla_bridge_mode, decode_ifla_bridge_vlan_info, decode_bridge_vlan_info_flags, decode_ifla_bridge_vlan_tunnel_info): New functions. (ifla_af_spec_bridge_vlan_tunnel_info_decoders, ifla_af_spec_bridge_nla_decoders): New decoder tables. (decode_ifla_af_spec): Add special handling for the ifi_family=AF_BRIDGE case by calling decode_nlattr directly with rtnl_ifla_af_spec_bridge_attrs and ifla_af_spec_bridge_nla_decoders. * tests/nlattr_ifla_af_spec.c: Include <linux/if_bridge.h>. (msg_af, msg_af_str): New static variables. (IFLA_AF): New macro, define to msg_af. (IFLA_AF_STR): New macro, define to msg_af_str. (init_IFLA_BRIDGE_VLAN_TUNNEL_INFO_msg, print_IFLA_BRIDGE_VLAN_TUNNEL_INFO_msg): New functions, defined via AF_SPEC_FUNCS. (main): Check unsupported IFLA_AF_SPEC address families for each ifinfomsg address family, skip AF_BRIDGE; add AF_BRIDGE IFLA_AF_SPEC checks. * NEWS: Mention it.