s4 dns: Import DNS win32 error codes from MS-ERREF
[Samba/gebeck_regimport.git] / selftest / in_screen
blob927d83109bde5447269c33a03b43c673991e9689
1 #!/usr/bin/env bash
3 export TMPDIR="$SELFTEST_TMPDIR"
5 SERVERNAME="$ENVNAME"
6 [ -z "$SERVERNAME" ] && SERVERNAME="base"
7 basedir=$TMPDIR
8 osname=$(uname)
9 if [ "$osname" = "Linux" ]; then
10 vars=$(mktemp)
11 else
12 vars=$(mktemp -t tmpsmb)
13 function seq() {
14 dpt=$1
15 end=$2
16 while [ $dpt -le $end ]; do
17 echo "$dpt"
18 dpt=$(( $dpt + 1))
19 done
23 [ -r $basedir/$SERVERNAME.pid ] && {
24 for i in $(seq 2 100); do
25 if [ ! -r "$basedir/${SERVERNAME}-$i.pid" ]; then
26 SERVERNAME="${SERVERNAME}-$i"
27 break
29 done
32 rm -f $basedir/$SERVERNAME.*
34 # set most of the environment vars we have in the screen session too
35 _ENV=""
36 printenv |
37 egrep -v '^TERMCAP|^WINDOW|^SHELL|^STY|^SHLVL|^SAMBA_VALGRIND|\$' |
38 egrep '^[A-Z]' |
39 sed "s/\(^[^=]*=\)\(.*\)/export \1'\2'/g" > $basedir/$SERVERNAME.vars
41 cat <<EOF > $basedir/$SERVERNAME.launch
42 echo \$\$ > $basedir/$SERVERNAME.pid
43 . $basedir/$SERVERNAME.vars
44 echo "\$(date) starting $SERVERNAME" >> $basedir/$SERVERNAME.log
46 echo \$? > $basedir/$SERVERNAME.status
47 read parent < $basedir/$SERVERNAME.parent.pid
48 kill \$parent
49 EOF
50 pid=$$
52 cleanup() {
53 trap "exit 1" SIGINT SIGTERM SIGPIPE
54 [ -r $basedir/$SERVERNAME.status ] && {
55 read status < $basedir/$SERVERNAME.status
56 echo "$(date) samba exited with status $status" >> $basedir/$SERVERNAME.log
57 exit $status
59 read pid < $basedir/$SERVERNAME.pid
60 echo "$(date) Killing samba pid $pid from $$" >> $basedir/$SERVERNAME.log
61 if [ "$pid" = "$$" ]; then
62 exit 1
64 kill -9 $pid 2>&1
65 exit 1
68 rm -f $basedir/$SERVERNAME.status $basedir/$SERVERNAME.log
69 echo $$ > $basedir/$SERVERNAME.parent.pid
70 trap cleanup SIGINT SIGTERM SIGPIPE
71 screen -r -X screen -t test:$SERVERNAME bash $basedir/$SERVERNAME.launch
72 echo "$(date) waiting in $$" >> $basedir/$SERVERNAME.log
73 read stdin_var
74 echo "$(date) EOF on stdin" >> $basedir/$SERVERNAME.log
75 read pid < $basedir/$SERVERNAME.pid
76 echo "$(date) killing $pid" >> $basedir/$SERVERNAME.log
77 kill $pid 2> /dev/null
78 echo "$(date) exiting" >> $basedir/$SERVERNAME.log
79 exit 0