ptrace: move SIGTRAP on exec(2) logic to ptrace_event()
authorTejun Heo <tj@kernel.org>
Fri, 17 Jun 2011 14:50:36 +0000 (16:50 +0200)
committerOleg Nesterov <oleg@redhat.com>
Wed, 22 Jun 2011 17:26:28 +0000 (19:26 +0200)
Move SIGTRAP on exec(2) logic from tracehook_report_exec() to
ptrace_event().  This is part of changes to make ptrace_event()
smarter and handle ptrace event related details in one place.

This doesn't introduce any behavior change.

Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
include/linux/ptrace.h
include/linux/tracehook.h

index 18feac6f441ec27d1166bf4206b7abc83405def3..b546fd6c35068528fc142ea3d155376477a7ef8e 100644 (file)
@@ -172,17 +172,17 @@ static inline bool ptrace_event_enabled(struct task_struct *task, int event)
  * Check whether @event is enabled and, if so, report @event and @message
  * to the ptrace parent.
  *
- * Returns nonzero if we did a ptrace notification, zero if not.
- *
  * Called without locks.
  */
-static inline int ptrace_event(int event, unsigned long message)
+static inline void ptrace_event(int event, unsigned long message)
 {
-       if (likely(!ptrace_event_enabled(current, event)))
-               return false;
-       current->ptrace_message = message;
-       ptrace_notify((event << 8) | SIGTRAP);
-       return true;
+       if (unlikely(ptrace_event_enabled(current, event))) {
+               current->ptrace_message = message;
+               ptrace_notify((event << 8) | SIGTRAP);
+       } else if (event == PTRACE_EVENT_EXEC && unlikely(current->ptrace)) {
+               /* legacy EXEC report via SIGTRAP */
+               send_sig(SIGTRAP, current, 0);
+       }
 }
 
 /**
index 7d38571b0c0595e43634f6b2f0584bcd6a89a5f1..3b68aa842a92c9e87ce2c05e6295c782dc4dfc01 100644 (file)
@@ -201,9 +201,7 @@ static inline void tracehook_report_exec(struct linux_binfmt *fmt,
                                         struct linux_binprm *bprm,
                                         struct pt_regs *regs)
 {
-       if (!ptrace_event(PTRACE_EVENT_EXEC, 0) &&
-           unlikely(current->ptrace & PT_PTRACED))
-               send_sig(SIGTRAP, current, 0);
+       ptrace_event(PTRACE_EVENT_EXEC, 0);
 }
 
 /**