summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbitbake/bin/bitbake-runtask-strace8
-rw-r--r--meta/classes/image-swab.bbclass19
-rwxr-xr-xscripts/swabber-strace-attach30
3 files changed, 47 insertions, 10 deletions
diff --git a/bitbake/bin/bitbake-runtask-strace b/bitbake/bin/bitbake-runtask-strace
deleted file mode 100755
index 1741a84de2..0000000000
--- a/bitbake/bin/bitbake-runtask-strace
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/bash
-STRACE=`which strace`
-
-if [ ! -x "$STRACE" ]; then
- bitbake-runtask $1 $2 $3 $4
-else
- strace -f -o $TRACE_LOGFILE-$3.log -e trace=open,execve bitbake-runtask $1 $2 $3 $4
-fi
diff --git a/meta/classes/image-swab.bbclass b/meta/classes/image-swab.bbclass
index ec949ffe2e..b939ec4b45 100644
--- a/meta/classes/image-swab.bbclass
+++ b/meta/classes/image-swab.bbclass
@@ -2,7 +2,7 @@ HOST_DATA ?= "${TMPDIR}/host-contamination-data/"
SWABBER_REPORT ?= "${LOG_DIR}/swabber/"
SWABBER_LOGS ?= "${LOG_DIR}/contamination-logs"
TRACE_LOGDIR ?= "${SWABBER_LOGS}/${PACKAGE_ARCH}"
-export TRACE_LOGFILE = "${TRACE_LOGDIR}/${PN}-${PV}"
+TRACE_LOGFILE = "${TRACE_LOGDIR}/${PN}-${PV}"
SWAB_ORIG_TASK := "${BB_DEFAULT_TASK}"
BB_DEFAULT_TASK = "generate_swabber_report"
@@ -56,7 +56,22 @@ python() {
bb.data.setVarFlag('do_setscene', 'depends', " ".join(deps), d)
logdir = bb.data.expand("${TRACE_LOGDIR}", d)
bb.utils.mkdirhier(logdir)
- bb.data.setVar('BB_RUNTASK', 'bitbake-runtask-strace', d)
+ else:
+ bb.data.setVar('STRACEFUNC', '', d)
+}
+
+STRACEPID = "${@os.getpid()}"
+STRACEFUNC = "imageswab_attachstrace"
+
+do_configure[prefuncs] += "${STRACEFUNC}"
+do_compile[prefuncs] += "${STRACEFUNC}"
+
+imageswab_attachstrace () {
+ STRACE=`which strace`
+
+ if [ -x "$STRACE" ]; then
+ swabber-strace-attach "$STRACE -f -o ${TRACE_LOGFILE}-${BB_CURRENTTASK}.log -e trace=open,execve -p ${STRACEPID}" "${TRACE_LOGFILE}-traceattach-${BB_CURRENTTASK}.log"
+ fi
}
do_generate_swabber_report () {
diff --git a/scripts/swabber-strace-attach b/scripts/swabber-strace-attach
new file mode 100755
index 0000000000..d4f80e4e91
--- /dev/null
+++ b/scripts/swabber-strace-attach
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+import os
+import sys
+
+# Detach from the controlling terminal and parent process by forking twice to daemonize ourselves,
+# then run the command passed as argv[1]. Send log data to argv[2].
+
+pid = os.fork()
+if (pid == 0):
+ os.setsid()
+ pid = os.fork()
+ if (pid != 0):
+ os._exit(0)
+else:
+ sys.exit()
+
+
+si = file(os.devnull, 'r')
+so = file(sys.argv[2], 'w')
+se = so
+
+# Replace those fds with our own
+os.dup2(si.fileno(), sys.stdin.fileno())
+os.dup2(so.fileno(), sys.stdout.fileno())
+os.dup2(se.fileno(), sys.stderr.fileno())
+
+ret = os.system(sys.argv[1])
+
+os._exit(ret)
+