git » libfiu » commit aea52dd

Add fiu-run, a script to simplify running programs with libfiu

author Alberto Bertogli
2009-06-15 06:09:58 UTC
committer Alberto Bertogli
2009-06-16 19:14:45 UTC
parent 278bb609c79d9bc9d718fc1395bf4249f9cdd36a

Add fiu-run, a script to simplify running programs with libfiu

See the help and/or manpage for more details.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

.gitignore +1 -0
preload/run/Makefile +11 -3
preload/run/fiu-run.1 +80 -0
preload/run/fiu-run.in +122 -0

diff --git a/.gitignore b/.gitignore
index fdfed27..18e44ba 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,4 +11,5 @@ preload/posix/modules/*.o
 preload/posix/modules/*.mod.c
 preload/run/*.o
 preload/run/*.so
+preload/run/fiu-run
 
diff --git a/preload/run/Makefile b/preload/run/Makefile
index 7655a86..cb11220 100644
--- a/preload/run/Makefile
+++ b/preload/run/Makefile
@@ -27,7 +27,7 @@ endif
 
 default: all
 	
-all: fiu_run_preload.so
+all: fiu_run_preload.so fiu-run
 
 .c.o:
 	$(NICE_CC) $(ALL_CFLAGS) -c $< -o $@
@@ -36,12 +36,20 @@ fiu_run_preload.so: $(OBJS)
 	$(NICE_CC) $(ALL_CFLAGS) -shared -fPIC $(OBJS) -lfiu -ldl \
 		-o fiu_run_preload.so
 
-install: fiu_run_preload.so
+fiu-run: fiu-run.in
+	cat fiu-run.in | sed "s+@@PREFIX@@+$(PREFIX)+g" > fiu-run
+	chmod +x fiu-run
+
+install: fiu_run_preload.so fiu-run
 	install -d $(PREFIX)/lib
 	install -m 0755 fiu_run_preload.so $(PREFIX)/lib
+	install -d $(PREFIX)/bin
+	install -m 0755 fiu-run $(PREFIX)/bin
+	install -d $(PREFIX)/man/man1
+	install -m 0644 fiu-run.1 $(PREFIX)/man/man1/
 
 clean:
-	rm -f $(OBJS) fiu_run_preload.so
+	rm -f $(OBJS) fiu_run_preload.so fiu-run
 	rm -f *.bb *.bbg *.da *.gcov *.gcda *.gcno gmon.out
 
 .PHONY: default install clean
diff --git a/preload/run/fiu-run.1 b/preload/run/fiu-run.1
new file mode 100644
index 0000000..bcc9788
--- /dev/null
+++ b/preload/run/fiu-run.1
@@ -0,0 +1,80 @@
+.TH fiu-run 1 "16/Jun/2009"
+.SH NAME
+fiu-run - a script to launch programs using libfiu
+.SH SYNOPSIS
+fiu-run [options] program [program arguments]
+
+.SH DESCRIPTION
+fiu-run is a script to make it easier to launch programs using
+\fBlibfiu\fR(3). It can enable failure points and start libfiu's remote
+control capabilities before starting to execute the program, avoiding the need
+to write a special launcher to inject failures.
+
+It is specially useful when used to inject failures in the POSIX/libc
+functions, because it does not require any program modifications.
+
+After launching programs with fiu-run, \fBfiu-ctrl\fR(1) can be used to enable
+and disable their failure points at runtme.
+
+For additional documentation, go to the project's website at
+.IR http://blitiri.com.ar/p/libfiu .
+
+.SH OPTIONS
+.TP
+.B "-e fpname"
+Enable the given failure point name.
+.TP
+.B "-p prob"
+Use the given probability for the previous failure point. In percent, defaults
+to 100, which means "always enabled". Must come \fIafter\fR the \fB-e\fR it
+affects.
+.TP
+.B "-u failnum"
+Use the given number as the failnum for the previous failure point. Must be !=
+0, defaults to 1. Must come \fIafter\fR the \fB-e\fR it affects.
+.TP
+.B "-i failinfo"
+Use the given number as the failinfo for the previous failure point. Defaults
+to 0. Must come \fIafter\fR the \fB-e\fR it affects.
+.TP
+.B -x
+Use the POSIX libfiu preload library, allows simulate failures in the POSIX
+and C standard library functions.
+.TP
+.B "-f ctrlpath"
+Enable remote control over named pipes with the given path as base name, the
+process id will be appended (defaults to "$TMPDIR/fiu-ctrl", or
+"/tmp/fiu-ctrl" if "$TMPDIR" is not set). Set to "" to disable remote control
+over named pipes.
+.TP
+.B "-l path"
+Path where to find the libfiu preload libraries. Defaults to the path where
+they were installed, so it is usually correct.
+
+.P
+You can enable any number of failure points by using \fB-e\fR repeatedly.
+
+.SH EXAMPLES
+The following will run the \fBfortune\fR(1) program simulating faults in all
+the POSIX I/O functions with a 10% probability, and in malloc() with 5%
+probability (note that the \fB-x\fR parameter is required in this case to
+enable failure points in the POSIX and libc functions):
+
+.RS
+.nf
+fiu-run -x -e posix/io/* -p 10 -e libc/mm/malloc -p 5 fortune
+.fi
+.RE
+
+By running it multiple times you will see that sometimes it works, but most of
+the time you get different errors, resulting from the simulated failures.
+
+.SH SEE ALSO
+.BR libfiu (3),
+.BR fiu-ctrl (1).
+
+.SH BUGS
+If you want to report bugs, or have any questions or comments, just let me
+know at albertito@blitiri.com.ar. For more information about libfiu, you can
+go to http://blitiri.com.ar/p/libfiu.
+
diff --git a/preload/run/fiu-run.in b/preload/run/fiu-run.in
new file mode 100644
index 0000000..8b97267
--- /dev/null
+++ b/preload/run/fiu-run.in
@@ -0,0 +1,122 @@
+#!/bin/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="@@PREFIX@@/lib"
+
+# the enable string to pass to the preload library (via the FIU_ENABLE
+# environment variable)
+ENABLE=""
+
+# additional preloader libraries to use
+PRELOAD_LIBS=""
+
+
+HELP_MSG="
+Usage: fiu-run [options] program [arguments]
+
+The following options are supported:
+
+  -e fpname	Enable the given failure point name.
+  -p prob	... with the given probability (defaults to 100%).
+  -u failnum	... and this failnum (must be != 0) (defaults to 1).
+  -i failinfo	... and this failinfo (defaults to 0).
+  -x		Use POSIX libfiu preload library, allows simulate failures in
+		the POSIX and C standard library functions.
+  -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).
+
+The -p, -u and -i options must come after the -e they affect.
+
+For example:
+
+  fiu-run -x -e 'posix/io/*' -p 25 -e libc/mm/malloc -p 5 ls -l
+
+will 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
+	NAME=""
+	PROB=-1
+	FAILNUM=1
+	FAILINFO=0
+}
+
+opts_reset;
+while getopts "+e:p:u:i:f:l:xh" opt; do
+	case $opt in
+	e)
+		# add the current one, if any
+		if [ "$NAME" != "" ]; then
+			ENABLE="$ENABLE:$NAME,$PROB,$FAILNUM,$FAILINFO"
+			opts_reset;
+		fi
+		NAME="$OPTARG"
+		;;
+	p)
+		PROB="$OPTARG"
+		;;
+	u)
+		FAILNUM="$OPTARG"
+		;;
+	i)
+		FAILINFO="$OPTARG"
+		;;
+	f)
+		FIFO_PREFIX="$OPTARG"
+		;;
+	l)
+		PLIBPATH="$OPTARG"
+		;;
+	x)
+		PRELOAD_LIBS="$PRELOAD_LIBS $PLIBPATH/fiu_posix_preload.so"
+		;;
+	h|*)
+		echo "$HELP_MSG"
+		exit 1
+		;;
+	esac;
+done
+
+# add leftovers
+if [ "$NAME" != "" ]; then
+	ENABLE="$ENABLE:$NAME,$PROB,$FAILNUM,$FAILINFO"
+	opts_reset;
+fi
+
+# eat the parameters we already processed
+shift $(( $OPTIND - 1 ))
+
+
+#
+# Run the application
+#
+
+export FIU_ENABLE="$ENABLE"
+export FIU_CTRL_FIFO="$FIFO_PREFIX"
+export LD_PRELOAD="$PLIBPATH/fiu_run_preload.so $PRELOAD_LIBS"
+exec "$@"
+