This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Fix PR 6732 - Add autoconf-real-parent.c check


Hi,

The following patch adds a runtime configure check for the real_parent
field of the task_struct. As described in PR 6732 some (utrace enabled)
kernels don't have this field, but have a parent field, which give the
information that mainline kernels have in the real_parent field. This
check defines STAPCONF_REAL_PARENT which is then used when the
runtime/tapset code is build to detect what field to use.

ChangeLog
2008-07-09  Mark Wielaard  <mwielaard@redhat.com>

    PR 6732
    * buildrun.cxx (compile_pass): Define STAPCONF_REAL_PARENT by
    calling autoconf-real-parent.c

runtime/ChangeLog
2008-07-09  Mark Wielaard  <mwielaard@redhat.com>

    PR 6732
    * autoconf-real-parent.c: New file.
    * task_finder.c (__stp_utrace_task_finder_report_exec): Define
    real_parent using STAPCONF_REAL_PARENT. Undefine when no longer
    needed.

tapset/ChangeLog
2008-07-09  Mark Wielaard  <mwielaard@redhat.com>

    PR 6732
    * context.stp (ppid): Use STAPCONF_REAL_PARENT.
    (pexecname): Likewise.
    * task.stp (task_parent): Likewise.

This makes the test results on mainline and newer fedora 9 2.6.25+
kernels much nicer. Tested against a 2.6.24.7-92.fc8 (parent field) and
2.6.25.9-76.fc9.i686 (real_parent field).

Committed and pushed,

Mark
diff --git a/buildrun.cxx b/buildrun.cxx
index a39f2b6..3183fe6 100644
--- a/buildrun.cxx
+++ b/buildrun.cxx
@@ -96,6 +96,7 @@ compile_pass (systemtap_session& s)
   o << module_cflags << " += $(call stap_check_build, $(SYSTEMTAP_RUNTIME)/autoconf-nameidata.c, -DSTAPCONF_NAMEIDATA_CLEANUP,)" << endl;
   o << module_cflags << " += $(call stap_check_build, $(SYSTEMTAP_RUNTIME)/autoconf-unregister-kprobes.c, -DSTAPCONF_UNREGISTER_KPROBES,)" << endl;
   o << module_cflags << " += $(call stap_check_build, $(SYSTEMTAP_RUNTIME)/autoconf-module-nsections.c, -DSTAPCONF_MODULE_NSECTIONS,)" << endl;
+  o << module_cflags << " += $(call stap_check_build, $(SYSTEMTAP_RUNTIME)/autoconf-real-parent.c, -DSTAPCONF_REAL_PARENT,)" << endl;
 #if 0
   /* NB: For now, the performance hit of probe_kernel_read/write (vs. our
    * homegrown safe-access functions) is deemed undesireable, so we'll skip
diff --git a/runtime/autoconf-real-parent.c b/runtime/autoconf-real-parent.c
new file mode 100644
index 0000000..010792c
--- /dev/null
+++ b/runtime/autoconf-real-parent.c
@@ -0,0 +1,15 @@
+/* PR6732 - In RHEL5 and F[678] kernels, the utrace patch removed the
+ * ptrace-related parent field and renamed real_parent to parent.  In
+ * future Fedora kernels, there may or may not be a ptrace-related
+ * parent field, but the real useful field will go back to being called
+ * real_parent.
+ */
+#include <linux/sched.h>
+
+struct task_struct t;
+
+void foo (void)
+{
+  struct task_struct *p;
+  p = t.real_parent; 
+}
diff --git a/runtime/task_finder.c b/runtime/task_finder.c
index 316a9bc..fc573eb 100644
--- a/runtime/task_finder.c
+++ b/runtime/task_finder.c
@@ -485,7 +485,7 @@ __stp_utrace_task_finder_report_exec(struct utrace_attached_engine *engine,
 	// '/bin/bash' clones and then execs '/bin/ls'.  If the user
 	// was probing '/bin/bash', the cloned thread is still
 	// '/bin/bash' up until the exec.
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
+#if ! defined(STAPCONF_REAL_PARENT)
 #define real_parent parent
 #endif
 	if (tsk != NULL && tsk->real_parent != NULL
@@ -494,6 +494,7 @@ __stp_utrace_task_finder_report_exec(struct utrace_attached_engine *engine,
 		// *could* call exec (although they aren't supposed to).
 		__stp_utrace_attach_match_tsk(tsk->real_parent, tsk, 0, 1);
 	}
+#undef real_parent
 
 	// We assume that all exec's are exec'ing a new process.  Note
 	// that we don't use bprm->filename, since that path can be
diff --git a/tapset/context.stp b/tapset/context.stp
index 10c5222..017c934 100644
--- a/tapset/context.stp
+++ b/tapset/context.stp
@@ -41,11 +41,19 @@ function tid:long () %{ /* pure */
 %}
 
 function ppid:long () %{ /* pure */
+#if defined(STAPCONF_REAL_PARENT)
+	THIS->__retvalue = current->real_parent->tgid;
+#else
 	THIS->__retvalue = current->parent->tgid;
+#endif
 %}
 
 function pexecname:string () %{ /* pure */
+#if defined(STAPCONF_REAL_PARENT)
+	strlcpy (THIS->__retvalue, current->real_parent->comm, MAXSTRINGLEN);
+#else
 	strlcpy (THIS->__retvalue, current->parent->comm, MAXSTRINGLEN);
+#endif
 %}
 
 function gid:long () %{ /* pure */
diff --git a/tapset/task.stp b/tapset/task.stp
index d89729e..9215e83 100644
--- a/tapset/task.stp
+++ b/tapset/task.stp
@@ -23,7 +23,11 @@ function task_current:long () %{ /* pure */
 // Return the parent task_struct of the given task
 function task_parent:long (task:long) %{ /* pure */
     struct task_struct *t = (struct task_struct *)(long)THIS->task;
+#if defined(STAPCONF_REAL_PARENT)
+    THIS->__retvalue = (long)kread(&(t->real_parent));
+#else
     THIS->__retvalue = (long)kread(&(t->parent));
+#endif
     CATCH_DEREF_FAULT();
 %}
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]