| 1 | #!/bin/bash |
| 2 | |
| 3 | USTD="./ustd/ustd" |
| 4 | LIBINTERFORK="./libinterfork/.libs/libinterfork.so" |
| 5 | |
| 6 | BASE_TRACE_DIR="$HOME/.usttraces" |
| 7 | |
| 8 | function usage () { |
| 9 | echo "usage: $0 COMMAND" 2>/dev/stderr |
| 10 | } |
| 11 | |
| 12 | function error() { |
| 13 | echo "$0: error: $1" 2>/dev/stderr |
| 14 | } |
| 15 | |
| 16 | # Prepare vars |
| 17 | CMD=$1 |
| 18 | |
| 19 | # Validate input |
| 20 | if [ -z "$HOME" ]; |
| 21 | then |
| 22 | error "no home specified" |
| 23 | fi |
| 24 | |
| 25 | if [ -z "$CMD" ]; |
| 26 | then |
| 27 | error "no command specified" |
| 28 | usage; |
| 29 | exit 1 |
| 30 | fi |
| 31 | |
| 32 | # Create directory for trace output |
| 33 | DATESTRING="$(hostname)-$(date +%Y%m%d%H%M%S)" |
| 34 | OUTDIR="$BASE_TRACE_DIR/$DATESTRING" |
| 35 | mkdir -p "$OUTDIR" |
| 36 | |
| 37 | # Choose socket path |
| 38 | SOCKPATH="/tmp/ust-sock-$$" |
| 39 | |
| 40 | # Start daemon |
| 41 | $USTD -s "$SOCKPATH" -o "$OUTDIR" >"$OUTDIR/ustd.log" 2>&1 & |
| 42 | USTDPID=$! |
| 43 | |
| 44 | # Establish the environment for the command |
| 45 | export UST_TRACE=1 |
| 46 | export UST_AUTOPROBE=1 |
| 47 | export UST_DAEMON_SOCKET="$SOCKPATH" |
| 48 | |
| 49 | # Execute the command |
| 50 | bash -c "$CMD" |
| 51 | |
| 52 | ## Because of the keepalive mechanism, we're sure that by the time |
| 53 | ## we get here, the daemon is connected to all the buffers that still exist. |
| 54 | ## Therefore we can politely ask it to die when it's done. |
| 55 | |
| 56 | kill -SIGTERM "$USTDPID" |
| 57 | |
| 58 | # Tell the daemon to die |
| 59 | echo "Waiting for ustd to shutdown..." |
| 60 | wait "$USTDPID" |