summaryrefslogtreecommitdiffstats
path: root/runtime/task_finder.c
diff options
context:
space:
mode:
authorFrank Ch. Eigler <fche@elastic.org>2008-05-14 14:35:48 -0400
committerFrank Ch. Eigler <fche@elastic.org>2008-05-14 14:35:48 -0400
commit0fe2b97c7b967d833b5588dbf1ef763bb4440ed3 (patch)
treefcce9345c9ebacb7d5bc1f510f155bfdcea08dc4 /runtime/task_finder.c
parenta007b4068d20af2d4488d54bf3ef2edbf47f2f06 (diff)
parentc3799d720b60bd74a60de4addcd0d77a90f7842a (diff)
downloadsystemtap-steved-0fe2b97c7b967d833b5588dbf1ef763bb4440ed3.tar.gz
systemtap-steved-0fe2b97c7b967d833b5588dbf1ef763bb4440ed3.tar.xz
systemtap-steved-0fe2b97c7b967d833b5588dbf1ef763bb4440ed3.zip
Merge commit 'origin/master' into pr6429-comp-unwindsyms
* commit 'origin/master': PR 5955 - Accept ; terminated globals Factored returnval() out of returnstr(), for use in dwarfless probing. Converted more aliases to use arg numbers instead of names. In particular, Revert "PR6487: extend blacklist with relay/timer subsystem" Add syscalls_by_pid.meta, syscalls_by_proc.meta, PR6487: extend blacklist with relay/timer subsystem Adjust iotime.meta description. * iotime.meta: New. Fix for PR 6500. Update ChangeLog * sleeptime.meta, wait4time.meta: New. systemtap.examples futexes.meta change futex.stp to futexes.stp. In ioblock.stp ioblock.end set bytes_done depending on kernel version. PR6492: make listing mode warning-free PR5648: Fix unaligned access warning in stp_print_flush on ia64 PR5648: Fix memcpy's endianess issue. futexes.meta, nettop.meta, pf2.meta: New. Clean up output.
Diffstat (limited to 'runtime/task_finder.c')
-rw-r--r--runtime/task_finder.c110
1 files changed, 78 insertions, 32 deletions
diff --git a/runtime/task_finder.c b/runtime/task_finder.c
index 6d79c98a..2c27e4a3 100644
--- a/runtime/task_finder.c
+++ b/runtime/task_finder.c
@@ -231,43 +231,16 @@ __stp_utrace_attach(struct task_struct *tsk,
return rc;
}
-static u32
-__stp_utrace_task_finder_report_clone(struct utrace_attached_engine *engine,
- struct task_struct *parent,
- unsigned long clone_flags,
- struct task_struct *child)
-{
- struct utrace_attached_engine *child_engine;
- struct mm_struct *mm;
-
- if (atomic_read(&__stp_task_finder_state) != __STP_TF_RUNNING)
- return UTRACE_ACTION_RESUME;
-
- // On clone, attach to the child.
- (void) __stp_utrace_attach(child, engine->ops, 0,
- __STP_UTRACE_TASK_FINDER_EVENTS);
- return UTRACE_ACTION_RESUME;
-}
-
-static u32
-__stp_utrace_task_finder_report_exec(struct utrace_attached_engine *engine,
- struct task_struct *tsk,
- const struct linux_binprm *bprm,
- struct pt_regs *regs)
+static inline void
+__stp_utrace_attach_match_filename(struct task_struct *tsk,
+ const char * const filename)
{
size_t filelen;
struct list_head *tgt_node;
struct stap_task_finder_target *tgt;
int found_node = 0;
- if (atomic_read(&__stp_task_finder_state) != __STP_TF_RUNNING)
- return UTRACE_ACTION_RESUME;
-
- // On exec, check bprm
- if (bprm->filename == NULL)
- return UTRACE_ACTION_RESUME;
-
- filelen = strlen(bprm->filename);
+ filelen = strlen(filename);
list_for_each(tgt_node, &__stp_task_finder_list) {
tgt = list_entry(tgt_node, struct stap_task_finder_target,
list);
@@ -275,7 +248,7 @@ __stp_utrace_task_finder_report_exec(struct utrace_attached_engine *engine,
// here, since they are handled at startup.
if (tgt != NULL && tgt->pathlen > 0
&& tgt->pathlen == filelen
- && strcmp(tgt->pathname, bprm->filename) == 0) {
+ && strcmp(tgt->pathname, filename) == 0) {
found_node = 1;
break;
}
@@ -309,6 +282,79 @@ __stp_utrace_task_finder_report_exec(struct utrace_attached_engine *engine,
cb_tgt->engine_attached = 1;
}
}
+}
+
+static u32
+__stp_utrace_task_finder_report_clone(struct utrace_attached_engine *engine,
+ struct task_struct *parent,
+ unsigned long clone_flags,
+ struct task_struct *child)
+{
+ int rc;
+ struct mm_struct *mm;
+ char *mmpath_buf;
+ char *mmpath;
+
+ if (atomic_read(&__stp_task_finder_state) != __STP_TF_RUNNING)
+ return UTRACE_ACTION_RESUME;
+
+ // On clone, attach to the child.
+ rc = __stp_utrace_attach(child, engine->ops, 0,
+ __STP_UTRACE_TASK_FINDER_EVENTS);
+ if (rc != 0 && rc != EPERM)
+ return UTRACE_ACTION_RESUME;
+
+ /* Grab the path associated with this task. */
+ mm = get_task_mm(child);
+ if (! mm) {
+ /* If the thread doesn't have a mm_struct, it is
+ * a kernel thread which we need to skip. */
+ return UTRACE_ACTION_RESUME;
+ }
+
+ // Allocate space for a path
+ mmpath_buf = _stp_kmalloc(PATH_MAX);
+ if (mmpath_buf == NULL) {
+ _stp_error("Unable to allocate space for path");
+ return UTRACE_ACTION_RESUME;
+ }
+
+ // Grab the path associated with the new task
+ mmpath = __stp_get_mm_path(mm, mmpath_buf, PATH_MAX);
+ mmput(mm); /* We're done with mm */
+ if (IS_ERR(mmpath)) {
+ rc = -PTR_ERR(mmpath);
+ _stp_error("Unable to get path (error %d) for pid %d",
+ rc, (int)child->pid);
+ }
+ else {
+ __stp_utrace_attach_match_filename(child, mmpath);
+ }
+
+ _stp_kfree(mmpath_buf);
+ return UTRACE_ACTION_RESUME;
+}
+
+static u32
+__stp_utrace_task_finder_report_exec(struct utrace_attached_engine *engine,
+ struct task_struct *tsk,
+ const struct linux_binprm *bprm,
+ struct pt_regs *regs)
+{
+ size_t filelen;
+ struct list_head *tgt_node;
+ struct stap_task_finder_target *tgt;
+ int found_node = 0;
+
+ if (atomic_read(&__stp_task_finder_state) != __STP_TF_RUNNING)
+ return UTRACE_ACTION_RESUME;
+
+ // On exec, check bprm
+ if (bprm->filename == NULL)
+ return UTRACE_ACTION_RESUME;
+
+ __stp_utrace_attach_match_filename(tsk, bprm->filename);
+
return UTRACE_ACTION_RESUME;
}