Speed up and explain fd_isset()

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Fix select decoding on e.g. 32-bit ppc process by 64-bit strace.

Added next_set_bit() function which finds the next set bit,
properly taking into account word size of the traced process.
Use it in decode_select() instead of fd_isset().
Also, properly round fdsize up to word size of traced process,
not to strace's word size.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Fix pathtrace_match() to match recent fixes to select decoding.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
sys_io_submit: stop traversing iocb vector after first failure.

The program may use a very large nr but supply either outright
invalid iocbpp[], or one with far fewer elements than nr.
We used to try reading iocbpp[i] until i == nr.
With this change, we stop on the first failure.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
sys_io_submit: simplify iocb_cmd_lookup() helper.

This helper returns two values (a string and an enum).
The caller prints the string. It's simpler to just print
the string in the caller itself. This eliminates
"return by reference" and more importantly, an intermediate
static string buffer for the string result.

Since function of the helper is different now,
it is renamed to tprint_lio_opcode().

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Stop using external libaio.h.

This change incorporates a partial copy instead
of using external libaio.h.
Why?
Because we want to properly decode 32-bit aio calls
by 64-bit strace. For that, we need more definitions than
libaio.h provides.
(These defs are not done yet, but will eventually be done).
Keeping our local 32-bit compat defs in sync with libaio.h
_without seeing libaio structs_ is hard/more bug prone.
A smaller benefit is that we don't need libaio installed.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Move io_* syscalls decoding to a separate file

* desc.c (sys_io_setup, sys_io_destroy, sys_io_submit, sys_io_cancel,
sys_io_getevents, declarations from libaio.h): Move to ...
* aio.c: new file.
* Makefile.am (strace_SOURCES): Add aio.c.
Include <sys/poll.h> only if there is no <poll.h>

* pathtrace.c: Do not include <sys/poll.h> if <poll.h> is available.
* stream.c: Likewise.
Assume "long long" availability

Most of the code already uses long long types unconditionally.

* configure.ac: Remove the check for long long.
* file.c (printstat64): Remove HAVE_LONG_LONG checks, use %llu format
string unconditionally.
Remove unused configure checks

* configure.ac (AC_CHECK_MEMBERS): Remove T_conn_res.QUEUE_ptr,
T_conn_res.ACCEPTOR_id, dqblk.dqb_curblocks, sigcontext.sc_hi2.
Make SIGEV_THREAD_ID decoding less glibc specific

SIGEV_THREAD_ID decoding requires access to an internal member of
struct sigevent.  There seems to be no portable way to do it besides
adding a configure check.

* configure.ac (AC_CHECK_MEMBERS): Check for
struct sigevent._sigev_un._pad and struct sigevent.__pad.
* time.c (printsigevent): Use an appropriate struct sigevent member
to print thread id.

Reported by John Spencer.
Use standard names of sched_param structure members

* process.c (sys_sched_setscheduler, sys_sched_getparam,
sys_sched_setparam): Use portable struct sched_param member name
sched_priority instead of glibc specific __sched_priority.

Reported by John Spencer.
Use struct sigcontext instead of struct sigcontext_struct

* configure.ac (AC_CHECK_TYPES): Remove struct sigcontext_struct.
* signal.c (sys_sigreturn) [S390 || S390X || POWERPC || ALPHA): Replace
struct sigcontext_struct with struct sigcontext.

Reported by John Spencer.
Remove unused code

* configure.ac (AC_CHECK_TYPES): Remove struct opthdr and
struct t_opthdr.
* net.c (print_sock_optmgmt): Remove.
Remove unused AC_OFF_T_IS_LONG_LONG configure check

* configure.ac: Remove AC_OFF_T_IS_LONG_LONG.
* m4/long_long.m4: Likewise.
Remove unneeded redefinitions of IPPROTO_* macros

IPPROTO_* macros are defined by <netinet/in.h>, no need to redefine
them.

* net.c (IPPROTO_EGP, IPPROTO_PUP, IPPROTO_IDP, IPPROTO_IGMP,
IPPROTO_RAW, IPPROTO_MAX): Remove.

Reported by John Spencer.
Make PTRACE_PEEKUSER/PTRACE_POKEUSER checks less glibc specific

* configure.ac (AC_CHECK_DECLS): Add PTRACE_PEEKUSER and
PTRACE_POKEUSER.
* defs.h: Define PTRACE_PEEKUSER and PTRACE_POKEUSER only if
they are not provided by <sys/ptrace.h>.

Reported by John Spencer.
Define printflock64 only if it is referenced by other code

* configure.ac (AC_CHECK_TYPES): Add struct flock64.
* desc.c (HAVE_F_SETLK64, HAVE_F_SETLKW64, HAVE_F_GETLK64): New macros.
[!HAVE_STRUCT_FLOCK64] (struct flock64): Define.
(printflock64): Define only if referenced by other code.
(sys_fcntl): Handle F_FREESP64, F_SETLK64, F_SETLKW64, and F_GETLK64 iff
these constants are defined and differ from their non-64bit versions.
Define truncate64, ftruncate64, and getdents64 decoders unconditionally

These decoders are referenced by most architectures, there were no
undefined references so far because _LFS64_LARGEFILE appears to be
always defined by glibc when _GNU_SOURCE is defined.

* file.c (sys_truncate64, sys_ftruncate64, sys_getdents64): Define
unconditionally.
Stop using _LFS64_LARGEFILE

There is only one place left in the code where strace guesses whether
libc provides LFS64 functions and structures.  The most natural thing to
do there is to check for _LARGEFILE64_SOURCE - the macro provided by
glibc.  Other libc implementations that provide nondegenerate LFS64
interfaces are expected to define this macro as well.

* defs.h (_LFS64_LARGEFILE): Remove.
* strace.c: Use _LARGEFILE64_SOURCE instead of _LFS64_LARGEFILE.