nelhage / reptyr

Reparent a running program to a new terminal
MIT License
5.8k stars 215 forks source link

Fix Linux ptrace event handling #125

Closed shachaf closed 3 years ago

shachaf commented 3 years ago

The code was previously using (status >> 8) & PTRACE_EVENT_FORK to check for a fork event, but the event is in (status >> 16), and PTRACEEVENT* is an enumeration, not a bit mask. What was actually being tested was the low bit of the signal, which was always set (since SIGTRAP is 5).

Presumably the old code was working fine because the child PID is only used immediately after a fork call, but this event handling is more correct.