From: Junio C Hamano Date: Thu, 28 Jul 2016 17:34:43 +0000 (-0700) Subject: Merge branch 'ew/daemon-socket-keepalive' X-Git-Tag: v2.10.0-rc0~76 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/b48dfd86c90cae3f98dca01101b7e298c0192d16?ds=inline;hp=-c Merge branch 'ew/daemon-socket-keepalive' Recent update to "git daemon" tries to enable the socket-level KEEPALIVE, but when it is spawned via inetd, the standard input file descriptor may not necessarily be connected to a socket. Suppress an ENOTSOCK error from setsockopt(). * ew/daemon-socket-keepalive: Windows: add missing definition of ENOTSOCK daemon: ignore ENOTSOCK from setsockopt --- b48dfd86c90cae3f98dca01101b7e298c0192d16 diff --combined compat/mingw.h index 233933ee86,7489d2980e..95e128fcfd --- a/compat/mingw.h +++ b/compat/mingw.h @@@ -73,6 -73,9 +73,9 @@@ typedef int pid_t #ifndef ECONNABORTED #define ECONNABORTED WSAECONNABORTED #endif + #ifndef ENOTSOCK + #define ENOTSOCK WSAENOTSOCK + #endif struct passwd { char *pw_name; @@@ -142,7 -145,6 +145,7 @@@ static inline int fcntl(int fd, int cmd #define sigemptyset(x) (void)0 static inline int sigaddset(sigset_t *set, int signum) { return 0; } +#define SIG_BLOCK 0 #define SIG_UNBLOCK 0 static inline int sigprocmask(int how, const sigset_t *set, sigset_t *oldset) { return 0; } @@@ -407,7 -409,7 +410,7 @@@ static inline void convert_slashes(cha int mingw_offset_1st_component(const char *path); #define offset_1st_component mingw_offset_1st_component #define PATH_SEP ';' -#ifndef __MINGW64_VERSION_MAJOR +#if !defined(__MINGW64_VERSION_MAJOR) && (!defined(_MSC_VER) || _MSC_VER < 1800) #define PRIuMAX "I64u" #define PRId64 "I64d" #else @@@ -417,6 -419,9 +420,6 @@@ void mingw_open_html(const char *path); #define open_html mingw_open_html -void mingw_mark_as_git_dir(const char *dir); -#define mark_as_git_dir mingw_mark_as_git_dir - /** * Converts UTF-8 encoded string to UTF-16LE. * @@@ -532,10 -537,10 +535,10 @@@ extern CRITICAL_SECTION pinfo_cs * A replacement of main() that adds win32 specific initialization. */ -void mingw_startup(); -#define main(c,v) dummy_decl_mingw_main(); \ +void mingw_startup(void); +#define main(c,v) dummy_decl_mingw_main(void); \ static int mingw_main(c,v); \ -int main(int argc, char **argv) \ +int main(int argc, const char **argv) \ { \ mingw_startup(); \ return mingw_main(__argc, (void *)__argv); \ diff --combined daemon.c index e647254c19,a84495113e..425aad0507 --- a/daemon.c +++ b/daemon.c @@@ -1,5 -1,6 +1,5 @@@ #include "cache.h" #include "pkt-line.h" -#include "exec_cmd.h" #include "run-command.h" #include "strbuf.h" #include "string-list.h" @@@ -31,7 -32,7 +31,7 @@@ static const char daemon_usage[] " [...]"; /* List of acceptable pathname prefixes */ -static char **ok_paths; +static const char **ok_paths; static int strict_paths; /* If this is set, git-daemon-export-ok is not required */ @@@ -239,7 -240,7 +239,7 @@@ static const char *path_ok(const char * } if ( ok_paths && *ok_paths ) { - char **pp; + const char **pp; int pathlen = strlen(path); /* The validation is done on the paths after enter_repo @@@ -672,9 -673,11 +672,11 @@@ static void set_keep_alive(int sockfd { int ka = 1; - if (setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, &ka, sizeof(ka)) < 0) - logerror("unable to set SO_KEEPALIVE on socket: %s", - strerror(errno)); + if (setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, &ka, sizeof(ka)) < 0) { + if (errno != ENOTSOCK) + logerror("unable to set SO_KEEPALIVE on socket: %s", + strerror(errno)); + } } static int execute(void) @@@ -1191,7 -1194,7 +1193,7 @@@ static int serve(struct string_list *li return service_loop(&socklist); } -int main(int argc, char **argv) +int cmd_main(int argc, const char **argv) { int listen_port = 0; struct string_list listen_addr = STRING_LIST_INIT_NODUP; @@@ -1201,8 -1204,12 +1203,8 @@@ struct credentials *cred = NULL; int i; - git_setup_gettext(); - - git_extract_argv0_path(argv[0]); - for (i = 1; i < argc; i++) { - char *arg = argv[i]; + const char *arg = argv[i]; const char *v; if (skip_prefix(arg, "--listen=", &v)) { @@@ -1376,7 -1383,8 +1378,7 @@@ if (detach) { if (daemonize()) die("--detach not supported on this platform"); - } else - sanitize_stdfds(); + } if (pid_file) write_file(pid_file, "%"PRIuMAX, (uintmax_t) getpid());