strace.py terminates with KeyError when tracing openssh server
vstinner opened this issue · 10 comments
Originally reported by: Pavel Šimerda (Bitbucket: pavlix, GitHub: pavlix)
For a network application testing project, I need to ptrace both client and server processes but tracing the SSH server apparently fails. So I also tried with strace.py
and it quits with a traceback.
Reproducer:
Run the two comments in two terminal emulators alpha and beta. The behavior seems to be the same whether you make sure the SSH authentication succeeds or no.
alpha# ./strace.py -f -o trace.python-ptrace -- which sshd
-D
beta$ ssh localhost true
Expected result:
With -D option, SSH server should run until you kill it and accept any incoming connections.
Actual result:
The first connection results in crashing the server with a traceback.
Original comment by Victor Stinner (Bitbucket: haypo, GitHub: haypo):
Hum, ProcessSignal.childExit() uses getSignalInfo() on Linux. siginfo class is defined ptrace.binding.linux_struct, for SIGCHLD, childExit() uses siginfo._sigchld especially siginfo._sigchld.status.
I checked: if the child exits with exit code 3, siginfo._sigchld.status is 3. But if the child is killed by SIGKILL, siginfo._sigchld is 9: it's also possitive.
You need to find the flag to check if the child exited with an exit code or was killed by a signal.
Original comment by Pavel Šimerda (Bitbucket: pavlix, GitHub: pavlix):
In my opinion those information are not part of si_status
but rather si_code
. When si_code == CLD_EXITED
, si_status
contains the exit code. Also ptrace()
and SIGTRAP
are mentioned in the manpage. The structure is apparently different than the status passed by wait()
.
Original comment by Victor Stinner (Bitbucket: haypo, GitHub: haypo):
Modifying formatProcessStatus() is wrong: if you get an exit code and not a status, the caller must be modified to not call formatProcessStatus(). According to trace.ptrace, the caller is signal_reason.py at line 154 (init): message = formatProcessStatus(status, "Child process %s" % pid).
The project moved to GitHub. Please reopen an issue there, or even better a pull request :-) https://github.com/haypo/python-ptrace