git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] daemon: handle freopen() failure
@ 2008-12-26  9:46 René Scharfe
  2008-12-26 10:01 ` [PATCH 2/3] daemon: cleanup: replace loop with if René Scharfe
  2008-12-26 10:17 ` [PATCH] merge-file: handle freopen() failure René Scharfe
  0 siblings, 2 replies; 4+ messages in thread
From: René Scharfe @ 2008-12-26  9:46 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List

Die if stderr couldn't be sent to /dev/null when operating in inetd
mode and report the error message from the OS.

This fixes a compiler warning about the return value of freopen()
being ignored on Ubuntu 8.10.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
 daemon.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/daemon.c b/daemon.c
index 1cef309..8c317be 100644
--- a/daemon.c
+++ b/daemon.c
@@ -1118,7 +1118,9 @@ int main(int argc, char **argv)
 		struct sockaddr *peer = (struct sockaddr *)&ss;
 		socklen_t slen = sizeof(ss);
 
-		freopen("/dev/null", "w", stderr);
+		if (!freopen("/dev/null", "w", stderr))
+			die("failed to redirect stderr to /dev/null: %s",
+			    strerror(errno));
 
 		if (getpeername(0, peer, &slen))
 			peer = NULL;
-- 
1.6.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] daemon: cleanup: replace loop with if
  2008-12-26  9:46 [PATCH 1/3] daemon: handle freopen() failure René Scharfe
@ 2008-12-26 10:01 ` René Scharfe
  2008-12-26 10:12   ` [PATCH 3/3] daemon: cleanup: factor out xstrdup_tolower() René Scharfe
  2008-12-26 10:17 ` [PATCH] merge-file: handle freopen() failure René Scharfe
  1 sibling, 1 reply; 4+ messages in thread
From: René Scharfe @ 2008-12-26 10:01 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List

Replace a loop around an enter_repo() call, which was used to retry
a single time with a different parameter in case the first call fails,
with two calls and an if.  This is shorter and cleaner.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
 daemon.c |   18 +++++-------------
 1 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/daemon.c b/daemon.c
index 8c317be..4468fb9 100644
--- a/daemon.c
+++ b/daemon.c
@@ -150,7 +150,6 @@ static char *path_ok(char *directory)
 {
 	static char rpath[PATH_MAX];
 	static char interp_path[PATH_MAX];
-	int retried_path = 0;
 	char *path;
 	char *dir;
 
@@ -219,22 +218,15 @@ static char *path_ok(char *directory)
 		dir = rpath;
 	}
 
-	do {
-		path = enter_repo(dir, strict_paths);
-		if (path)
-			break;
-
+	path = enter_repo(dir, strict_paths);
+	if (!path && base_path && base_path_relaxed) {
 		/*
 		 * if we fail and base_path_relaxed is enabled, try without
 		 * prefixing the base path
 		 */
-		if (base_path && base_path_relaxed && !retried_path) {
-			dir = directory;
-			retried_path = 1;
-			continue;
-		}
-		break;
-	} while (1);
+		dir = directory;
+		path = enter_repo(dir, strict_paths);
+	}
 
 	if (!path) {
 		logerror("'%s': unable to chdir or not a git archive", dir);
-- 
1.6.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] daemon: cleanup: factor out xstrdup_tolower()
  2008-12-26 10:01 ` [PATCH 2/3] daemon: cleanup: replace loop with if René Scharfe
@ 2008-12-26 10:12   ` René Scharfe
  0 siblings, 0 replies; 4+ messages in thread
From: René Scharfe @ 2008-12-26 10:12 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List

Add xstrdup_tolower(), a helper to get a lower case copy of a
string, and use it in two cases.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
 daemon.c |   34 +++++++++++++---------------------
 1 files changed, 13 insertions(+), 21 deletions(-)

diff --git a/daemon.c b/daemon.c
index 4468fb9..60bf6c7 100644
--- a/daemon.c
+++ b/daemon.c
@@ -397,6 +397,14 @@ static void make_service_overridable(const char *name, int ena)
 	die("No such service %s", name);
 }
 
+static char *xstrdup_tolower(const char *str)
+{
+	char *p, *dup = xstrdup(str);
+	for (p = dup; *p; p++)
+		*p = tolower(*p);
+	return dup;
+}
+
 /*
  * Separate the "extra args" information as supplied by the client connection.
  */
@@ -405,7 +413,6 @@ static void parse_extra_args(char *extra_args, int buflen)
 	char *val;
 	int vallen;
 	char *end = extra_args + buflen;
-	char *hp;
 
 	while (extra_args < end && *extra_args) {
 		saw_extended_args = 1;
@@ -423,7 +430,7 @@ static void parse_extra_args(char *extra_args, int buflen)
 					tcp_port = xstrdup(port);
 				}
 				free(hostname);
-				hostname = xstrdup(host);
+				hostname = xstrdup_tolower(host);
 			}
 
 			/* On to the next one */
@@ -432,19 +439,10 @@ static void parse_extra_args(char *extra_args, int buflen)
 	}
 
 	/*
-	 * Replace literal host with lowercase-ized hostname.
-	 */
-	hp = hostname;
-	if (!hp)
-		return;
-	for ( ; *hp; hp++)
-		*hp = tolower(*hp);
-
-	/*
 	 * Locate canonical hostname and its IP address.
 	 */
+	if (hostname) {
 #ifndef NO_IPV6
-	{
 		struct addrinfo hints;
 		struct addrinfo *ai, *ai0;
 		int gai;
@@ -468,9 +466,7 @@ static void parse_extra_args(char *extra_args, int buflen)
 			}
 			freeaddrinfo(ai0);
 		}
-	}
 #else
-	{
 		struct hostent *hent;
 		struct sockaddr_in sa;
 		char **ap;
@@ -491,8 +487,8 @@ static void parse_extra_args(char *extra_args, int buflen)
 		canon_hostname = xstrdup(hent->h_name);
 		free(ip_address);
 		ip_address = xstrdup(addrbuf);
-	}
 #endif
+	}
 }
 
 
@@ -945,12 +941,8 @@ int main(int argc, char **argv)
 		char *arg = argv[i];
 
 		if (!prefixcmp(arg, "--listen=")) {
-		    char *p = arg + 9;
-		    char *ph = listen_addr = xmalloc(strlen(arg + 9) + 1);
-		    while (*p)
-			*ph++ = tolower(*p++);
-		    *ph = 0;
-		    continue;
+			listen_addr = xstrdup_tolower(arg + 9);
+			continue;
 		}
 		if (!prefixcmp(arg, "--port=")) {
 			char *end;
-- 
1.6.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] merge-file: handle freopen() failure
  2008-12-26  9:46 [PATCH 1/3] daemon: handle freopen() failure René Scharfe
  2008-12-26 10:01 ` [PATCH 2/3] daemon: cleanup: replace loop with if René Scharfe
@ 2008-12-26 10:17 ` René Scharfe
  1 sibling, 0 replies; 4+ messages in thread
From: René Scharfe @ 2008-12-26 10:17 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List

Report the error if redirection of stderr to /dev/null failed.

This silences a compiler warning about ignoring the return value
of freopen() on Ubuntu 8.10.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
 builtin-merge-file.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/builtin-merge-file.c b/builtin-merge-file.c
index 9d4e874..96edb97 100644
--- a/builtin-merge-file.c
+++ b/builtin-merge-file.c
@@ -51,8 +51,11 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
 	argc = parse_options(argc, argv, options, merge_file_usage, 0);
 	if (argc != 3)
 		usage_with_options(merge_file_usage, options);
-	if (quiet)
-		freopen("/dev/null", "w", stderr);
+	if (quiet) {
+		if (!freopen("/dev/null", "w", stderr))
+			return error("failed to redirect stderr to /dev/null: "
+				     "%s\n", strerror(errno));
+	}
 
 	for (i = 0; i < 3; i++) {
 		if (!names[i])

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-12-26 10:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-26  9:46 [PATCH 1/3] daemon: handle freopen() failure René Scharfe
2008-12-26 10:01 ` [PATCH 2/3] daemon: cleanup: replace loop with if René Scharfe
2008-12-26 10:12   ` [PATCH 3/3] daemon: cleanup: factor out xstrdup_tolower() René Scharfe
2008-12-26 10:17 ` [PATCH] merge-file: handle freopen() failure René Scharfe

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).