/usr/bin/fiu-run is in fiu-utils 0.95-3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | #!/usr/bin/env bash
# This script aims to make the use of the fiu_run_preload library a little
# easier by providing a more friendly user interface, and abstracting the
# environment variables used to communicate with it.
# default remote control over named pipes prefix
FIFO_PREFIX="${TMPDIR:-/tmp}/fiu-ctrl"
# default library path to look for preloader libraries
PLIBPATH="/usr/lib/fiu"
# the enable string to pass to the preload library (via the FIU_ENABLE
# environment variable)
ENABLE=""
# additional preloader libraries to use
PRELOAD_LIBS=""
# use the POSIX preload library?
USE_POSIX_PRELOAD=0
# don't run, but show the command line instead
DRY_RUN=0
HELP_MSG="
Usage: fiu-run [options] program [arguments]
The following options are supported:
-x Use POSIX libfiu preload library, allows simulate failures in
the POSIX and C standard library functions.
-c command Run the given libfiu remote control command before executing
the program (see below for reference).
-f ctrlpath Enable remote control over named pipes with the given path as
base name, the process id will be appended (defaults to
\"$FIFO_PREFIX\", set to \"\" to disable).
-l path Path where to find the libfiu preload libraries, defaults to
$PLIBPATH (which is usually correct).
Remote control commands are of the form 'command param1=value1,param2=value2'.
Valid commands are:
- 'enable name=NAME'
Enables the NAME failure point unconditionally.
- 'enable_random name=NAME,probability=P'
Enables the NAME failure point with a probability of P.
All of them can also optionally take 'failnum' and 'failinfo' parameters,
analogous to the ones taken by the C functions.
The following options existed in the past but are deprecated and WILL BE
REMOVED in future releases: -e, -p, -u and -i.
Example:
fiu-run -x -c 'enable_random name=posix/io/*,probability=0.25' \\
-c 'enable_random name=libc/mm/*,probability=0.05' ls -l
Run \"ls -l\" enabling all failure points that begin with 'posix/io/' with a
25% of probability to fail, and the failure point libc/mm/malloc with a 5% of
probability to fail.
"
#
# Parse the options
#
if [ $# -lt 1 ]; then
echo "$HELP_MSG"
exit 1
fi
function opts_reset() {
# variables to store what we know so far; after a new name is found
# the old one is added to $ENABLE
DEP_NAME=""
DEP_PROB=-1
DEP_FAILNUM=1
DEP_FAILINFO=0
}
function add_deprecated_enable() {
if [ "$NAME" == "" ]; then
return
fi;
PARAMS="name=$DEP_NAME,failnum=$DEP_FAILNUM,failinfo=$DEP_FAILINFO"
if [ $PROB -ge 0 ]; then
C="enable_random $PARAMS,probability=$PROB"
else
C="enable $PARAMS"
fi
ENABLE="$ENABLE
$C"
}
opts_reset;
while getopts "+c:f:l:xne:p:u:i:h" opt; do
case $opt in
c)
# Note we use the newline as a command separator.
ENABLE="$ENABLE
$OPTARG"
;;
f)
FIFO_PREFIX="$OPTARG"
;;
l)
PLIBPATH="$OPTARG"
;;
x)
USE_POSIX_PRELOAD=1
;;
n)
DRY_RUN=1
;;
# Deprecated options
e)
add_deprecated_enable
opts_reset
DEP_NAME="$OPTARG"
;;
p)
DEP_PROB="$OPTARG"
;;
u)
DEP_FAILNUM="$OPTARG"
;;
i)
DEP_FAILINFO="$OPTARG"
;;
h|*)
echo "$HELP_MSG"
exit 1
;;
esac;
done
# add leftovers
add_deprecated_enable
opts_reset;
# eat the parameters we already processed
shift $(( $OPTIND - 1 ))
# Allow user to give -l and -x in any order.
if [ $USE_POSIX_PRELOAD -eq 1 ] ; then
PRELOAD_LIBS="$PRELOAD_LIBS $PLIBPATH/fiu_posix_preload.so"
fi
#
# Run the application
#
export FIU_ENABLE="$ENABLE"
export FIU_CTRL_FIFO="$FIFO_PREFIX"
export LD_PRELOAD="$PLIBPATH/fiu_run_preload.so $PRELOAD_LIBS"
if [ $DRY_RUN -eq 1 ] ; then
echo "FIU_ENABLE=\"$ENABLE\"" \\
echo "FIU_CTRL_FIFO=\"$FIFO_PREFIX\"" \\
echo "LD_PRELOAD=\"$PLIBPATH/fiu_run_preload.so $PRELOAD_LIBS\"" \\
echo "$@"
else
exec "$@"
fi
|