t/lib-git-daemon: make sure to kill the 'git-daemon' process
[gitweb.git] / t / lib-git-daemon.sh
index edbea2d986134f36b86e044f307abae1457f8165..6dab8766e7c7431e25ef94b43cc30d0281f25f32 100644 (file)
@@ -28,9 +28,10 @@ then
        test_skip_or_die $GIT_TEST_GIT_DAEMON "file system does not support FIFOs"
 fi
 
-LIB_GIT_DAEMON_PORT=${LIB_GIT_DAEMON_PORT-${this_test#t}}
+test_set_port LIB_GIT_DAEMON_PORT
 
 GIT_DAEMON_PID=
+GIT_DAEMON_PIDFILE="$PWD"/daemon.pid
 GIT_DAEMON_DOCUMENT_ROOT_PATH="$PWD"/repo
 GIT_DAEMON_HOST_PORT=127.0.0.1:$LIB_GIT_DAEMON_PORT
 GIT_DAEMON_URL=git://$GIT_DAEMON_HOST_PORT
@@ -49,24 +50,16 @@ start_git_daemon() {
        mkfifo git_daemon_output
        ${LIB_GIT_DAEMON_COMMAND:-git daemon} \
                --listen=127.0.0.1 --port="$LIB_GIT_DAEMON_PORT" \
-               --reuseaddr --verbose \
+               --reuseaddr --verbose --pid-file="$GIT_DAEMON_PIDFILE" \
                --base-path="$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
                "$@" "$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
                >&3 2>git_daemon_output &
        GIT_DAEMON_PID=$!
-       >daemon.log
        {
                read -r line <&7
-               printf "%s\n" "$line"
-               printf >&4 "%s\n" "$line"
-               (
-                       while read -r line <&7
-                       do
-                               printf "%s\n" "$line"
-                               printf >&4 "%s\n" "$line"
-                       done
-               ) &
-       } 7<git_daemon_output >>"$TRASH_DIRECTORY/daemon.log" &&
+               printf "%s\n" "$line" >&4
+               cat <&7 >&4 &
+       } 7<git_daemon_output &&
 
        # Check expected output
        if test x"$(expr "$line" : "\[[0-9]*\] \(.*\)")" != x"Ready to rumble"
@@ -92,12 +85,13 @@ stop_git_daemon() {
        kill "$GIT_DAEMON_PID"
        wait "$GIT_DAEMON_PID" >&3 2>&4
        ret=$?
-       if test_match_signal 15 $?
+       if ! test_match_signal 15 $ret
        then
                error "git daemon exited with status: $ret"
        fi
+       kill "$(cat "$GIT_DAEMON_PIDFILE")" 2>/dev/null
        GIT_DAEMON_PID=
-       rm -f git_daemon_output
+       rm -f git_daemon_output "$GIT_DAEMON_PIDFILE"
 }
 
 # A stripped-down version of a netcat client, that connects to a "host:port"