lib:ldb: Use correct integer types for sizes
[Samba.git] / selftest / in_screen
blobd7d1b53d9201e0489ebc420f7b54c138b4b3b159
1 #!/usr/bin/env bash
3 export TMPDIR="$SELFTEST_TMPDIR"
5 SERVERNAME="$ENVNAME"
6 [ -z "$SERVERNAME" ] && SERVERNAME="base"
7 basedir=$TMPDIR
9 [ -r $basedir/$SERVERNAME.pid ] && {
10 for i in {2..100}; do
11 if [ ! -r "$basedir/${SERVERNAME}-$i.pid" ]; then
12 SERVERNAME="${SERVERNAME}-$i"
13 break
15 done
18 rm -f $basedir/$SERVERNAME.{launch,log,parent.pid,pid,status}
20 # set most of the environment vars we have in the screen session too
21 _ENV=""
22 printenv |
23 egrep -v '^TERMCAP|^WINDOW|^SHELL|^STY|^SHLVL|^SAMBA_VALGRIND|\$' |
24 egrep '^[A-Z]' |
25 sed "s/\(^[^=]*=\)\(.*\)/export \1'\2'/g" >$basedir/$SERVERNAME.vars
27 cat <<EOF >$basedir/$SERVERNAME.launch
28 cd $PWD
29 echo \$\$ > $basedir/$SERVERNAME.pid
30 . $basedir/$SERVERNAME.vars
31 echo "\$(date) starting $SERVERNAME" >> $basedir/$SERVERNAME.log
33 echo \$? > $basedir/$SERVERNAME.status
34 read parent < $basedir/$SERVERNAME.parent.pid
35 kill \$parent
36 EOF
37 pid=$$
39 cleanup()
41 trap "exit 1" SIGINT SIGTERM SIGPIPE
42 [ -r $basedir/$SERVERNAME.status ] && {
43 read status <$basedir/$SERVERNAME.status
44 echo "$(date) samba exited with status $status" >>$basedir/$SERVERNAME.log
45 exit $status
48 case $ENVNAME in
49 *.nmbd | *.smbd | *.winbindd | *.samba | *.samba_dcerpcd)
50 kill $(cat $basedir/../"${ENVNAME%\.*}"/pid/"${ENVNAME##*\.}".pid)
52 esac
54 read pid <$basedir/$SERVERNAME.pid
55 echo "$(date) Killing samba pid $pid from $$" >>$basedir/$SERVERNAME.log
56 if [ "$pid" = "$$" ]; then
57 exit 1
59 kill -9 $pid 2>&1
60 exit 1
63 echo $$ >$basedir/$SERVERNAME.parent.pid
64 trap cleanup SIGINT SIGTERM SIGPIPE
66 if [[ "$TMUX" ]]; then
67 TMUX_CMD=tmux
68 if [[ $TMUX = *tmate* ]]; then
69 TMUX_CMD=tmate
72 $TMUX_CMD new-window -n test:$SERVERNAME "bash $basedir/$SERVERNAME.launch"
74 # tmux seems to lag a bit for new sessions. Don't create them too
75 # quickly one after another
76 sleep .1
77 else
78 screen -r -X screen -t test:$SERVERNAME bash $basedir/$SERVERNAME.launch
80 echo "$(date) waiting in $$" >>$basedir/$SERVERNAME.log
81 read stdin_var
82 echo "$(date) EOF on stdin" >>$basedir/$SERVERNAME.log
84 case $ENVNAME in
85 *.nmbd | *.smbd | *.winbindd | *.samba | *.samba_dcerpcd)
86 kill $(cat $basedir/../"${ENVNAME%\.*}"/pid/"${ENVNAME##*\.}".pid)
88 esac
90 read pid <$basedir/$SERVERNAME.pid
91 echo "$(date) killing $pid" >>$basedir/$SERVERNAME.log
92 kill $pid 2>/dev/null
93 echo "$(date) exiting" >>$basedir/$SERVERNAME.log
94 exit 0