Commit Graph

3637 Commits

Author SHA1 Message Date
591906cccb waitid: print pid argument as int
* wait.c (SYS_FUNC(waitid)): As the type of second syscall argument
in the kernel is pid_t, print it as int.
2016-02-11 03:06:17 +00:00
d3f17c642d waitid: always print 5th argument
* wait.c (SYS_FUNC(waitid)): Do not check for tcp->s_ent->nargs
as waitid syscall has 5 arguments.
2016-02-11 03:06:17 +00:00
ea21823d27 socketutils: add const qualifier to variables
* socketutils.c (cache_and_print_inode_details): Make "details"
parameter const.
(print_sockaddr_by_inode_cached): Make "e" variable const.
(inet_send_query): Make struct nlmsghdr and struct inet_diag_req_v2
members const.  Make "msg" variable const.
(inet_parse_response): Make "data" parameter and diag_msg variable const.
(receive_responses): Make "h" and "rc" variables const.
(unix_send_query): Make struct nlmsghdr and struct unix_diag_req
members const.  Make "msg" variable const.
(unix_print): Make all parameters const.
(print_sockaddr_by_inode): Make proto_name parameter const.
2016-02-11 03:06:17 +00:00
bcf5975a3e print_sockaddr_by_inode: cleanup protocol lookup
* socketutils.c (tcp_v4_print, udp_v4_print, tcp_v6_print,
udp_v6_print): New functions.
(print_sockaddr_by_inode): Make "protocols" array static, replace
"family" and "protocol" members with "print" in its underlying
structure.  Iterate through protocols array when the protocol name
is specified.
2016-02-11 03:06:17 +00:00
6204654329 tests: check that -f -p attaches to threads properly
Check that -f -p attaches and follows all threads of the given pid.

* tests/attach-f-p.c: New file.
* tests/attach-f-p.test: New test.
* tests/.gitignore: Add attach-f-p.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(attach_f_p_LDADD): New variable.
(TESTS): Add attach-f-p.test.
2016-02-09 05:08:00 +00:00
6ca4c92c1b Introduce libstrace.a for potentially conditional compilation units
Some files are used conditionally depending on architecture and
configuration.  Create a library for the purpose of keeping such
compilation units.

* Makefile.am (strace_LDADD, noinst_LIBRARIES): Add libstrace.a.
(libstrace_a_CPPFLAGS): New variable, set to $(strace_CPPFLAGS).
(libstrace_a_CFLAGS): New variable, set to $(strace_CFLAGS).
(libstrace_a_SOURCES): New variable, set to upeek.c.
* util.c (upeek): Move ...
* upeek.c: ... here.
2016-02-09 05:08:00 +00:00
0acd8d0ec3 travis-ci: pass more gcov arguments to codecov 2016-02-08 18:35:16 +00:00
b1b692eb23 tests: extend coverage of struct itimerspec
* tests/timer_xettime.c (main): Check decoding of NULL struct itimerspec
pointer.
2016-02-08 18:28:36 +00:00
9ee77b9e65 tests: extend coverage of utimensat syscall
* tests/utimensat.c (main): Check decoding of NULL struct timespec
pointer.
2016-02-08 18:27:59 +00:00
c736b456ad tests: extend coverage of time syscall
* tests/time.c (main): Check decoding of NULL time_t pointer.
2016-02-08 18:27:17 +00:00
595fc10f11 tests: extend coverage of struct sigevent
* tests/timer_create.c (main): Check decoding of NULL struct sigevent
pointer.  Check decoding of invalid sigev_notify value.
2016-02-08 18:26:46 +00:00
23168c1e54 tests: extend coverage of execve and execveat syscalls
Check decoding of inaccessible or partially inaccessible arrays.

* tests/execve-v.c: New file.
* tests/execveat-v.c: Likewise.
* tests/execve-v.test: New test.
* tests/execveat-v.test: Likewise.
* tests/execve.c: Rewrite.
* tests/execveat.c: Likewise.
* tests/execve.test: Likewise.
* tests/execveat.test: Likewise.
* tests/execve.expected: Remove.
* tests/execve-v.expected: Likewise.
* tests/execveat.expected: Likewise.
* tests/execveat-v.expected: Likewise.
* tests/.gitignore: Add execve-v and execveat-v.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(TESTS): Add execve-v.test and execveat-v.test.
(EXTRA_DIST): Remove execve.expected, execve-v.expected,
execveat.expected, and execveat-v.expected.
2016-02-08 18:25:33 +00:00
3c00e63b03 Fix decoding of execve and execveat syscalls with invalid input
* execve.c (printargv): Fix decoding of inaccessible or partially
inaccessible array.
(printargc): Diagnose inaccessible or partially inaccessible array.
(decode_execve, SYS_FUNC(execv)): Update printargv and printargc callers.
2016-02-08 18:21:31 +00:00
a59fcec4c9 tests: extend coverage of capget syscall
* tests/caps.c (main): Check decoding of inaccessible cap_user_header_t
and/or cap_user_data_t.
* tests/caps.awk: Update match patterns.
* tests/caps.test: Update.
2016-02-08 18:21:10 +00:00
48d97b6a83 tests: extend coverage of sched_getaffinity syscall
* tests/sched_xetaffinity.c (main): Check decoding of pointer
to inaccessible cpu_set_t.
2016-02-08 18:18:51 +00:00
f2e6f3d3c4 tests: extend coverage of utime syscall
* tests/utime.c (main): Check decoding of NULL struct utimbuf pointer.
Check decoding of struct utimbuf located at the end of page boundary.
* tests/utime.test: Update.
2016-02-08 18:18:05 +00:00
b5a7011d71 tests: extend coverage of sysinfo syscall
* tests/sysinfo.c (main): Check decoding of NULL struct sysinfo pointer.
Check decoding of struct sysinfo located at the end of page boundary.
* tests/sysinfo.test: Update.
2016-02-08 18:17:28 +00:00
7fce7c0332 tests: extend coverage of adjtimex syscall
* tests/adjtimex.c (main): Check decoding of NULL struct timex pointer.
Check decoding of struct timex located at the end of page boundary.
* tests/adjtimex.test: Update.
2016-02-08 18:16:27 +00:00
a88c72ef66 tests: check that strace does not retain stdin and stdout descriptors
* tests/redirect.test: New test.
* tests/Makefile.am (TESTS): Add it.
2016-02-08 17:51:18 +00:00
6aedd42206 Create a dummy pipe descriptor instead of opening /dev/null
* strace.c (open_dev_null): Rename to open_dummy_desc.  All callers
changed.  Create a pipe and return its first descriptor instead of
opening /dev/null.
2016-02-08 17:51:18 +00:00
Denys Vlasenko
0736d4e1a3 If stdin/stdout aren't open on startup, open them to /dev/null
Otherwise, -oLOGFILE may end up using one of them. This conflicts
with the previous change, which closes stdin/out in strace.

* strace.c (init): If fcntl(F_GETFD) fails on stdin or stdout,
sanitize them: open /dev/null and dup it until fds 0,1,2
are all used up.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2016-02-08 18:17:38 +01:00
Denys Vlasenko
c9f85b3876 Close stdin/out after child is forked
Testcase:

{ sleep 1; yes | head -n99999; } | strace -o/dev/null sh -c 'exec <&-; sleep 9'

The writer (head) will be able to perform writes to write end of the pipe.
With strace call removed, head will immediately get SIGPIPE.

This change fixes this: now writer immediately gets SIGPIPE with strace too.

* strace.c (startup_child): Close stdin/out and reopen them to /dev/null.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
2016-02-08 18:17:38 +01:00
7469e252fa tests: add opipe.test
Check that -o |pipe_command works.  In particular, check that
strace waits for completion of piped command.

* tests/opipe.test: New test.
* tests/Makefile.am (TESTS): Add it.
2016-02-05 14:58:41 +00:00
Keith Owens
320fb41682 strace-graph: print the pid in the graph
* strace-graph: Prefix each command with its pid.
2016-02-05 00:41:23 +00:00
Keith Owens
7e0ba4bdcc strace-graph: cope with clone immediately followed by exit
* strace-graph: A clone() followed by exit() with no intervening fork
or execve resulted in the new pid having no seq key.  That breaks when
trying to use seq as an array reference.  Ensure that clone populates
the new pid with an empty seq entry.
2016-02-05 00:41:23 +00:00
Keith Owens
ef445b5daf strace-graph: handle recent strace output
* strace-graph: Fix regex for --SIG.  Ignore '+++ exited with <n> +++'
lines.  Handle exit_group syscall as well as _exit.
2016-02-05 00:41:23 +00:00
Keith Owens
dbc1ffb2a4 strace-graph: handle strace -T
* strace-graph: Ignore extra ' <time.spent>' field added by strace -T.
2016-02-05 00:41:23 +00:00
Keith Owens
a0bc25f085 strace-graph: use "strict" and "warnings" pragmas
* strace-graph: Set "use strict" and "use warnings" options.  Fix errors
detected by strict/warnings.  $result is really a string, it can be "-1"
followed by an error text.
2016-02-05 00:41:23 +00:00
26ed70b252 Add README.md file with links to build status and test coverage 2016-02-04 18:20:14 +00:00
5be488c3a5 travis-ci: prepare and submit test coverage report 2016-02-04 17:04:13 +00:00
d8a81dfa40 tests: extend readlink and readlinkat coverage
* tests/readlink.c (PREFIX, TARGET, LINKPATH): New macros.
(main): Allocate memory for string and buffer passed to the syscall
being tested using tail_alloc mechanism.  Create and cleanup test
symlink.  Test syscall error path output.  Print hexquoted strings
using hexquote_strndup.
* tests/readlinkat.c: Likewise.
* tests/readlink.test: Remove creation and cleanup of test symlinks.
2016-02-04 03:36:25 +00:00
7637b1d9e8 tests: add hexquote_strndup function to libtests
* tests/tests.h (hexquote_strndup): New prototype.
* tests/hexquote_strndup.c: New file.
* tests/Makefile.am (libtests_a_SOURCES): Add it.
2016-02-04 03:36:25 +00:00
f2eb27c73e readlinkat.test: use readlink.test
* tests/readlink.test (syscall): Initialize from $0.
* tests/readlinkat.test: Source readlink.test.
2016-02-04 03:36:25 +00:00
Gabriel Laskar
cba67108a0 Add configure --enable-code-coverage option
* m4/ax_code_coverage.m4: New file.
* configure.ac: Use AX_CODE_COVERAGE.
* Makefile.am: Add @CODE_COVERAGE_RULES@.
(CODE_COVERAGE_LCOV_OPTIONS, CODE_COVERAGE_GENHTML_OPTIONS,
CODE_COVERAGE_IGNORE_PATTERN): New variables.
(strace_CPPFLAGS): Add $(CODE_COVERAGE_CPPFLAGS).
(strace_CFLAGS): Add $(CODE_COVERAGE_CFLAGS).
(strace_LDADD): Add $(CODE_COVERAGE_LDFLAGS).
* .gitignore: Add *.gcda and *.gcno.

Signed-off-by: Gabriel Laskar <gabriel@lse.epita.fr>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2016-02-04 03:36:11 +00:00
71d3aa0cea Makefile.am: introduce strace_CFLAGS and derivatives
* Makefile.am (strace_CFLAGS): New variable, set to $(AM_CFLAGS).
(libmpers_CFLAGS): New variable, set to $(strace_CFLAGS).
(libmpers_m32_a_CFLAGS, libmpers_mx32_a_CFLAGS): New variables,
set to $(libmpers_CFLAGS).
2016-02-03 19:24:23 +00:00
fafa7dc2f3 Makefile.am: use strace_CPPFLAGS consistently
* Makefile.am (libmpers_CPPFLAGS): Replace $(AM_CPPFLAGS)
with $(strace_CPPFLAGS).
2016-02-03 19:18:28 +00:00
751fcb8f8a tests: replace net-fd.test with net-y-unix.test
Unlike the former test that was based on match_grep,
the new one uses match_diff and does more rigorous testing.

* tests/net-y-unix.c: New file.
* tests/net-y-unix.test: New test.
* tests/net-fd.test: Remove.
* tests/net-fd.expected: Remove.
* tests/.gitignore: Add net-y-unix.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(TESTS): Replace net-fd.test with net-y-unix.test.
(net-fd.log): Remove.
(EXTRA_DIST): Remove net-fd.expected.
2016-02-03 16:09:34 +00:00
3c17d1b5e1 Implement caching of print_sockaddr_by_inode
As -yy parser, compared to -y, needs to do at least 5 extra syscalls
(getxattr, socket, sendmsg, recvmsg, close) to print socket details,
caching results of netlink conversations between strace and kernel
noticeably reduces amount of system time spent by strace.

The caching is safe since sockets do not change their addresses after
successful bind or connect syscall.

* defs.h (string_quote, print_sockaddr_by_inode_cached): New prototypes.
* socketutils.c (cache_entry): New type.
(CACHE_SIZE, CACHE_MASK): New macros.
(cache): New static array.
(cache_and_print_inode_details): New static function.
(print_sockaddr_by_inode_cached): New function.
(inet_parse_response, unix_parse_response): Use
cache_and_print_inode_details.
* util.c (printfd): Use string_quote and print_sockaddr_by_inode_cached.
(string_quote): Remove static qualifier.
* NEWS: Mention this improvement.
* tests/unix-yy.c (main): Update.
2016-02-03 12:43:22 +00:00
69bfc89770 Change unix_diag requests to use exact match instead of full dump
* socketutils.c (unix_send_query): Remove NLM_F_DUMP from nlmsg_flags,
initialize udiag_cookie.
* tests/netlink_unix_diag.c (send_query): Remove "family" and "proto"
arguments, add "inode" argument, remove NLM_F_DUMP from nlmsg_flags,
initialize udiag_ino and udiag_cookie.
(check_responses): Add "inode" argument, check inode match.
(main): Pass listening socket inode to send_query and check_responses.
2016-02-03 12:43:22 +00:00
3c86e0ea5d Robustify netlink response parsers
* socketutils.c (inet_parse_response, unix_parse_response): Change
return type from bool to int, return -1 on all parse errors except
inode mismatch.
(receive_responses): Stop on the first nlmsg_type that is not
SOCK_DIAG_BY_FAMILY, also stop when the parser returns -1.
* tests/netlink_inet_diag.c (check_responses): Stop on short messages,
on first nlmsg_type that is not SOCK_DIAG_BY_FAMILY, print more verbose
diagnostics for NLMSG_ERROR.
* tests/netlink_unix_diag.c (check_responses): Likewise.
2016-02-03 12:43:17 +00:00
cc09ba1a84 inet_parse_response: add a safety check
* socketutils.c (inet_parse_response): Check that netlink message
is large enough to contain a inet_diag_msg structure.
2016-02-03 12:42:20 +00:00
2215c3e352 receive_responses: avoid potential hangup
* socketutils.c (receive_responses): Pass MSG_DONTWAIT to recvmsg after
the first recvmsg call to avoid potential hangup.
2016-02-03 12:42:20 +00:00
9d15ec7b57 tests: replace net-yy.test with net-yy-inet.test
Unlike the former test that was based on match_awk,
the new one uses match_diff and does more rigorous testing.

* tests/net-yy-inet.c: New file.
* tests/net-yy-inet.test: New test.
* tests/net-yy.test: Remove.
* tests/net-yy-accept.awk: Remove.
* tests/net-yy-connect.awk: Remove.
* tests/inet-accept-connect-send-recv.c: Remove.
* tests/.gitignore: Replace inet-accept-connect-send-recv
with net-yy-inet.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(TESTS): Replace net-yy.test with net-yy-inet.test.
(EXTRA_DIST): Remove net-yy-accept.awk and net-yy-connect.awk.
2016-02-03 12:42:01 +00:00
6124cd9932 tests: replace unix-yy.test with net-yy-unix.test
Unlike the former test that was based on match_awk,
the new one uses match_diff and does more rigorous testing.

* tests/net-yy-unix.c: New file.
* tests/net-yy-unix.test: New test.
* tests/unix-yy.test: Remove.
* tests/unix-yy-accept.awk: Remove.
* tests/unix-yy-connect.awk: Remove.
* tests/.gitignore: Add net-yy-unix.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(TESTS): Replace unix-yy.test with net-yy-unix.test.
(EXTRA_DIST): Remove unix-yy-accept.awk and unix-yy-connect.awk.
2016-02-03 12:39:06 +00:00
e364920b67 tests: add inode_of_sockfd function to libtests
* tests/tests.h (inode_of_sockfd): New prototype.
* tests/inode_of_sockfd.c: New file.
* tests/Makefile.am (libtests_a_SOURCES): Add it.
2016-02-02 00:24:48 +00:00
3d0f55e419 unix_parse_response: add a safety check
* socketutils.c (unix_parse_response): Check that netlink message
is large enough to contain a unix_diag_msg structure.
2016-02-02 00:24:46 +00:00
dfea1da0e6 Fixed decoding of mincore syscall's last argument
* mem.c (SYS_FUNC(mincore)): Print only those bytes of the vector
that were written by the kernel.
* NEWS: Mention this fix.
* tests/mincore.c: New file.
* tests/mincore.test: New test.
* tests/Makefile.am (check_PROGRAMS): Add mincore.
(TESTS): Add mincore.test.
* tests/.gitignore: Add mincore.
2016-01-29 02:39:40 +00:00
ea8b8e3152 Move fallback -yy socket print from printfd to print_sockaddr_by_inode
* util.c (printfd): In -yy mode, move fallback print of proto:[inode] ...
* socketutils.c (to print_sockaddr_by_inode): ... here.
2016-01-23 16:35:02 +00:00
fa8c286d50 Implement simultaneous use of -p option and tracing of a command
* strace.c (init): Allow -p option along with a command.
(startup_child): In -D mode, record the parent of the tracer process
as strace_child.
(startup_attach): Save trace_tracer_pid before -D mode fork.
When tracing a command in -f mode, do not check for the command's
threads as it has no threads at this moment.
Never attach to the tracer process.
In -D mode, never attach to the parent of the tracer process,
terminate that process only once at the end of startup_attach,
and reset strace_child.
* strace.1: Document that -p option can be used along with tracing
of a command.
* NEWS: Mention it.
* tests/attach-p-cmd-cmd.c: New file.
* tests/attach-p-cmd-p.c: Likewise.
* tests/attach-p-cmd.test: New test.
* tests/.gitignore: Add attach-p-cmd-cmd and attach-p-cmd-p.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(TESTS): Add attach-p-cmd.test.

This fixes Debian bug #549942.
2016-01-22 19:37:11 +00:00
38721432de strace.1: fix format of -P description
* strace.1 (-P): Write trailing using regular font.
2016-01-22 14:55:56 +00:00