From: Junio C Hamano Date: Fri, 21 Oct 2005 06:21:50 +0000 (-0700) Subject: Merge branch 'fixes' X-Git-Tag: v0.99.9~69 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4ae22d96fe9248dac4f26b1fc91154ba5e879799;p=git.git Merge branch 'fixes' --- 4ae22d96fe9248dac4f26b1fc91154ba5e879799 diff --cc daemon.c index 2b56d7d22,cec7e75d5..0c6182fb9 --- a/daemon.c +++ b/daemon.c @@@ -143,9 -126,13 +143,9 @@@ static int set_dir(const char *dir return -1; } - if (chdir(dir) < 0) { - logerror("Cannot chdir('%s'): %s", dir, strerror(errno)); + if ( chdir(dir) ) return -1; - - } - - chdir(".git"); + /* * Security on the cheap. * @@@ -485,57 -438,16 +485,57 @@@ static int socksetup(int port, int **so freeaddrinfo(ai0); - if (socknum == 0) - die("unable to allocate any listen sockets on port %u", port); + *socklist_p = socklist; + return socknum; +} + +#else /* NO_IPV6 */ + +static int socksetup(int port, int **socklist_p) +{ + struct sockaddr_in sin; + int sockfd; + + sockfd = socket(AF_INET, SOCK_STREAM, 0); + if (sockfd < 0) + return 0; + + memset(&sin, 0, sizeof sin); + sin.sin_family = AF_INET; + sin.sin_addr.s_addr = htonl(INADDR_ANY); + sin.sin_port = htons(port); + + if ( bind(sockfd, (struct sockaddr *)&sin, sizeof sin) < 0 ) { + close(sockfd); + return 0; + } + + *socklist_p = xmalloc(sizeof(int)); + **socklist_p = sockfd; +} + +#endif + +static int service_loop(int socknum, int *socklist) +{ + struct pollfd *pfd; + int i; + + pfd = xcalloc(socknum, sizeof(struct pollfd)); + + for (i = 0; i < socknum; i++) { + pfd[i].fd = socklist[i]; + pfd[i].events = POLLIN; + } + + signal(SIGCHLD, child_handler); - + for (;;) { int i; - fds = fds_init; - if (select(maxfd + 1, &fds, NULL, NULL, NULL) < 0) { + if (poll(pfd, socknum, -1) < 0) { if (errno != EINTR) { - error("select failed, resuming: %s", + error("poll failed, resuming: %s", strerror(errno)); sleep(1); } @@@ -563,17 -477,6 +563,17 @@@ } } +static int serve(int port) +{ + int socknum, *socklist; - ++ + socknum = socksetup(port, &socklist); + if (socknum == 0) + die("unable to allocate any listen sockets on port %u", port); - ++ + return service_loop(socknum, socklist); - } ++} + int main(int argc, char **argv) { int port = DEFAULT_GIT_PORT;