Fix translate_path(): return -EBADF if the file descriptor is not valid.

Before:

    $ proot ./ltp-full-20130503/testcases/kernel/syscalls/fchdir/fchdir02
    fchdir02    1  TFAIL  :  call failed unexpectedly: TEST_ERRNO=EPERM(1): Operation not permitted

Now:

    $ proot ./ltp-full-20130503/testcases/kernel/syscalls/fchdir/fchdir02
    fchdir02    1  TPASS  :  failed as expected with EBADF
Fix translate_path(): return correct errno when dir_fd points to an unreachable path.

Before:

    $ proot ./ltp-full-20130503/testcases/kernel/syscalls/linkat/linkat01
    [...]
    linkat01   16  TFAIL  :  linkat failed unexpectedly; expected 2 - No such file or directory: TEST_ERRNO=ENOTDIR(20): Not a directory
    linkat01   17  TFAIL  :  linkat failed unexpectedly; expected 2 - No such file or directory: TEST_ERRNO=ENOTDIR(20): Not a directory
    [...]

Now:

    $ proot ./ltp-full-20130503/testcases/kernel/syscalls/linkat/linkat01
    [...]
    linkat01   16  TPASS  :  linkat failed as expected: TEST_ERRNO=ENOENT(2): No such file or directory
    linkat01   17  TPASS  :  linkat failed as expected: TEST_ERRNO=ENOENT(2): No such file or directory
    [...]
Fix the sysenter handling of socket syscalls: return correct errno.

Before:

    $ proot -w ./ltp-full-20130503/ ./runltp -f syscalls
    [...]
    accept01    4  TFAIL  :  invalid salen ; returned -1 (expected -1), errno 5 (expected 22)
    [...]
    getpeername01    5  TFAIL  :  invalid aligned salen ; returned -1 (expected -1), errno 5 (expected 14)
    getpeername01    6  TFAIL  :  invalid unaligned salen ; returned -1 (expected -1), errno 5 (expected 14)
    [...]
    getsockname01    4  TFAIL  :  invalid aligned salen ; returned -1 (expected -1), errno 5 (expected 14)
    getsockname01    5  TFAIL  :  invalid unaligned salen ; returned -1 (expected -1), errno 5 (expected 14)
    [...]

Now:

    $ proot -w ./ltp-full-20130503/ ./runltp -f syscalls
    [...]
    accept01    4  TPASS  :  invalid salen successful
    [...]
    getpeername01    5  TPASS  :  invalid aligned salen successful
    getpeername01    6  TPASS  :  invalid unaligned salen successful
    [...]
    getsockname01    4  TPASS  :  invalid aligned salen successful
    getsockname01    5  TPASS  :  invalid unaligned salen successful
    [...]
Fix expand_interp(): don't overwrite argv[0] when it's the NULL terminator.

Before:

    $ proot -R rootfs -w ltp-full-20130503/testcases/bin ./execve04 -F ./test3
    proot: ./tracee/array.c:415: push_array: Assertion `local_count < array->length + 1' failed.

Now:

    $ proot -R rootfs -w ltp-full-20130503/testcases/bin ./execve04 -F ./test3
    Hello World
    execve04    1  TFAIL  :  execve succeeded, expected failure

At least, it doesn't abort anymore...
Introduce read_path(), a new helper for read_string(PATH_MAX).
Introduce substitute_path_prefix(), extracted from substitute_binding().
Fix the sysexit handling of rename[at] when used to move [a prefix of] cwd.

Before:

    $ proot ./ltp-full-20130503/testcases/kernel/syscalls/inotify/inotify02
    inotify02    8  TBROK  :  unlink(test_file2) failed: errno=ENOENT(2): No such file or directory
    inotify02    9  TBROK  :  Remaining cases broken
    inotify02    0  TWARN  :  tst_rmdir: rmobj(/tmp/inoHPzj80) failed: lstat(/tmp/inoHPzj80) failed; errno=2: No such file or directory

Now:

    $ proot ./ltp-full-20130503/testcases/kernel/syscalls/inotify/inotify02
    inotify02    1  TPASS  :  get event: wd=1 mask=40000004 cookie=0 len=0 name=""
    inotify02    2  TPASS  :  get event: wd=1 mask=100 cookie=0 len=16 name="test_file1"
    inotify02    3  TPASS  :  get event: wd=1 mask=20 cookie=0 len=16 name="test_file1"
    inotify02    4  TPASS  :  get event: wd=1 mask=8 cookie=0 len=16 name="test_file1"
    inotify02    5  TPASS  :  get event: wd=1 mask=40 cookie=11309409 len=16 name="test_file1"
    inotify02    6  TPASS  :  get event: wd=1 mask=80 cookie=11309409 len=16 name="test_file2"
    inotify02    7  TPASS  :  get event: wd=1 mask=800 cookie=0 len=0 name=""
    inotify02    8  TPASS  :  get event: wd=1 mask=200 cookie=0 len=16 name="test_file2"
    inotify02    9  TPASS  :  get event: wd=1 mask=800 cookie=0 len=0 name=""
Fix off-by-one in read/write_data() when there are no "trailing" bytes.

PEEKDATA might fail due to an illegal access.  It seems I was
(un)lucky so far: this could happen only on a page boundary.
kompat: discard AT_SYSINFO to ensure faked OS release is read through uname(2).

AT_SYSINFO* vectors can be used to get the OS release number from
memory instead of from the uname syscall, and only this latter is
currently hooked by PRoot.

PRoot can now run recent programs (eg. from Ubuntu 13.04 x86_64) on
obsolete platforms (eg. RHEL 5 x86_64) without any further tweaks
(previously a binary patch against the ELF interpreter was required).
Fix the syscall number setting mechanism on ARM.

On ARM, the PTRACE_SET_SYSCALL request is required to change effectively
the syscall number during a ptrace-stop.  Moreover the syscall number
has to be valid (i.e. it can't be -2).

Reported-by: Corbin Champion <corbinlc@gmail.com>
Add a new entry into the roadmap.
Introduce a mechanism to execute forged syscalls after an actual syscall.

This will be typically useful to the kompat extension: for instance "pipe2"
can be emulated by chaining "pipe" and "fcntl".
Improve forward kernel compatibility, a.k.a. "kompat" extension or "-k" option.

A lot of "new" syscalls can be emulated with "old" syscalls + fcntl(2).
For instance:

    pipe2(fds, O_CLOEXEC | O_NONBLOCK);

can be emulated with 5 syscalls:

    pipe(fds);
    fcntl(fds[0], F_SETFD, FD_CLOEXEC);
    fcntl(fds[0], F_SETFL, O_NONBLOCK);
    fcntl(fds[1], F_SETFD, FD_CLOEXEC);
    fcntl(fds[1], F_SETFL, O_NONBLOCK);

There is still some remaining work:

- epoll_pwait: the "sigprocmask" behaviour is not emulated yet.

- eventfd2: the flag EFD_SEMAPHORE is not emulated yet.

- pselect6: the "timeout" parameter must be converted from "struct
            timeval" into "struct timespec".

- recv: the MSG_CMSG_CLOEXEC flag is not emulated yet.
Pass clone(2) flags down to INHERIT_* extension events.

This is useful to create different configuration according to the
clone(2) flags.
Make the -0 option fake the success of setgroups*(2).

Allows to run initgroups.

v2: commit message and indentation fix.
Signed-off-by: Cédric VINCENT <cedric.vincent@st.com>
Don't abort when a "spurious" sysexit event from a signaled tracee is reported.

When a tracee gets signaled during its "sysenter" stage, all ptrace
requests return "No such process", so PRoot removes its entry from the
list of tracees.  However, the kernel does report a "sysexit" event,
and there are no way of checking if this is a spurious event since all
ptrace requests succeed:

    1. ptrace event: sysenter (SIGTRAP | 0x80)

    2. the current tracee gets signaled

    3. ptrace request -> "No such process"

    4. ptrace event: sysexit (SIGTRAP | 0x80)

    5. ptrace request -> OK

    6. ptrace event: signaled

The solution is to check whether the tracee structure is sane.
Fix spelling
Add support for multiple command line interfaces (PRoot, CARE, DepsTracker, ...)
Split the generic CLI support apart from the PRoot specific part.
Move CLI related sources into a dedicated module.