Revert "git-daemon wrapper to wait until daemon is ready"

This reverts commit 4c96c7aab7, as the
patch by j6t to fix the shell script with wrong construct is a better
way to go.
This commit is contained in:
Junio C Hamano
2012-04-27 11:05:27 -07:00
parent 4c96c7aab7
commit 16e068bd15
4 changed files with 26 additions and 68 deletions

1
.gitignore vendored
View File

@@ -177,7 +177,6 @@
/test-dump-cache-tree
/test-scrap-cache-tree
/test-genrandom
/test-git-daemon
/test-index-version
/test-line-buffer
/test-match-trees

View File

@@ -477,7 +477,6 @@ TEST_PROGRAMS_NEED_X += test-delta
TEST_PROGRAMS_NEED_X += test-dump-cache-tree
TEST_PROGRAMS_NEED_X += test-scrap-cache-tree
TEST_PROGRAMS_NEED_X += test-genrandom
TEST_PROGRAMS_NEED_X += test-git-daemon
TEST_PROGRAMS_NEED_X += test-index-version
TEST_PROGRAMS_NEED_X += test-line-buffer
TEST_PROGRAMS_NEED_X += test-match-trees

View File

@@ -23,13 +23,27 @@ start_git_daemon() {
trap 'code=$?; stop_git_daemon; (exit $code); die' EXIT
say >&3 "Starting git daemon ..."
test-git-daemon --listen=127.0.0.1 --port="$LIB_GIT_DAEMON_PORT" \
mkfifo git_daemon_output
git daemon --listen=127.0.0.1 --port="$LIB_GIT_DAEMON_PORT" \
--reuseaddr --verbose \
--base-path="$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
"$@" "$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
>&3 2>&4 ||
error "git daemon failed to start"
GIT_DAEMON_PID=$(cat git-daemon.pid)
>&3 2>git_daemon_output &
GIT_DAEMON_PID=$!
{
read line
echo >&4 "$line"
cat >&4 &
# Check expected output
if test x"$(expr "$line" : "\[[0-9]*\] \(.*\)")" != x"Ready to rumble"
then
kill "$GIT_DAEMON_PID"
wait "$GIT_DAEMON_PID"
trap 'die' EXIT
error "git daemon failed to start"
fi
} <git_daemon_output
}
stop_git_daemon() {
@@ -43,5 +57,13 @@ stop_git_daemon() {
# kill git-daemon child of git
say >&3 "Stopping git daemon ..."
kill "$GIT_DAEMON_PID"
wait "$GIT_DAEMON_PID" >&3 2>&4
ret=$?
# expect exit with status 143 = 128+15 for signal TERM=15
if test $ret -ne 143
then
error "git daemon exited with status: $ret"
fi
GIT_DAEMON_PID=
rm -f git_daemon_output
}

View File

@@ -1,62 +0,0 @@
#include "git-compat-util.h"
#include "run-command.h"
#include "exec_cmd.h"
#include "strbuf.h"
#include <string.h>
#include <errno.h>
static int parse_daemon_output(char *s)
{
if (*s++ != '[')
return 1;
s = strchr(s, ']');
if (!s)
return 1;
if (strcmp(s, "] Ready to rumble\n"))
return 1;
return 0;
}
int main(int argc, char **argv)
{
struct strbuf line = STRBUF_INIT;
FILE *fp;
struct child_process proc, cat;
char *cat_argv[] = { "cat", NULL };
setup_path();
memset(&proc, 0, sizeof(proc));
argv[0] = "git-daemon";
proc.argv = (const char **)argv;
proc.no_stdin = 1;
proc.err = -1;
if (start_command(&proc) < 0)
return 1;
strbuf_getwholeline_fd(&line, proc.err, '\n');
fputs(line.buf, stderr);
memset(&cat, 0, sizeof(cat));
cat.argv = (const char **)cat_argv;
cat.in = proc.err;
cat.out = 2;
if (start_command(&cat) < 0)
return 1;
if (parse_daemon_output(line.buf)) {
kill(proc.pid, SIGTERM);
finish_command(&proc);
finish_command(&cat);
return 1;
}
fp = fopen("git-daemon.pid", "w");
fprintf(fp, "%"PRIuMAX"\n", (uintmax_t)proc.pid);
fclose(fp);
return 0;
}