From 5b276ee4fb01a5c3cf4970df69d319a3c93c81c9 Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Tue, 20 Jun 2006 15:38:13 +0100 Subject: [PATCH 1/2] Log peer address when git-daemon called from inetd When we run git-daemon from inetd, even with the --verbose option, it doesn't log the peer address. That logic was only in the standalone daemon code -- move it to the execute() function instead. Tested with both IPv6 and Legacy IP clients, in both inetd and daemon mode. Signed-off-by: David Woodhouse Acked-by: Jon Loeliger Signed-off-by: Junio C Hamano --- daemon.c | 58 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/daemon.c b/daemon.c index 2f03f99d2d..bdfe80d2e4 100644 --- a/daemon.c +++ b/daemon.c @@ -264,11 +264,34 @@ static int upload(char *dir) return -1; } -static int execute(void) +static int execute(struct sockaddr *addr) { static char line[1000]; int pktlen, len; + if (addr) { + char addrbuf[256] = ""; + int port = -1; + + if (addr->sa_family == AF_INET) { + struct sockaddr_in *sin_addr = (void *) addr; + inet_ntop(addr->sa_family, &sin_addr->sin_addr, addrbuf, sizeof(addrbuf)); + port = sin_addr->sin_port; +#ifndef NO_IPV6 + } else if (addr && addr->sa_family == AF_INET6) { + struct sockaddr_in6 *sin6_addr = (void *) addr; + + char *buf = addrbuf; + *buf++ = '['; *buf = '\0'; /* stpcpy() is cool */ + inet_ntop(AF_INET6, &sin6_addr->sin6_addr, buf, sizeof(addrbuf) - 1); + strcat(buf, "]"); + + port = sin6_addr->sin6_port; +#endif + } + loginfo("Connection from %s:%d", addrbuf, port); + } + alarm(init_timeout ? init_timeout : timeout); pktlen = packet_read_line(0, line, sizeof(line)); alarm(0); @@ -414,8 +437,6 @@ static void check_max_connections(void) static void handle(int incoming, struct sockaddr *addr, int addrlen) { pid_t pid = fork(); - char addrbuf[256] = ""; - int port = -1; if (pid) { unsigned idx; @@ -436,26 +457,7 @@ static void handle(int incoming, struct sockaddr *addr, int addrlen) dup2(incoming, 1); close(incoming); - if (addr->sa_family == AF_INET) { - struct sockaddr_in *sin_addr = (void *) addr; - inet_ntop(AF_INET, &sin_addr->sin_addr, addrbuf, sizeof(addrbuf)); - port = sin_addr->sin_port; - -#ifndef NO_IPV6 - } else if (addr->sa_family == AF_INET6) { - struct sockaddr_in6 *sin6_addr = (void *) addr; - - char *buf = addrbuf; - *buf++ = '['; *buf = '\0'; /* stpcpy() is cool */ - inet_ntop(AF_INET6, &sin6_addr->sin6_addr, buf, sizeof(addrbuf) - 1); - strcat(buf, "]"); - - port = sin6_addr->sin6_port; -#endif - } - loginfo("Connection from %s:%d", addrbuf, port); - - exit(execute()); + exit(execute(addr)); } static void child_handler(int signo) @@ -751,8 +753,16 @@ int main(int argc, char **argv) } if (inetd_mode) { + struct sockaddr_storage ss; + struct sockaddr *peer = (struct sockaddr *)&ss; + socklen_t slen = sizeof(ss); + fclose(stderr); //FIXME: workaround - return execute(); + + if (getpeername(0, peer, &slen)) + peer = NULL; + + return execute(peer); } return serve(port); From 4170af82328e50a75723cee084ae779e7a882b9d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 20 Jun 2006 02:47:14 -0700 Subject: [PATCH 2/2] checkout -f: do not leave untracked working tree files. Earlier we did not consider untracked working tree files "precious", but we have always considered them fair game to clobber. These days, branch switching by read-tree is more careful and tries to protect untracked working tree files. This caused the following workflow to stop working: git checkout one-branch-with-file-F git checkout -f another-without-file-F git pull . one-branch-with-file-F Because the second checkout leaves F from the previous state as untracked file in the working tree, the merge would fail, trying to protect F from being clobbered. This changes "git checkout -f" to remove working tree files that are known to git in the switched-from state but do not exist in the switched-to state, borrowing the same logic from "reset --hard". Signed-off-by: Junio C Hamano --- git-checkout.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/git-checkout.sh b/git-checkout.sh index 564117f006..77c2593809 100755 --- a/git-checkout.sh +++ b/git-checkout.sh @@ -137,8 +137,7 @@ fi if [ "$force" ] then - git-read-tree --reset $new && - git-checkout-index -q -f -u -a + git-read-tree --reset -u $new else git-update-index --refresh >/dev/null merge_error=$(git-read-tree -m -u $old $new 2>&1) || (