#!/bin/sh

#
# Commands executed by this script will write messages to
# stderr about suspicious writes to /tmp.
# 
# This script mainly serves to show how to use the libtricks
# functionality.


help ()
{
    echo "$0: log all open() calls of files"
    echo "  Usage: $0 [--libpath path] [command]"
}

while true; do
  case $1 in
    --libpath)
      shift
      LIBPATH="$1"
      ;;
    --help)
      help
      exit 0
      ;;
    --version)
      echo trick-chroot, version 0.2
      exit 0
      ;;
    *)
      break;
      ;;
  esac
  shift
done


# If you want your warning messages to appear in syslog, change
# "stderr" to "syslog":

LD_PRELOAD=${LIBPATH:-/usr/lib/libtricks}/libtricks.so.0
VPATH="needwrite&!needexcl&check(\"/tmp/\")&stderr(\"Warning: write to \$name without EXCL, prog=\$cmd\")="

# If you want the output to go to a file, use:
#VPATH="needwrite&!needexcl&check(\"/tmp/\")&writefile(\"/tmp/trick-chktmp.log\",\"Warning: write to \$name without EXCL, prog=\$cmd\")="

#if you want all writes to /tmp to fail, add '&return(EPERM)'
#just before the last '=' sign in the VPATH above.


if test -z "$*"; then
  export LD_PRELOAD VPATH
  /bin/sh
else
  export LD_PRELOAD VPATH
  $@
fi



