]> granicus.if.org Git - strace/log
strace
12 years agoMake printing of utsname.domainname more portable
Dmitry V. Levin [Tue, 1 May 2012 20:56:32 +0000 (20:56 +0000)]
Make printing of utsname.domainname more portable

* configure.ac: Check for struct utsname.domainname field.
* process.c (sys_uname): Print utsname.domainname when the field is
available.

12 years agoFix recvmmsg decode: do not show more data than actually returned
Dmitry V. Levin [Tue, 1 May 2012 20:41:40 +0000 (20:41 +0000)]
Fix recvmmsg decode: do not show more data than actually returned

This change complements recent fix for recvmsg decoding.

* net.c (printmmsghdr): Add msg_len parameter to pass down to do_msghdr.
When this parameter is zero, pass mmsghdr.msg_len to do_msghdr instead.
(decode_mmsg): Add msg_len parameter, pass it down to printmmsghdr.
(sys_sendmmsg): Call decode_mmsg with msg_len == (unsigned long) -1L.
(sys_recvmmsg): Call decode_mmsg with msg_len == 0.

12 years agoRemove recently introduced use of ULONG_MAX
Dmitry V. Levin [Tue, 1 May 2012 20:30:02 +0000 (20:30 +0000)]
Remove recently introduced use of ULONG_MAX

* io.c: Remove limits.h inclusion.
(tprint_iov): Use "(unsigned long) -1L" instead of "ULONG_MAX".
* net.c: Remove limits.h inclusion.
(printmmsghdr, sys_sendmsg): Use "(unsigned long) -1L" instead of
"ULONG_MAX".

12 years agoEnable printing of uts.domainname in uname syscall
Denys Vlasenko [Sat, 28 Apr 2012 14:59:47 +0000 (16:59 +0200)]
Enable printing of uts.domainname in uname syscall

* process.c (sys_uname): Enable printing of uts.domainname

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoFix printstr's len parameter width
Denys Vlasenko [Sat, 28 Apr 2012 12:58:35 +0000 (14:58 +0200)]
Fix printstr's len parameter width

We often pass syscall params and other long-sized values
as printstr(len). Truncating them to int may be a bad thing.

* defs.h: Change len parameter's type from int to long in
string_quote and printstr function declarations.
* util.c (string_quote): Special-case only len==-1, not all len<0.
(printstr): Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoFix recvmsg decode: do not show more data than actually returned
Denys Vlasenko [Sat, 28 Apr 2012 12:26:18 +0000 (14:26 +0200)]
Fix recvmsg decode: do not show more data than actually returned

I noticed that "hostname -d" talks over netlink and gets 20 bytes
of response, but we show entire 1024 bytes of iov.
This changes fixes that.

* defs.h: New function tprint_iov_upto.
* io.c (tprint_iov_upto): Definition of this function.
(tprint_iov): Call tprint_iov_upto.
* net.c (do_msghdr): Add data_size parameter, pass it down to tprint_iov_upto.
(printmsghdr): Add data_size parameter, pass it down to do_msghdr.
(printmmsghdr): Call do_msghdr with data_size==ULONG_MAX.
(sys_sendmsg): Call printmsghdr with data_size==ULONG_MAX.
(sys_recvmsg): Call printmsghdr with data_size==tcp->u_rval.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoPackage strace-log-merge
Dmitry V. Levin [Fri, 27 Apr 2012 23:38:44 +0000 (23:38 +0000)]
Package strace-log-merge

* strace.spec (%files): Add strace-log-merge.

12 years agoNEWS: clarify & fix typo
Mike Frysinger [Fri, 27 Apr 2012 23:13:55 +0000 (19:13 -0400)]
NEWS: clarify & fix typo

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
12 years agoCast current_wordsize to an int
Mike Frysinger [Fri, 27 Apr 2012 22:58:20 +0000 (18:58 -0400)]
Cast current_wordsize to an int

On 64bit systems with a single personality, we see:
count.c: In function 'call_summary':
count.c:223:5: warning: format '%u' expects type 'unsigned int',
but argument 3 has type 'long unsigned int'

Since on multi-personality systems this is an array of ints, cast
the multiplication to an int and update the printf format.

* count.c (call_summary): Change %u to %d and cast first argument to int.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
12 years agoUpdate NEWS for upcoming 4.7 release
Dmitry V. Levin [Fri, 20 Apr 2012 17:32:50 +0000 (17:32 +0000)]
Update NEWS for upcoming 4.7 release

* NEWS: Update for 4.7 release.

12 years agoSync strace.spec and debian/ with packages
Dmitry V. Levin [Fri, 20 Apr 2012 17:31:48 +0000 (17:31 +0000)]
Sync strace.spec and debian/ with packages

* debian/changelog: Sync with 4.5.20-2.3.
* debian/control: Likewise.
* strace.spec: Sync with 4.6-2.

12 years agoDecode /dev/loop ioctls
Mike Frysinger [Wed, 18 Apr 2012 02:19:31 +0000 (22:19 -0400)]
Decode /dev/loop ioctls

Needed to debug some losetup failures, and it's easier when you can see
what the kernel is getting vs what you think you're sending, so add some
decoders for those ioctls.

* loop.c: New file.
* Makefile.am (strace_SOURCES): Add loop.c.
* defs.h (loop_ioctl): New prototype.
(string_quote): Likewise.
* ioctl.c (ioctl_decode): Call loop_ioctl when code is 'L'.
* util.c (string_quote): Remove static keyword.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
12 years agox32: add ia32 support
H.J. Lu [Tue, 17 Apr 2012 18:05:04 +0000 (11:05 -0700)]
x32: add ia32 support

* Makefile.am (EXTRA_DIST): Add linux/x32/errnoent1.h,
linux/x32/ioctlent1.h, linux/x32/signalent1.h and
linux/x32/syscallent1.h.
* configure.ac: Remove AC_GNU_SOURCE, obsoleted by
AC_USE_SYSTEM_EXTENSIONS.
* defs.h (SUPPORTED_PERSONALITIES): Set to 2 for X32.
(PERSONALITY1_WORDSIZE): Set to 4 for X32.
* file.c (stat64): New struct for X32.
(sys_lseek32): New function for X32.
(stat64): Undef.
(sys_fstat64): Likewise.
(sys_stat64): Likewise.
(realprintstat64): New function for X32.
(sys_fstat64): Likewise.
(sys_stat64): Likewise.
* mem.c (sys_old_mmap): New function for X32.
* pathtrace.c (pathtrace_match): Also check sys_old_mmap for X32.
* syscall.c (update_personality): Add X32 support.
(get_scno): Support currpers == 1 for X32.
* linux/syscall.h (sys_lseek32): New function prototype for X32.
* linux/x32/errnoent1.h: New file.
* linux/x32/ioctlent1.h: Likewise.
* linux/x32/signalent1.h: Likewise.
* linux/x32/syscallent1.h: Likewise.

12 years agoCast clock_t type to unsigned long long
H.J. Lu [Sun, 15 Apr 2012 18:17:13 +0000 (11:17 -0700)]
Cast clock_t type to unsigned long long

* resource.c (sys_times): Cast clock_t type to unsigned long long.
* signal.c (printsiginfo): Likewise.

12 years agoAdd custom (faster) vfprintf implementation (disabled by default)
Denys Vlasenko [Mon, 16 Apr 2012 16:22:19 +0000 (18:22 +0200)]
Add custom (faster) vfprintf implementation (disabled by default)

* defs.h: Declare strace_vfprintf either as a alias to vfprintf
or as a bona fide function. USE_CUSTOM_PRINTF define controls whether
we use strace_vfprintf. By default, we don't.
* strace.c (tprintf): Call strace_vfprintf instead of vfprintf.
* vsprintf.c: New file, implements strace_vfprintf.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoStop using %h[h]u format specifiers
Denys Vlasenko [Mon, 16 Apr 2012 16:12:27 +0000 (18:12 +0200)]
Stop using %h[h]u format specifiers

This is needed for simplified printf, and reduces code size a bit.

* block.c (block_ioctl): Cast the value to unsinged and use %u
instead of using %hu.
* desc.c (sys_io_cancel): Likewise.
* resource.c (sys_sysinfo): Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoTrivial speed optimization
Denys Vlasenko [Mon, 16 Apr 2012 16:10:15 +0000 (18:10 +0200)]
Trivial speed optimization

* strace.c (tprints): Use fputs_unlocked instead of fputs.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoFix a problem with sys_lseek on x32
H.J. Lu [Mon, 16 Apr 2012 15:41:13 +0000 (17:41 +0200)]
Fix a problem with sys_lseek on x32

* file.c (sys_lseek): Use MIPS-n32 variant also for x32

Signed-off-by: H.J. Lu <hongjiu.lu@intel.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoAdd x32 support to strace
H.J. Lu [Mon, 16 Apr 2012 11:00:01 +0000 (13:00 +0200)]
Add x32 support to strace

X32 support is added to Linux kernel 3.4. In a nutshell, x32 is x86-64 with
32bit pointers.  At system call level, x32 is also identical to x86-64,
as shown by many changes like "defined(X86_64) || defined(X32)".  The
main differerence bewteen x32 and x86-64 is off_t in x32 is long long
instead of long.

This patch adds x32 support to strace.  Tested on Linux/x32.

* configure.ac: Support X32.
* defs.h: Set SUPPORTED_PERSONALITIES to 3 for X86_64,
Set PERSONALITY2_WORDSIZE to 4 for X86_64.
Add tcb::ext_arg for X32.
* file.c (stat): New for X32.
(sys_lseek): Use 64-bit version for X32.
(printstat64): Check current_personality != 1 for X86_64.
* ipc.c (indirect_ipccall): Check current_personality == 1
for X86_64.
* mem.c (sys_mmap64): Also use tcp->u_arg for X32.  Print NULL
for zero address.  Call printllval for offset for X32.
* pathtrace.c (pathtrace_match): Don't check sys_old_mmap for
X32.
* process.c (ARG_FLAGS): Defined for X32.
(ARG_STACK): Likewise.
(ARG_PTID): Likewise.
(change_syscall): Handle X32.
(struct_user_offsets): Support X32.
(sys_arch_prctl): Likewise.
* signal.c: Include <asm/sigcontext.h> for X32.
(SA_RESTORER): Also define for X32.
* syscall.c (update_personality): Support X32 for X86_64.
(is_restart_error): Likewise.
(syscall_fixup_on_sysenter): Likewise.
(get_syscall_args): Likewise.
(get_syscall_result): Likewise.
(get_error): Likewise.
(__X32_SYSCALL_BIT): Define if not defined.
(__X32_SYSCALL_MASK): Likewise.
(get_scno): Check DS register value for X32.  Use
__X32_SYSCALL_MASK on X32 system calls.
* util.c (printllval): Use ext_arg for X32.
(printcall): Support X32.
(change_syscall): Likewise.
(arg0_offset): Likewise.
(arg1_offset): Likewise.
* Makefile.am (EXTRA_DIST): Add linux/x32/errnoent.h,
linux/x32/ioctlent.h.in, linux/x32/signalent.h,
linux/x32/syscallent.h, linux/x86_64/errnoent2.h,
linux/x86_64/ioctlent2.h, linux/x86_64/signalent2.h and
linux/x86_64/syscallent2.h.
* linux/x32/errnoent.h: New.
* linux/x32/ioctlent.h.in: Likewise.
* linux/x32/signalent.h: Likewise.
* linux/x32/syscallent.h: Likewise.
* linux/x86_64/errnoent2.h: Likewise.
* linux/x86_64/ioctlent2.h: Likewise.
* linux/x86_64/signalent2.h: Likewise.
* linux/x86_64/syscallent2.h: Likewise.

Signed-off-by: H.J. Lu <hongjiu.lu@intel.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoRestore tcb::u_lrval; fix lseek on MIPS-n32
H.J. Lu [Mon, 16 Apr 2012 10:16:45 +0000 (12:16 +0200)]
Restore tcb::u_lrval; fix lseek on MIPS-n32

Linux kernel v3.4 adds x32 support.  Both x32 and n32 use 64bit offset
for lseek parameter and return value.  We need u_lrval to handle it
properly.  Also we shouldn't check HAVE_LONG_LONG_OFF_T for n32 lseek.
This patch fixes it properly and prepares lseek for x32.

* defs.h (tcb): Restore tcb::u_lrval field, RVAL_Lfoo constants.
Set RVAL_MASK to 7.
* file.c (sys_lseek): Print 64bit offset and return RVAL_LUDECIMAL
for n32.
* syscall.c (get_error): Set u_lrval for MIPS-n32.
(trace_syscall_exiting): Handle RVAL_Lfoo return value types.

Signed-off-by: H.J. Lu <hongjiu.lu@intel.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoDecode mtd ioctls
Mike Frysinger [Thu, 5 Apr 2012 02:22:01 +0000 (22:22 -0400)]
Decode mtd ioctls

I got tired of figuring out mtd structures (which show up a lot
in the embedded space), so add decoders for those ioctls.

* defs.h (mtd_ioctl): New prototype.
(print_loff_t): Likewise.
* io.c (print_loff_t): Delete static keyword
* ioctl.c (ioctl_decode): Call mtd_ioctl when code is 'M'.
* Makefile.am (strace_SOURCES): Add mtd.c.
(EXTRA_DIST): Add linux/mtd-abi.h.
* mtd.c: New file.
* linux/mtd-abi.h: New file.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
12 years agoFix indefinite hang on no-mmu systems
Mike Frysinger [Thu, 5 Apr 2012 05:52:25 +0000 (01:52 -0400)]
Fix indefinite hang on no-mmu systems

The ptrace setoptions code will fork a child which goes to sleep and
expects the parent to continue on to do tests.  Unfortunately, this
does not work on no-mmu systems as fork() is actually vfork() and any
vforked children will hang the parent until it exits or execs.

We might be able to make this test work on no-mmu systems with a bit
of work, but easier to just disable this for the release so it works
now.

* strace.c (test_ptrace_setoptions_for_all): Return if strace_vforked.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
12 years agoMakefile.am: whitespace fix
Denys Vlasenko [Thu, 29 Mar 2012 15:21:41 +0000 (17:21 +0200)]
Makefile.am: whitespace fix

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agopowerpc: Add syscall entries for direct socket system calls
Anton Blanchard [Mon, 26 Mar 2012 23:34:54 +0000 (10:34 +1100)]
powerpc: Add syscall entries for direct socket system calls

* linux/powerpc/syscallent.h: Add direct socket system calls.

12 years agoqual_syscall: fix potential NULL dereference
Dmitry V. Levin [Mon, 26 Mar 2012 14:14:50 +0000 (14:14 +0000)]
qual_syscall: fix potential NULL dereference

Fix regression introduced by commit
c1371ebc400fe9578908beca87f2bf407daf1506

* syscall.c (qual_syscall): Handle null sys_name.

Reported-by: Fr. Br. George <george@altlinux.org>
12 years agostrace-log-merge: fix file suffix calculation
Dmitry V. Levin [Mon, 26 Mar 2012 12:10:01 +0000 (12:10 +0000)]
strace-log-merge: fix file suffix calculation

* strace-log-merge: Quote file prefix to fix file suffix calculation.

Reported-by: Denys Vlasenko <vda.linux@googlemail.com>
Suggested-by: Andreas Schwab <schwab@linux-m68k.org>
12 years agoRemove unreachable code
Denys Vlasenko [Mon, 26 Mar 2012 11:41:56 +0000 (13:41 +0200)]
Remove unreachable code

* strace.c (process_opt_p_list): Remove unreachable code.

12 years agomanpage: remove false info about -p being limited to 32 processes
Denys Vlasenko [Mon, 26 Mar 2012 11:31:11 +0000 (13:31 +0200)]
manpage: remove false info about -p being limited to 32 processes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoTweak help text and manpage (added -In to manpage)
Denys Vlasenko [Mon, 26 Mar 2012 11:10:50 +0000 (13:10 +0200)]
Tweak help text and manpage (added -In to manpage)

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoprintstr: check for potential integer overflow
Dmitry V. Levin [Sun, 25 Mar 2012 22:56:53 +0000 (22:56 +0000)]
printstr: check for potential integer overflow

* util.c (printstr): Check for potential integer overflow during outstr
buffer size calculation.

12 years agoRobustify parsing of numbers from strings
Dmitry V. Levin [Sun, 25 Mar 2012 21:49:48 +0000 (21:49 +0000)]
Robustify parsing of numbers from strings

* defs.h (string_to_uint): New prototype.
* util.c (string_to_uint): New function.
* strace.c (error_opt_arg): New function.
(process_opt_p_list): Use string_to_uint instead of atoi.
Terminate in case of invalid process id.
(init): Use string_to_uint instead of atoi.
Use error_opt_arg in case of invalid option argument.
* syscall.c (qual_syscall, qual_signal, qual_desc): Use string_to_uint
instead of atoi.

12 years agostrace-log-merge: enhance usage error diagnostics
Dmitry V. Levin [Sun, 25 Mar 2012 21:04:57 +0000 (21:04 +0000)]
strace-log-merge: enhance usage error diagnostics

* strace-log-merge: Add --help option.  Check number of arguments.
Issue an error message when no strace output was merged.

12 years agoconfigure.ac: sort lists and use m4_normalize to ease maintenance
Dmitry V. Levin [Sun, 25 Mar 2012 15:12:16 +0000 (15:12 +0000)]
configure.ac: sort lists and use m4_normalize to ease maintenance

* configure.ac (AC_CHECK_FUNCS, AC_CHECK_HEADERS, AC_CHECK_MEMBERS,
AC_CHECK_DECLS): Sort lists, use m4_normalize.

12 years agoSimple optimizations
Denys Vlasenko [Fri, 23 Mar 2012 10:29:01 +0000 (11:29 +0100)]
Simple optimizations

Why open-coding isdigit is a good idea?

Before: call   __ctype_b_loc
        movzbl (%ebx),%edx
        mov    (%eax),%eax
        testb  $0x8,0x1(%eax,%edx,2)
        je     lbl

After:  movzbl (%eax),%edx
        sub    $0x30,%edx
        cmp    $0x9,%dl
        ja     lbl

   text    data     bss     dec     hex filename
 236869     704   18944  256517   3ea05 strace.before
 236719     700   18944  256363   3e96b strace

* defs.h: Alias sigemptyset to __sigemptyset on glibc.
* syscall.c (qual_syscall): Open-code isdigit.
(qual_desc): Likewise.
(qual_signal): Open-code isdigit. Remove string copying
which was done for no apparent reason.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoReorder declarations in defs.h. No code changes
Denys Vlasenko [Fri, 23 Mar 2012 10:26:36 +0000 (11:26 +0100)]
Reorder declarations in defs.h. No code changes

* defs.h: Reorder declarations (such as: keep all printing functions together).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoSimplify current tcp switching and current column handling
Denys Vlasenko [Thu, 22 Mar 2012 08:56:20 +0000 (09:56 +0100)]
Simplify current tcp switching and current column handling

Instead of using "static FILE *outf and static unsigned int curcol"
to cache current outfile and its position, we can simply
remember current tcb and use its ->outf and ->curcol.
This allows to drop numerous "tcp->curcol = curcol" ops in trace().

Turns out we can't drop "static FILE *outf", but now its role is
a bit clearer: it newer changes after init, stays == stderr or
opened to shared log (which may be the same thing if neither -o
nor -ff was specified). Let's rename it then.

   text    data     bss     dec     hex filename
 236953     704   18944  256601   3ea59 strace.before.prev.commit
 236905     704   18944  256553   3ea29 strace.before
 236869     704   18944  256517   3ea05 strace

* strace.c: Replace curcol static variable by struct tcb *current_tcp.
Rename static FILE *outf to shared_log (since it no longer caches tcp->outf).
(ptrace_restart): Use current_tcp->curcol instead of curcol.
(tprintf): Check current_tcp != NULL instead of outf != NULL.
Use current_tcp->outf instead of outf, current_tcp->curcol instead of curcol.
(tprints): Likewise.
(line_ended): Likewise.
(printleader): Switch current tcb by "current_tcp = tcp" istead of
assignments to outf and curcol.
(droptcb): Set current_tcp to NULL if we dropped it.
(startup_child): Rename outf to shared_log.
(init): Likewise.
(cleanup): Likewise.
(trace): Simplify current tcp switching and current column handling.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoMake threaded execve handling code more reabable and somewhat simpler
Denys Vlasenko [Thu, 22 Mar 2012 08:35:51 +0000 (09:35 +0100)]
Make threaded execve handling code more reabable and somewhat simpler

* strace.c (droptcb): Remove outfname check in "outfname && followfork >= 2" -
with recent changes, followfork >= 2 check guarantees that outfile
was specified, and _is already opened_.
(trace): Move tcb existence check before threaded execve handling.
This allows to remove tcp != NULL checks in threaded execve handling.
Rewrite threaded execve handling code to be less indented,
keeping the same logic.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agosimple cleanups in defs.h. No logic changes.
Denys Vlasenko [Wed, 21 Mar 2012 13:39:22 +0000 (14:39 +0100)]
simple cleanups in defs.h. No logic changes.

* defs.h: Move offsetof macro definition into "libc stuff" section.
Renumber TCB_foo constants (smaller constants -> sometimes smaller code).
Remove uoff macro.
* process.c: Move uoff macro here (sole user).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoShow "+++ exited..." with -C
Denys Vlasenko [Wed, 21 Mar 2012 13:27:40 +0000 (14:27 +0100)]
Show "+++ exited..." with -C

* strace.c (trace): Show "+++ exited..." with -C too.
Save tcp->curcol after PTRACE_LISTEN failure too, just in case.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoSlight tweak to qemu_multiarch_testing scripts
Denys Vlasenko [Wed, 21 Mar 2012 10:32:55 +0000 (11:32 +0100)]
Slight tweak to qemu_multiarch_testing scripts

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoReplace reprinting decision logic
Denys Vlasenko [Wed, 21 Mar 2012 10:06:20 +0000 (11:06 +0100)]
Replace reprinting decision logic

After this change, we no longer need to decide when we need
to set TCB_REPRINT, and when we don't: it's never needed :)

Well, almost. That pesky pid-changing execve needs special treatment.
If not it, it'd be possible to nuke TCB_REPRINT...

While at it, fix a case of mishandled -C.

* strace.c (printleader): Do not set TCB_REPRINT.
(trace): Set TCB_REPRINT only for execve with changing pid.
Fix mishandling of -C.
* syscall.c (trace_syscall_entering): Do not clear TCB_REPRINT.
(trace_syscall_exiting): Replace reprinting decision logic.
Remove call to printargs(): it is known to just return 0 here.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoReport some ptrace failures; nuke tcp->ptrace_errno
Denys Vlasenko [Wed, 21 Mar 2012 09:32:49 +0000 (10:32 +0100)]
Report some ptrace failures; nuke tcp->ptrace_errno

Report some (not all) ptrace errors, namely,
errors on ptrace restart operations.

Before: 10533 sendto(-1, 0x804895e, 17, 0, NULL, 0 <unfinished ...>
After:  10533 sendto(-1, 0x804895e, 17, 0, NULL, 0 <ptrace(SYSCALL):No such process>

This tells user that strace failed to let sendto syscall
to be entered - process was dead at that point of time.
It is (marginally) better than to always say "<unfinished ...>"

While at it, patch removes tcp->ptrace_errno.
I added it many months ago, and it looks that after all
it is not needed for ptrace error detection: I failed to execute
a single existing code path which is accessible
through that variable only.

* defs.h: Remove struct tcp::ptrace_errno field.
* strace.c (ptrace_restart): Emit message to log on error.
(printleader): Remove "if (printing_tcp->ptrace_errno)..." code.
(trace): Remove !tcp->ptrace_errno check, it's always true.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoEliminate redundant checks of res variable
Denys Vlasenko [Tue, 20 Mar 2012 23:23:16 +0000 (00:23 +0100)]
Eliminate redundant checks of res variable

* syscall.c (trace_syscall_entering): Eliminate redundant checks of res variable.
(trace_syscall_exiting): Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoRename POWERPC-specific static variable result to ppc_result
Denys Vlasenko [Tue, 20 Mar 2012 23:07:25 +0000 (00:07 +0100)]
Rename POWERPC-specific static variable result to ppc_result

* syscall.c: Rename POWERPC-specific static variable result to ppc_result.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoRemove redundant checks in syscall entry/exit, rename badly named function
Denys Vlasenko [Tue, 20 Mar 2012 16:10:35 +0000 (17:10 +0100)]
Remove redundant checks in syscall entry/exit, rename badly named function

* syscall.c (syscall_enter): Rename to get_syscall_args.
Document its return values.
(trace_syscall_entering): Don't check get_syscall_args() return
value for 0, it never returns that.
(syscall_fixup_on_sysexit): Make it return void.
(trace_syscall_exiting): Fix up syscall_fixup_on_sysexit()
call site accordingly.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoTrivial tweaks. No logic changes
Denys Vlasenko [Tue, 20 Mar 2012 15:48:35 +0000 (16:48 +0100)]
Trivial tweaks. No logic changes

* process.c (sys_ptrace): Remove unneeded line wrapping.
* syscall.c (trace_syscall_entering): Use tprints() instead of tprintf().

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoMake ptrace_restart() static. No code changes
Denys Vlasenko [Tue, 20 Mar 2012 15:26:25 +0000 (16:26 +0100)]
Make ptrace_restart() static. No code changes

* defs.h: Remove ptrace_restart() declaration.
* strace.c (ptrace_restart): Move its definition here.
* util.c (ptrace_restart): Remove its definition.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoDo not include limits.h unnecessarily
Dmitry V. Levin [Tue, 20 Mar 2012 14:02:51 +0000 (14:02 +0000)]
Do not include limits.h unnecessarily

* ioctl.c: Remove limits.h inclusion left after the reverted change.

12 years agoPartially revert last change
Denys Vlasenko [Tue, 20 Mar 2012 12:11:51 +0000 (13:11 +0100)]
Partially revert last change

Thank you Dmitry for spotting it.

* ioctl.c (compare): Partially revert last change - the new
comparison logic was buggy.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoSimplify search in ioctl table
Denys Vlasenko [Tue, 20 Mar 2012 09:57:41 +0000 (10:57 +0100)]
Simplify search in ioctl table

   text    data     bss     dec     hex filename
 236973     704   18944  256621   3ea6d strace.before
 236929     704   18944  256577   3ea41 strace

* ioctl.c (compare): Simplify generation of compare result.
(ioctl_lookup): Pass key directly, not as part of dummy struct.
(ioctl_next_match): More readable code. No logic changes.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoUpdate qemu build script: now tries to upload result back to host
Denys Vlasenko [Mon, 19 Mar 2012 11:20:32 +0000 (12:20 +0100)]
Update qemu build script: now tries to upload result back to host

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoShrink space needed by undefined syscalls in syscall tables.
Denys Vlasenko [Mon, 19 Mar 2012 08:51:42 +0000 (09:51 +0100)]
Shrink space needed by undefined syscalls in syscall tables.

Undefined syscall looked like this before this change:
{ 5,    0,      printargs,              "SYS_53"                },
That is, "SYS_53" string had to be allocated and stored in strace binary.
Since now SCNO_IN_RANGE() macro requires sysent[scno].sys_func != NULL
for valid syscalls, we can replace printargs with NULL in such lines
and make them "invalid", thus not requiring syscall name string.

Savings on i386:
   text    data     bss     dec     hex filename
 237389     704   18944  257037   3ec0d strace.before
 236973     704   18944  256621   3ea6d strace
Savings on mips:
 336551  153692   38320  528563   810b3 strace.before
 275543  153688   38320  467551   7225f strace

Tested to still decode undefined syscalls correctly (syscall no. 222 on i386).

* linux/*/syscallent.h: Replace 'printargs, "SYS_nnn"' with
'NULL, NULL'.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoOptimize code if we have only one personality
Denys Vlasenko [Mon, 19 Mar 2012 08:36:42 +0000 (09:36 +0100)]
Optimize code if we have only one personality

On i386:
   text    data     bss     dec     hex filename
 238025     672   18980  257677   3ee8d strace.before
 237389     704   18944  257037   3ec0d strace

* defs.h: Define PERSONALITY0_WORDSIZE as sizeof(long) if not defined.
Introduce new define, current_wordsize as
(personality_wordsize[current_personality]).
Make set_personality() no-op, current_personality constant zero,
current_wordsize as PERSONALITY0_WORDSIZE if we have only one personality.
* count.c (call_summary): Use current_wordsize instead of
personality_wordsize[current_personality].
* desc.c (printflock): Likewise.
* file.c (sys_utime): Likewise.
* io.c (tprint_iov): Likewise.
* process.c (printargv): Likewise.
* resource.c (decode_rlimit): Likewise.
* signal.c (sys_kill): Likewise.
(sys_rt_sigaction): Likewise.
* time.c (sprinttv): Likewise.
(sprint_timespec): Likewise.
(printitv_bitness): Likewise.
(tprint_timex): Likewise.
(printsigevent): Likewise.
* util.c (dumpiov): Likewise.
(umoven): Likewise.
(umovestr): Likewise.
* syscall.c: Initialize sysent to sysent0 etc.
Make current_personality, personality_wordsize[], set_personality()
conditional on SUPPORTED_PERSONALITIES > 1.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoFix mips64 build failure: sys_pwrite64 doesn't exist.
Denys Vlasenko [Sun, 18 Mar 2012 22:49:07 +0000 (23:49 +0100)]
Fix mips64 build failure: sys_pwrite64 doesn't exist.

sys_pwrite seems to do the same thing as sys_pwrite64
which we deleted when we removed non-Linux code.

* linux/mips/syscallent.h: s/sys_pwrite64/sys_pwrite/

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoqemu_multiarch_testing/: a directory with scripts for build testing
Denys Vlasenko [Sun, 18 Mar 2012 22:27:23 +0000 (23:27 +0100)]
qemu_multiarch_testing/: a directory with scripts for build testing

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoMake internal_fork and internal_exec static
Denys Vlasenko [Sun, 18 Mar 2012 21:10:48 +0000 (22:10 +0100)]
Make internal_fork and internal_exec static

   text    data     bss     dec     hex filename
 237917     672   18980  257569   3ee21 strace
 237845     672   18980  257497   3edd9 strace_new

* defs.h: Remove declarations of internal_fork and internal_exec.
* process.c: Remove definitions of internal_fork and internal_exec.
* syscall.c: Move them here.
(internal_syscall): Return void instead of int. We were always
returning zero, and callers weren't checking it anyway.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoRemove code which is not used on Linux
Denys Vlasenko [Sun, 18 Mar 2012 03:16:59 +0000 (04:16 +0100)]
Remove code which is not used on Linux

Compile tested in qemu on armv4l,armv4tl,armv5l,armv6l,i686,
mipsel,mips,x86_64

* syscall.c: Remove code which handles RVAL_Lfoo constants.
* defs.h: Remove struct tcb::u_lrval member - it is never set.
Remove RVAL_Lfoo constants which signify return of "long" result -
they are never used.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoRemove unused version of sys_lseek
Denys Vlasenko [Sun, 18 Mar 2012 03:13:14 +0000 (04:13 +0100)]
Remove unused version of sys_lseek

It is buggy: it returns RVAL_LUDECIMAL, which means the return value
is in tcp->u_lrval. But tcp->u_lrval is never set
(on Linux - it used to be set on other OSes).

* file.c (sys_lseek): Remove a version of this function which is
supposed to be used if off_t is long long. It appears to be buggy
and unused.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoRevert "Remove underscores from a few syscall names which have them"
Denys Vlasenko [Sat, 17 Mar 2012 17:00:14 +0000 (18:00 +0100)]
Revert "Remove underscores from a few syscall names which have them"

This reverts commit 31972d52b1059d8faca1c5f417c2db1a90b868ae.

12 years agoSimplify sys_lseek64 conditional compilation.
Denys Vlasenko [Sat, 17 Mar 2012 15:26:47 +0000 (16:26 +0100)]
Simplify sys_lseek64 conditional compilation.

It looks like sys_lseek64() is never used.
For one, it is buggy (always shows 0 return value), and no one complains.

From code inspection: sys_lseek64 name is not used anywhere.
It is defined to sys_lseek if HAVE_LONG_LONG_OFF_T is true.
Thus, if !HAVE_LONG_LONG_OFF_T, it is never used.
Therefore "if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T"
conditional it sits in can be simplified to
"if HAVE_LONG_LONG_OFF_T".
Therefore, we can move it a bit up and merge with
"if !HAVE_LONG_LONG_OFF_T, use this sys_lseek()" code block,
by addind an "else" clause to it.
To simplify it more, drop define and just rename sys_lseek64 ->
sys_lseek.

Since the function is buggy, I think it is unused and we can
just drop it. (I checked: at least I386 never uses it).

* file.c (sys_lseek64): Rename to sys_lseek; don't compile it
if _LFS64_LARGEFILE but !HAVE_LONG_LONG_OFF_T since in this case
it is never used.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoRemove underscores from a few syscall names which have them
Denys Vlasenko [Sat, 17 Mar 2012 12:23:00 +0000 (13:23 +0100)]
Remove underscores from a few syscall names which have them

Affected names are "_newselect", "_llseek", "_sysctl".
I see no apparent reason why they have leading underscores.
Moreover, some arches have underscored names and some have
non-underscored ones. This is not consistent.

I verified that every architectire I touched did not have
a similarly named syscall without underscore, thus this change
does not introduce new ambiquities.

I left "_exit" untouched for now, but the same points stand for it too:
some architectures use "exit" and no one complains. So why many
arches are using "_exit"?

* linux/*/syscallent.h: Remove underscores from displayed
syscall names for _newselect, _llseek, _sysctl.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoRemove unused struct tcb::baddr field
Denys Vlasenko [Sat, 17 Mar 2012 11:41:27 +0000 (12:41 +0100)]
Remove unused struct tcb::baddr field

* defs.h: Remove unused struct tcb::baddr field.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoRemove unused PTRACE_WRITE{TEXT,DATA} constants (they are from SunOS)
Denys Vlasenko [Sat, 17 Mar 2012 11:11:10 +0000 (12:11 +0100)]
Remove unused PTRACE_WRITE{TEXT,DATA} constants (they are from SunOS)

* util.c: Remove unused PTRACE_WRITE{TEXT,DATA} constants.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoReindent case labels. No code changes
Denys Vlasenko [Sat, 17 Mar 2012 03:42:07 +0000 (04:42 +0100)]
Reindent case labels. No code changes

* net.c (printsockopt): Reindent case labels.
* signal.c (sys_signal): Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoRemove unused constants. No code changes
Denys Vlasenko [Sat, 17 Mar 2012 02:17:15 +0000 (03:17 +0100)]
Remove unused constants. No code changes

* syscall.c: Remove unused ENOIOCTLCMD constant. Fix indentation.
* util.c: Remove unused CLONE_STOPPED constant.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoMove change_syscall() to its only user and make it static
Denys Vlasenko [Sat, 17 Mar 2012 01:17:51 +0000 (02:17 +0100)]
Move change_syscall() to its only user and make it static

* defs.h: Remove declaration of change_syscall().
* process.c (change_syscall): Remove definition of this function.
* util.c (change_syscall): Add definition of change_syscall().

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoMAP_ANON is the same as MAP_ANONYMOUS, no need to have the former
Denys Vlasenko [Sat, 17 Mar 2012 00:29:40 +0000 (01:29 +0100)]
MAP_ANON is the same as MAP_ANONYMOUS, no need to have the former

* mem.c: Do not allocate string for MAP_ANON if it is the same as
MAP_ANONYMOUS.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoIndentation and whitespace fixes. No code changes.
Denys Vlasenko [Sat, 17 Mar 2012 00:27:37 +0000 (01:27 +0100)]
Indentation and whitespace fixes. No code changes.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agotest/threaded_execve: make it also test a case when leader is not in syscall
Denys Vlasenko [Sat, 17 Mar 2012 00:24:25 +0000 (01:24 +0100)]
test/threaded_execve: make it also test a case when leader is not in syscall

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoImplement prlimit64 decoding, rewrite [gs]etrlimit decoding
Dmitry V. Levin [Fri, 16 Mar 2012 19:05:21 +0000 (23:05 +0400)]
Implement prlimit64 decoding, rewrite [gs]etrlimit decoding

* configure.ac: Remove AC_RLIM_T_IS_LONG_LONG call.
Define SIZEOF_RLIM_T.
* m4/long_long.m4 (AC_RLIM_T_IS_LONG_LONG): Remove.
* linux/dummy.h (sys_prlimit64): Remove.
* linux/syscall.h (sys_prlimit64): New prototype.
* resource.c (resources): Reindent, add RLIMIT_RTTIME.
(sprintrlim, print_rlimit32, sys_getrlimit, sys_setrlimit): Remove.
[HAVE_LONG_LONG_RLIM_T]: Remove dead code.
[_LFS64_LARGEFILE || HAVE_LONG_LONG_RLIM_T]: Likewise.
(sprint_rlim64, print_rlimit64, decode_rlimit64, sprint_rlim32,
print_rlimit32, decode_rlimit, sys_getrlimit, sys_setrlimit,
sys_prlimit64): New functions.

12 years agoRemove another "interrupt to quit" message
Denys Vlasenko [Fri, 16 Mar 2012 14:21:49 +0000 (15:21 +0100)]
Remove another "interrupt to quit" message

* strace.c (startup_attach): Remove another "interrupt to quit" message.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoFix "strace -oFILE -ff -p<nonexistant_pid>" behavior
Denys Vlasenko [Fri, 16 Mar 2012 14:15:14 +0000 (15:15 +0100)]
Fix "strace -oFILE -ff -p<nonexistant_pid>" behavior

* strace.c (newoutf): Set tcp->outf in non-ff mode too.
(alloctcb): This define is removed.
(alloc_tcb): Renamed to alloctcb. Does not set tcp->outf anymore.
Lost 'command_options_parsed' flag parameter.
(startup_attach): Do not say "interrupt to quit" in attach message -
^C does not work in all cases, we mislead users.
Call newoutf(tcp) after successful attach.
(startup_child): Call newoutf(tcp) after successful attach.
(trace): Call newoutf(tcp) when we picked up already attached child.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoMake alloc_tcb and droptcb static. No code changes.
Denys Vlasenko [Fri, 16 Mar 2012 14:11:34 +0000 (15:11 +0100)]
Make alloc_tcb and droptcb static. No code changes.

The change is trivial. Diff is large because it is confused
by function definitions being moved around.

* defs.h: Remove declarations of alloc_tcb and droptcb.
* strace.c: Make alloc_tcb and droptcb static.
Shuffle functions around to make compiler happy.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoTidy up includes and copyright notices, fix indentation
Denys Vlasenko [Fri, 16 Mar 2012 11:02:22 +0000 (12:02 +0100)]
Tidy up includes and copyright notices, fix indentation

The files not mentioned in changelog below had only
copyright notices fixes and indentation fixes.

* defs.h: Include <stdint.h> and <inttypes.h>.
* file.c: Do not include <inttypes.h>.
Move struct kernel_dirent declaration below top include block.
* block.c: Do not include <stdint.h> and <inttypes.h>.
* quota.c: Likewise.
* desc.c: Likewise.
* signal.c: Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoscsi.c: add copyright header
Dmitry V. Levin [Fri, 16 Mar 2012 10:43:32 +0000 (10:43 +0000)]
scsi.c: add copyright header

* scsi.c: This file was added back in 2007 without a copyright header.
Add it now.

12 years agoEnhance capget and capset syscalls decoding
Dmitry V. Levin [Thu, 15 Mar 2012 22:58:39 +0000 (22:58 +0000)]
Enhance capget and capset syscalls decoding

* system.c (cap_version): New xlat structure.
(print_cap_header, print_cap_data): New functions.
(sys_capget, sys_capset): Use them.

12 years agoRemove unused code
Dmitry V. Levin [Thu, 15 Mar 2012 22:08:55 +0000 (22:08 +0000)]
Remove unused code

* syscall.c (subcall_style, decode_subcall): Remove.
[SYS_socket_subcall] (decode_socket_subcall): New function, based on
decode_subcall in deref_style.
[SYS_ipc_subcall] (decode_ipc_subcall): New function, based on
decode_subcall in shift_style.
(trace_syscall_entering): Use decode_socket_subcall and
decode_ipc_subcall instead of decode_subcall.

12 years agoFix IPC decoding on alpha and arm
Dmitry V. Levin [Thu, 15 Mar 2012 21:19:36 +0000 (21:19 +0000)]
Fix IPC decoding on alpha and arm

* ipc.c (indirect_ipccall): Return 0 on ALPHA and ARM EABI.
(sys_shmat): Use indirect_ipccall for proper return value decoding.

12 years agoarm: fix compilation warnings
Dmitry V. Levin [Thu, 15 Mar 2012 20:42:46 +0000 (20:42 +0000)]
arm: fix compilation warnings

* configure.ac: Define SIZEOF_LONG.
* signal.c (sys_rt_sigaction) [SUPPORTED_PERSONALITIES > 1]: Help
compiler to optimize out unreachable code that is not expected to work
on platforms where sizeof(long) <= 4.

12 years agotests: robustify again buggy shells
Dmitry V. Levin [Thu, 15 Mar 2012 20:17:49 +0000 (20:17 +0000)]
tests: robustify again buggy shells

* tests/init.sh (check_strace): Use "${parameter:-word}" shell syntax
instead of "${parameter-word}".

Reported-by: Mike Frysinger <vapier@gentoo.org>
12 years agoimprove ifdef check with decode_subcall
Mike Frysinger [Thu, 15 Mar 2012 05:09:19 +0000 (01:09 -0400)]
improve ifdef check with decode_subcall

Use the same ifdef logic around the call sites of decode_subcall()
to protect the definition of the func itself.  This fixes warnings
for targets like hppa which don't use this func.

* syscall.c (decode_subcall): Wrap in SYS_socket_subcall and
SYS_ipc_subcall define checks.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
12 years agoalpha: fix decode of osf_sigprocmask
Mike Frysinger [Thu, 15 Mar 2012 04:45:33 +0000 (00:45 -0400)]
alpha: fix decode of osf_sigprocmask

The alpha sigprocmask syscall is special in that it comes from OSF rather
than the style that everyone else uses.

Tested with this simple code:
$ cat test.c
#include <signal.h>
main() {
sigset_t set, oldset;
sigemptyset(&set);
sigaddset(&set, SIGINT);
sigaddset(&set, SIGHUP);
sigprocmask(SIG_SETMASK, &set, &oldset);
sigprocmask(SIG_UNBLOCK, &oldset, &set);
sleep(3);
}
$ gcc test.c && ./strace ./a.out
...
osf_sigprocmask(SIG_SETMASK, [HUP INT]) = 0 (old mask [])
osf_sigprocmask(SIG_UNBLOCK, [])        = 0x3 (old mask [HUP INT])
osf_sigprocmask(SIG_BLOCK, [CHLD])      = 0x3 (old mask [HUP INT])
...

* linux/alpha/syscallent.h: Call sys_sigprocmask for osf_sigprocmask,
and change number of arguments to two.
* signal.c (sys_sigprocmask): Fix decoding of alpha osf sigprocmask.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
12 years agoFix array size calculation in previous commit
Denys Vlasenko [Thu, 15 Mar 2012 17:11:51 +0000 (18:11 +0100)]
Fix array size calculation in previous commit

* pathtrace.c (getfdpath): Fix array size calculation.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agopathtrace_select() is never called with NULL, remove dead code
Denys Vlasenko [Thu, 15 Mar 2012 17:03:56 +0000 (18:03 +0100)]
pathtrace_select() is never called with NULL, remove dead code

pathtrace_select() is only called for -P FILE options,
and FILE is never a NULL pointer.

   text    data     bss     dec     hex filename
 239453     672   19012  259137   3f441 strace.before
 239329     672   19012  259013   3f3c5 strace

* pathtrace.c (pathtrace_select): Remove "if (path == NULL)...".
(pathtrace_select): Remove code which only executes if path == NULL.
The code was also buggy, it can free non-malloced pointer.
(getfdpath): Simplify snprintf to sprintf.
(pathmatch): Use strcmp() == 0 idiom for string equality test.
(pathtrace_match): Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agomanpage: remove bugs which are fixed
Denys Vlasenko [Thu, 15 Mar 2012 16:32:56 +0000 (17:32 +0100)]
manpage: remove bugs which are fixed

"A traced process ignores SIGSTOP" - fixed, expected to be in linux-3.4.x.
"A traced process which tries to block SIGTRAP will be sent a SIGSTOP
in an attempt to force continuation of tracing." - not needed
and no longer done.
"On Linux, exciting as it would be, tracing the init process is forbidden"
- not true anymore.
"When a traced process receives a SIGTRAP signal not
associated with tracing, strace will not report that signal correctly."
- not true anymore.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoSimplify SIGCHLD handler setting
Denys Vlasenko [Thu, 15 Mar 2012 16:27:49 +0000 (17:27 +0100)]
Simplify SIGCHLD handler setting

* strace.c (init): Set SIGCHLD to SIG_DFL earlier.
(startup_child): Do not bother restoring SIGCHLD handler.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoWhen reporting signals, use short signal names (SIGfoo) instead of strerror
Denys Vlasenko [Thu, 15 Mar 2012 16:24:49 +0000 (17:24 +0100)]
When reporting signals, use short signal names (SIGfoo) instead of strerror

* defs.h: Remove strsignal declaration.
* signal.c: Better check for SI_FROMUSER define.
* strace.c (strerror): Remove this function.
(trace): Use short signal names (SIGfoo) instead of strerror.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoRemove TODO file: it's eleven years old and completely outdated
Denys Vlasenko [Thu, 15 Mar 2012 14:55:33 +0000 (15:55 +0100)]
Remove TODO file: it's eleven years old and completely outdated

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoClean up defs.h order. No code changes
Denys Vlasenko [Thu, 15 Mar 2012 14:02:49 +0000 (15:02 +0100)]
Clean up defs.h order. No code changes

* defs.h: Group together related declarations. No code changes.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoFix lame kernel version checking code
Denys Vlasenko [Thu, 15 Mar 2012 13:36:28 +0000 (14:36 +0100)]
Fix lame kernel version checking code

The code "os_release[0] >= '3'" is not good for any
finer-grained checks such as "kernel >= 3.2.1".
Let's proactively fix it.

* strace.c: Change os_release from string to integer.
(get_os_release): Parse uname.release to KERNEL_VERSION
representation.
(init): Convert kernel version check to KERNEL_VERSION.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoExperimental support for "detach on execve" feature
Denys Vlasenko [Thu, 15 Mar 2012 12:44:17 +0000 (13:44 +0100)]
Experimental support for "detach on execve" feature

* strace.c: Define new detach_on_execve, skip_startup_execve bool variables.
(init): Set detach_on_execve on -b, set skip_startup_execve if
"strace PROG" form is used.
(trace): Detach from process if -b and we see PTRACE_EVENT_EXEC event.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoSimple fixes.
Denys Vlasenko [Thu, 15 Mar 2012 12:39:05 +0000 (13:39 +0100)]
Simple fixes.

* strace.c (usage): Document -d; document that -F is deprecated.
(droptcb): Print "<detached ...>" correctly for non-ff mode too.
(detach): Suppress a warning.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoRemove an outdated comment
Denys Vlasenko [Thu, 15 Mar 2012 12:02:31 +0000 (13:02 +0100)]
Remove an outdated comment

* defs.h: Remove an outdated comment.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoRemove extra include directives. No code changes.
Denys Vlasenko [Thu, 15 Mar 2012 11:56:25 +0000 (12:56 +0100)]
Remove extra include directives. No code changes.

* defs.h: Include <signal.h> unconditionally.
Other files were doing it unconditionally, so no harm done.
* bjm.c: Remove system includes which are already included by defs.h.
* pathtrace.c: Likewise.
* process.c: Likewise.
* signal.c: Likewise.
* strace.c: Likewise.
* stream.c: Likewise.
* syscall.c: Likewise.
* system.c: Likewise.
* util.c: Likewise.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoTidy up order of includes; make bool variables explicit.
Denys Vlasenko [Thu, 15 Mar 2012 11:49:52 +0000 (12:49 +0100)]
Tidy up order of includes; make bool variables explicit.

Bool variables are more compact in data and (on x86) on code too:

   text    data     bss     dec     hex filename
 237950     676   19044  257670   3ee86 strace.before
 237838     676   19012  257526   3edf6 strace

* defs.h: Group library includes at the top of the file.
Rename dtime to Tflag, debug to debug_flag.
Change debug_flag,Tflag,qflag,not_failing_only,show_fd_path,tracing_paths
variable declarations from int to bool.
* strace.c: Change corresponding definitions. Do the same for static
variables iflag,rflag,print_pid_pfx.
Rename dtime to Tflag, debug to debug_flag.
* syscall.c: Rename dtime to Tflag, debug to debug_flag.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
12 years agoFix compiler warnings about breaking strict-aliasing rules
Dmitry V. Levin [Thu, 15 Mar 2012 02:03:36 +0000 (02:03 +0000)]
Fix compiler warnings about breaking strict-aliasing rules

* system.c (sys_capget, sys_capset): Use proxy unions to cast long*
pointers to cap_user_header_t and cap_user_data_t pointers without
breaking strict-aliasing rules.

Reported-by: Mike Frysinger <vapier@gentoo.org>
12 years agoppc64: drop unused pid variable
Mike Frysinger [Thu, 15 Mar 2012 00:16:13 +0000 (20:16 -0400)]
ppc64: drop unused pid variable

* syscall.c (get_scno) [POWERPC64]: Delete unused pid variable.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
12 years agoia64: fix compilation warnings
Dmitry V. Levin [Thu, 15 Mar 2012 01:01:25 +0000 (01:01 +0000)]
ia64: fix compilation warnings

* linux/ia64/syscallent.h: Remove improper defines and undefs.

Reported-by: Mike Frysinger <vapier@gentoo.org>
12 years agoEnsure that SWAP_FLAG_* constants are defined
Dmitry V. Levin [Thu, 15 Mar 2012 00:52:22 +0000 (00:52 +0000)]
Ensure that SWAP_FLAG_* constants are defined

* file.c: Define those of SWAP_FLAG_* constants which are not yet
provided by <sys/swap.h>.

Reported-by: Mike Frysinger <vapier@gentoo.org>
12 years agoEnhance *listxattr syscalls decoding
Dmitry V. Levin [Wed, 14 Mar 2012 16:34:32 +0000 (16:34 +0000)]
Enhance *listxattr syscalls decoding

* file.c (print_xattr_list): New function.
(sys_listxattr, sys_flistxattr): Use it.