Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kerneltoast/2ec6a8d8c4d180cd30a9ce98773c0d08 to your computer and use it in GitHub Desktop.
Save kerneltoast/2ec6a8d8c4d180cd30a9ce98773c0d08 to your computer and use it in GitHub Desktop.
From b90d2cb2bf4a9162459bfe3e68f08ea7d7715bd5 Mon Sep 17 00:00:00 2001
From: Sultan Alsawaf <sultan@openresty.com>
Date: Thu, 29 Oct 2020 10:40:34 -0700
Subject: [PATCH] task_finder2: don't attach to forked children when a PID is
specified
When we have a PID specified for tracing and a fork occurs from our
target PID, the forked child will have the same exe as our target and
will subsequently get matched and attached to by
__stp_utrace_attach_match_filename(). Attaching to these children is not
productive though, since we are only interested in a specific process.
Therefore, as an optimization, only bother trying to attach to forked
children when a PID is *not* specified. When a PID is specified and
match_tsk != path_tsk, we know that a fork just occurred and match_tsk
is the child of path_tsk, in which case we should just skip attaching to
match_tsk.
---
runtime/linux/task_finder2.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/runtime/linux/task_finder2.c b/runtime/linux/task_finder2.c
index 9960eb06d..fbfd2c5e6 100644
--- a/runtime/linux/task_finder2.c
+++ b/runtime/linux/task_finder2.c
@@ -906,7 +906,8 @@ __stp_utrace_attach_match_tsk(struct task_struct *path_tsk,
printk(KERN_ERR "%s:%d entry\n", __FUNCTION__, __LINE__);
#endif
if (path_tsk == NULL || path_tsk->pid <= 0
- || match_tsk == NULL || match_tsk->pid <= 0)
+ || match_tsk == NULL || match_tsk->pid <= 0
+ || (_stp_target && match_tsk != path_tsk))
return;
// Grab the path associated with the path_tsk.
--
2.29.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment