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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
|
#!/bin/sh
# RTAI application loader script.
# (Processes the .runinfo files)
# April 2003, <rpm@xenomai.org>
usage='usage: rtai-load [[dir:]target]'
prefix="@prefix@"
exec_prefix="@exec_prefix@"
insmod=/sbin/insmod
modprobe=/sbin/modprobe
rmmod=/sbin/rmmod
modext=@RTAI_MODULE_EXT@
verbose=0
spc=" "
if test "x$1" = x--help; then
echo $usage
exit 0
fi
if test "x$1" = x--verbose; then
verbose=1
shift
fi
qual_target=$1
target_dir=`echo $qual_target|cut -d: -f1`
target_name=`echo $qual_target|cut -s -d: -f2`
if test "x$target_dir" = x; then
target_dir=`pwd`
fi
if test "x$target_name" = x; then
if `echo $target_dir | grep -q /`; then
target_name=default
else
target_name=$target_dir
target_dir=.
fi
fi
run_info_file=$target_dir/.runinfo
if test \! -r $run_info_file; then
echo "rtai-load: cannot find run info: $run_info_file"
exit 2
fi
if test $target_name = default; then
target_name=`cut -s -d: -f1 $run_info_file | head -1`
if test "x$target_name" = x; then
echo "rtai-load: no target defined in $run_info_file"
exit 2
fi
fi
stanza=`grep "^[$spc]*$target_name[$spc]*:" $run_info_file`
if test "x$stanza" = x; then
echo "rtai-load: cannot find run info for target $target_name"
exit 2
fi
rtai_moddir=`grep "^[$spc]*rtai_moddir[$spc]*=" $run_info_file`
user_moddir=`grep "^[$spc]*user_moddir[$spc]*=" $run_info_file`
if test "x$rtai_moddir" = x; then
eval rtai_moddir='${DESTDIR}@RTAI_MODULE_DIR@'
else
eval $rtai_moddir
fi
eval $user_moddir
if `$modprobe -nq adeos >& /dev/null`; then
target_deps="adeos+"
else
target_deps=
fi
target_deps="${target_deps}trace+hal+malloc+`echo $stanza | cut -d: -f2`"
target_info=`echo $stanza | cut -d: -f3`
target_mesg=`echo $stanza | cut -s -d: -f4`
test $verbose = 1 && echo "Running $target_name from $run_info_file"
if test \! "x`type -t sudo`" = x; then
sudo=sudo
fi
if test \! "x$target_mesg" = x; then
case "$target_mesg" in
control_c)
target_mesg="Type ^C to stop this application."
;;
esac
echo "*"
echo "*"
echo "* $target_mesg"
echo "*"
echo "*"
fi
sync
loadlist=`cat /proc/modules | ( \
while read lm; do \
set -- $lm; \
loadlist="$loadlist $1"; \
done ; echo $loadlist )`
( cd $target_dir ;
inslist=""
children_pids=""
cleanup () {
if test \! "x$children_pids" = x; then
$sudo kill -SIGINT $children_pids >& /dev/null
children_pids=""
sleep 1
fi
if test \! "x$inslist" = x; then
for mod in $inslist ; do
test $verbose = 1 && echo "+ $rmmod $mod"
$sudo $rmmod $mod
done
inslist=""
fi
}
trap cleanup SIGINT
while test -n "$target_deps" ; do
mod=`echo $target_deps|cut -d+ -f1`
target_deps=`echo $target_deps|cut -s -d+ -f2-`
if test -h $rtai_moddir/rtai_$mod$modext; then
# Substitute the symlink with the target name since
# new modutils (>= 2.5.48) will use the actual name.
mod=`ls -l $rtai_moddir/rtai_$mod$modext|sed -e "s,.* \-> .*rtai_\([a-z0-9A-Z]*\)$modext.*,\1,"`
fi
if `echo $loadlist | grep -vq "\\brtai_$mod\\b"`; then
# If we cannot find the module in our install dir, try Linux's
# one. If the latter fails too, assume the feature is built into
# the scheduler or not needed. Obviously, we should _always_ find
# the scheduler...
if test -r $rtai_moddir/rtai_$mod$modext; then
test $verbose = 1 && echo "+ $insmod $rtai_moddir/rtai_$mod$modext"
$sudo $insmod $rtai_moddir/rtai_$mod$modext
if test $? = 0 ; then
inslist="rtai_$mod $inslist"
loadlist="$loadlist $mod"
else
echo "ERROR: cannot load $rtai_moddir/rtai_$mod$modext"
break
fi
elif `$modprobe -n $mod >& /dev/null`; then
test $verbose = 1 && echo "+ $modprobe $mod"
$sudo $modprobe $mod
inslist="$mod $inslist"
loadlist="$loadlist $mod"
fi
fi
done
while test -n "$target_info" ; do
action=`echo $target_info|cut -d';' -f1`
target_info=`echo $target_info|cut -s -d';' -f2-`
set -- $action
case "$1" in
push)
mod=`basename $2 $modext`
if test -r $user_moddir/$mod$modext; then
modpath="$user_moddir/$mod"
else
modpath="$mod"
fi
shift 2
if `echo $loadlist | grep -vq "\\b$mod\\b"`; then
test $verbose = 1 && echo "+ $insmod $modpath$modext $@"
$sudo $insmod $modpath$modext $@
if test $? = 0; then
loadlist="$loadlist $mod"
inslist="$mod $inslist"
else
echo "ERROR: cannot load $modpath$modext"
break
fi
fi
;;
pop)
shift
if test "x$*" = x; then
rmlist=`echo $inslist | cut -s -f1 -d' '`
else
rmlist=$*
fi
_inslist="$inslist"
if test \! "x$rmlist" = x; then
for mod in $rmlist ; do
test $verbose = 1 && echo "+ $rmmod $mod"
$sudo $rmmod $mod && _inslist=`echo $_inslist | sed -e "s,$mod,,g"`
done
inslist="$_inslist"
fi
;;
popall|flush)
cleanup
;;
*)
case "$1" in
exec|spawn) shift ;;
klog) set -- \! tail -f /var/log/messages ;;
esac
e=`echo $* | sed -e "s,^[$spc]*![$spc]*\\(.*\\)$,\\1,"`
test "$e" = "$*" && suflag= || suflag=$sudo
set -- $e
e=`echo $* | sed -e "s,\\(.*\\)&[$spc]*$,\\1,"`
test "$e" = "$*" && waitflag=1 || waitflag=0
set -- $e
test $verbose = 1 && echo "+ spawning command ($*)"
if test $waitflag = 1; then
$suflag $*
else
$suflag $* &
children_pids="$! $children_pids"
fi
;;
esac
done )
exit 0
|