-
Notifications
You must be signed in to change notification settings - Fork 21
/
run
executable file
·59 lines (51 loc) · 1.18 KB
/
run
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
#!/bin/sh
REQUIREMENTS="/sbin/ip /usr/bin/slirp-fullbolt"
for R in $REQUIREMENTS
do
[ -x $R ] || {
echo "Requirement $R not found. Aborting."
exit 1
}
done
if [ "$2" ]
then
shift
echo "Extraneous arguments: $*"
echo "Try to enclose them within quotes?"
exit 255
fi
LOGDIR=/tmp/log.$$
mkdir $LOGDIR
if [ "$1" ]
then
CMD="$1"
STDIN=/dev/null
STDOUT=/dev/null
STDERR=/dev/null
touch $LOGDIR/output
tail -f $LOGDIR/output &
TAILPID=$!
trap '' TERM
else
CMD=/bin/zsh
STDIN=/dev/stdin
STDOUT=/dev/stdout
STDERR=/dev/stderr
TAILPID=""
fi
cat /etc/resolv.conf > $LOGDIR/resolv.conf
echo "$CMD" > $LOGDIR/cmd
INITDIR="$(readlink --canonicalize $(dirname "$0"))"
$INITDIR/uml quiet mem=2G rootfstype=hostfs rootflags=/ ro \
eth0=slirp,,/usr/bin/slirp-fullbolt \
init=$INITDIR/init LOGDIR="$LOGDIR" \
<$STDIN >$STDOUT 2>$STDERR
# Due to a weird behavior of usermodelinux, sometimes it will kill the
# whole process group, and we won't have to kill tail. Duh.
[ "$TAILPID" ] && [ -d /proc/$TAILPID ] &&
/bin/kill $TAILPID >/dev/null 2>/dev/null
STATUS=""
[ -f "$LOGDIR/status" ] && STATUS="$(cat $LOGDIR/status)"
[ "$DEBUG" ] || rm -rf "$LOGDIR"
[ "$STATUS" ] && exit $STATUS
exit 255