Fix handling of test/threaded_execve.c testcase

Since 3.0, Linux has a way to identify which thread execve'ed.
This patch makes use of it in order to properly dispose
of disappeared ("superseded") thread leader,
and replace it with execve'ed thread.

Before this patch, strace was "leaking" thread which exec'ed.
It was thinking that it still runs. It would look like this:

18460 pause( <unfinished ...>     <=== thread leader
18466 execve("/proc/self/exe", ["exe", "exe"], [/* 47 vars */] <unfinished ...>
18465 +++ exited with 0 +++       <=== exits from other threads
18460 <... pause resumed> )             = 0

The last line is wrong: it's not pause resumed, it's execve resumed.
If thread leader would do exit instead of pause, it is much worse:
strace panics because it thinks it sees return from exit syscall!

And strace isn't aware 18466 (exec'ed thread) is gone.
It still thinks it's executes execve syscall.

* strace.c: New variable "static char *os_release".
(get_os_release): New static function.
(main): Call get_os_release to retrieve Linux version.
(trace): If we see PTRACE_EVENT_EXEC, retrieve old pid, and if it
differs from new one, free one of tcbs and print correct messages.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
1 file changed