changeset 1472:a4673f17b7c0

Add record-commands wrapper and plumbing to target image, so you can record-commands /mnt/init in a native build.
author Rob Landley <rob@landley.net>
date Tue, 06 Dec 2011 21:29:16 -0600
parents 9c2b7ec6b0c7
children a584fb153593
files simple-root-filesystem.sh sources/root-filesystem/sbin/record-commands
diffstat 2 files changed, 31 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/simple-root-filesystem.sh	Tue Dec 06 21:15:59 2011 -0600
+++ b/simple-root-filesystem.sh	Tue Dec 06 21:29:16 2011 -0600
@@ -74,6 +74,10 @@
   "${ARCH}-cc" "${SOURCES}/toys/hello.c" -Os $CFLAGS -static -o "$STAGE_DIR/bin/hello-static" || dienow
 fi
 
+# Debug wrapper for use with /usr/src/record-commands.sh
+
+"${ARCH}-cc" "$SOURCES/toys/wrappy.c" -Os $CFLAGS -o "$STAGE_DIR/bin/record-commands-wrapper" || dienow
+
 # Do we need shared libraries?
 
 if [ "$BUILD_STATIC" != all ]
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sources/root-filesystem/sbin/record-commands	Tue Dec 06 21:29:16 2011 -0600
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+# Set up command recording wrapper
+
+[ -z "$WRAPDIR" ] && WRAPDIR=/tmp/record-commands
+[ -z "$WRAPPY_LOGPATH" ] &&
+  export WRAPPY_LOGPATH=/tmp/record-commands-log.txt
+
+if [ $# -eq 0 ]
+then
+  echo "Usage: record-commands command..."
+  exit 1
+fi
+
+mkdir -p "$WRAPDIR" &&
+  ln -s $(which record-commands-wrapper) "$WRAPDIR" || exit 1
+
+echo "$PATH" | sed 's/:/\n/g' | while read DIR
+do
+  find "$DIR/" -maxdepth 1 -mindepth 1 | sed 's@.*/@@' | while read FILE
+  do
+    ln -s record-commands-wrapper "$WRAPDIR/$FILE" 2>/dev/null
+  done
+done
+
+OLDPATH="$PATH" PATH="$WRAPDIR:$PATH" "$@"
+rm -rf "$WRAPDIR"