source: vendor/current/selftest/in_screen

Last change on this file was 988, checked in by Silvan Scherrer, 9 years ago

Samba Server: update vendor to version 4.4.3

File size: 2.2 KB
Line 
1#!/usr/bin/env bash
2
3export TMPDIR="$SELFTEST_TMPDIR"
4
5SERVERNAME="$ENVNAME"
6[ -z "$SERVERNAME" ] && SERVERNAME="base"
7basedir=$TMPDIR
8osname=$(uname)
9if [ "$osname" = "Linux" ]; then
10 vars=$(mktemp)
11else
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
20 }
21fi
22
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
28 fi
29 done
30}
31
32rm -f $basedir/$SERVERNAME.*
33
34# set most of the environment vars we have in the screen session too
35_ENV=""
36printenv |
37 egrep -v '^TERMCAP|^WINDOW|^SHELL|^STY|^SHLVL|^SAMBA_VALGRIND|\$' |
38 egrep '^[A-Z]' |
39 sed "s/\(^[^=]*=\)\(.*\)/export \1'\2'/g" > $basedir/$SERVERNAME.vars
40
41cat <<EOF > $basedir/$SERVERNAME.launch
42cd $PWD
43 echo \$\$ > $basedir/$SERVERNAME.pid
44 . $basedir/$SERVERNAME.vars
45 echo "\$(date) starting $SERVERNAME" >> $basedir/$SERVERNAME.log
46 $@
47 echo \$? > $basedir/$SERVERNAME.status
48 read parent < $basedir/$SERVERNAME.parent.pid
49 kill \$parent
50EOF
51pid=$$
52
53cleanup() {
54 trap "exit 1" SIGINT SIGTERM SIGPIPE
55 [ -r $basedir/$SERVERNAME.status ] && {
56 read status < $basedir/$SERVERNAME.status
57 echo "$(date) samba exited with status $status" >> $basedir/$SERVERNAME.log
58 exit $status
59 }
60 read pid < $basedir/$SERVERNAME.pid
61 echo "$(date) Killing samba pid $pid from $$" >> $basedir/$SERVERNAME.log
62 if [ "$pid" = "$$" ]; then
63 exit 1
64 fi
65 kill -9 $pid 2>&1
66 exit 1
67}
68
69rm -f $basedir/$SERVERNAME.status $basedir/$SERVERNAME.log
70echo $$ > $basedir/$SERVERNAME.parent.pid
71trap cleanup SIGINT SIGTERM SIGPIPE
72
73if [[ "$TMUX" ]]; then
74 TMUX_CMD=tmux
75 if [[ $TMUX = *tmate* ]]; then
76 TMUX_CMD=tmate
77 fi
78
79 $TMUX_CMD new-window -n test:$SERVERNAME "bash $basedir/$SERVERNAME.launch"
80else
81 screen -r -X screen -t test:$SERVERNAME bash $basedir/$SERVERNAME.launch
82fi
83echo "$(date) waiting in $$" >> $basedir/$SERVERNAME.log
84read stdin_var
85echo "$(date) EOF on stdin" >> $basedir/$SERVERNAME.log
86read pid < $basedir/$SERVERNAME.pid
87echo "$(date) killing $pid" >> $basedir/$SERVERNAME.log
88kill $pid 2> /dev/null
89echo "$(date) exiting" >> $basedir/$SERVERNAME.log
90exit 0
Note: See TracBrowser for help on using the repository browser.