git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Erik Faye-Lund <kusmabite@googlemail.com>
To: msysgit@googlecode.com
Cc: git@vger.kernel.org, dotzenlabs@gmail.com,
	Erik Faye-Lund <kusmabite@gmail.com>
Subject: [PATCH/RFC 11/11] mingw: compile git-daemon
Date: Thu, 26 Nov 2009 00:39:18 +0000	[thread overview]
Message-ID: <1259195958-2372-12-git-send-email-kusmabite@gmail.com> (raw)
In-Reply-To: <1259195958-2372-11-git-send-email-kusmabite@gmail.com>

--user and --detach are disabled on Windows due to lack of
fork(), setuid(), setgid(), setsid() and initgroups().

Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
---
 Makefile       |    6 +++---
 compat/mingw.h |    1 +
 daemon.c       |   19 ++++++++++++++-----
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile
index 3b01694..406ca81 100644
--- a/Makefile
+++ b/Makefile
@@ -352,6 +352,7 @@ EXTRA_PROGRAMS =
 
 # ... and all the rest that could be moved out of bindir to gitexecdir
 PROGRAMS += $(EXTRA_PROGRAMS)
+PROGRAMS += git-daemon$X
 PROGRAMS += git-fast-import$X
 PROGRAMS += git-hash-object$X
 PROGRAMS += git-imap-send$X
@@ -981,6 +982,8 @@ ifneq (,$(findstring MINGW,$(uname_S)))
 	OBJECT_CREATION_USES_RENAMES = UnfortunatelyNeedsTo
 	NO_REGEX = YesPlease
 	BLK_SHA1 = YesPlease
+	NO_INET_PTON = YesPlease
+	NO_INET_NTOP = YesPlease
 	COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/fnmatch
 	COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
 	# We have GCC, so let's make use of those nice options
@@ -1079,9 +1082,6 @@ ifdef ZLIB_PATH
 endif
 EXTLIBS += -lz
 
-ifndef NO_POSIX_ONLY_PROGRAMS
-	PROGRAMS += git-daemon$X
-endif
 ifndef NO_OPENSSL
 	OPENSSL_LIBSSL = -lssl
 	ifdef OPENSSLDIR
diff --git a/compat/mingw.h b/compat/mingw.h
index 576b1a1..1b0dd5b 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -6,6 +6,7 @@
 
 typedef int pid_t;
 typedef int socklen_t;
+typedef unsigned int gid_t;
 #define hstrerror strerror
 
 #define S_IFLNK    0120000 /* Symbolic link */
diff --git a/daemon.c b/daemon.c
index 130e951..5872ec7 100644
--- a/daemon.c
+++ b/daemon.c
@@ -616,7 +616,7 @@ static struct child {
 	struct sockaddr_storage address;
 } *firstborn;
 
-static void add_child(struct async *async, struct sockaddr *addr, int addrlen)
+static void add_child(struct async *async, struct sockaddr *addr, socklen_t addrlen)
 {
 	struct child *newborn, **cradle;
 
@@ -679,7 +679,7 @@ int async_execute(int fd, void *data)
 	return ret;
 }
 
-static void handle(int incoming, struct sockaddr *addr, int addrlen)
+static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen)
 {
 	struct sockaddr_storage *ss;
 	struct async async = { 0 };
@@ -884,7 +884,7 @@ static int service_loop(int socknum, int *socklist)
 		for (i = 0; i < socknum; i++) {
 			if (pfd[i].revents & POLLIN) {
 				struct sockaddr_storage ss;
-				unsigned int sslen = sizeof(ss);
+				socklen_t sslen = sizeof(ss);
 				int incoming = accept(pfd[i].fd, (struct sockaddr *)&ss, &sslen);
 				if (incoming < 0) {
 					switch (errno) {
@@ -916,6 +916,7 @@ static void sanitize_stdfds(void)
 
 static void daemonize(void)
 {
+#ifndef WIN32
 	switch (fork()) {
 		case 0:
 			break;
@@ -930,6 +931,9 @@ static void daemonize(void)
 	close(1);
 	close(2);
 	sanitize_stdfds();
+#else
+	die("--detach is not supported on Windows");
+#endif
 }
 
 static void store_pid(const char *path)
@@ -950,10 +954,12 @@ static int serve(char *listen_addr, int listen_port, struct passwd *pass, gid_t
 		die("unable to allocate any listen sockets on host %s port %u",
 		    listen_addr, listen_port);
 
+#ifndef WIN32
 	if (pass && gid &&
 	    (initgroups(pass->pw_name, gid) || setgid (gid) ||
 	     setuid(pass->pw_uid)))
 		die("cannot drop privileges");
+#endif
 
 	return service_loop(socknum, socklist);
 }
@@ -966,7 +972,6 @@ int main(int argc, char **argv)
 	const char *pid_file = NULL, *user_name = NULL, *group_name = NULL;
 	int detach = 0;
 	struct passwd *pass = NULL;
-	struct group *group;
 	gid_t gid = 0;
 	int i;
 
@@ -1110,6 +1115,7 @@ int main(int argc, char **argv)
 		die("--group supplied without --user");
 
 	if (user_name) {
+#ifndef WIN32
 		pass = getpwnam(user_name);
 		if (!pass)
 			die("user not found - %s", user_name);
@@ -1117,12 +1123,15 @@ int main(int argc, char **argv)
 		if (!group_name)
 			gid = pass->pw_gid;
 		else {
-			group = getgrnam(group_name);
+			struct group *group = getgrnam(group_name);
 			if (!group)
 				die("group not found - %s", group_name);
 
 			gid = group->gr_gid;
 		}
+#else
+		die("--user is not supported on Windows");
+#endif
 	}
 
 	if (strict_paths && (!ok_paths || !*ok_paths))
-- 
1.6.5.rc2.7.g4f8d3

  reply	other threads:[~2009-11-26  0:40 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-26  0:39 [PATCH/RFC 00/11] daemon-win32 Erik Faye-Lund
2009-11-26  0:39 ` [PATCH/RFC 01/11] mingw: add network-wrappers for daemon Erik Faye-Lund
2009-11-26  0:39   ` [PATCH/RFC 02/11] strbuf: add non-variadic function strbuf_vaddf() Erik Faye-Lund
2009-11-26  0:39     ` [PATCH/RFC 03/11] mingw: implement syslog Erik Faye-Lund
2009-11-26  0:39       ` [PATCH/RFC 04/11] compat: add inet_pton and inet_ntop prototypes Erik Faye-Lund
2009-11-26  0:39         ` [PATCH/RFC 05/11] inet_ntop: fix a couple of old-style decls Erik Faye-Lund
2009-11-26  0:39           ` [PATCH/RFC 06/11] run-command: add kill_async() and is_async_alive() Erik Faye-Lund
2009-11-26  0:39             ` [PATCH/RFC 07/11] run-command: support input-fd Erik Faye-Lund
2009-11-26  0:39               ` [PATCH/RFC 08/11] daemon: use explicit file descriptor Erik Faye-Lund
2009-11-26  0:39                 ` [PATCH/RFC 09/11] daemon: use run-command api for async serving Erik Faye-Lund
2009-11-26  0:39                   ` [PATCH/RFC 10/11] daemon: use full buffered mode for stderr Erik Faye-Lund
2009-11-26  0:39                     ` Erik Faye-Lund [this message]
2009-11-26  0:43 ` [PATCH/RFC 00/11] daemon-win32 Erik Faye-Lund
  -- strict thread matches above, loose matches on Subject: below --
2009-11-26  0:44 Erik Faye-Lund
2009-11-26  0:44 ` [PATCH/RFC 01/11] mingw: add network-wrappers for daemon Erik Faye-Lund
2009-11-26  0:44   ` [PATCH/RFC 02/11] strbuf: add non-variadic function strbuf_vaddf() Erik Faye-Lund
2009-11-26  0:44     ` [PATCH/RFC 03/11] mingw: implement syslog Erik Faye-Lund
2009-11-26  0:44       ` [PATCH/RFC 04/11] compat: add inet_pton and inet_ntop prototypes Erik Faye-Lund
2009-11-26  0:44         ` [PATCH/RFC 05/11] inet_ntop: fix a couple of old-style decls Erik Faye-Lund
2009-11-26  0:44           ` [PATCH/RFC 06/11] run-command: add kill_async() and is_async_alive() Erik Faye-Lund
2009-11-26  0:44             ` [PATCH/RFC 07/11] run-command: support input-fd Erik Faye-Lund
2009-11-26  0:44               ` [PATCH/RFC 08/11] daemon: use explicit file descriptor Erik Faye-Lund
2009-11-26  0:44                 ` [PATCH/RFC 09/11] daemon: use run-command api for async serving Erik Faye-Lund
2009-11-26  0:44                   ` [PATCH/RFC 10/11] daemon: use full buffered mode for stderr Erik Faye-Lund
2009-11-26  0:44                     ` [PATCH/RFC 11/11] mingw: compile git-daemon Erik Faye-Lund

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1259195958-2372-12-git-send-email-kusmabite@gmail.com \
    --to=kusmabite@googlemail.com \
    --cc=dotzenlabs@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=kusmabite@gmail.com \
    --cc=msysgit@googlecode.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).