{"thread":{"id":"16867","subject":"[PATCH 1/3] daemon: handle freopen() failure","startedAt":"2008-12-26T09:46:25Z","lastAt":"2008-12-26T10:17:04Z","messageCount":4,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"98716","messageId":"1230284785.6728.26.camel@ubuntu.ubuntu-domain","threadId":"16867","inReplyTo":null,"subject":"[PATCH 1/3] daemon: handle freopen() failure","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2008-12-26T09:46:25Z","receivedAt":"2008-12-26T09:46:25Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Die if stderr couldn't be sent to /dev/null when operating in inetd\nmode and report the error message from the OS.\n\nThis fixes a compiler warning about the return value of freopen()\nbeing ignored on Ubuntu 8.10.\n\nSigned-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\n daemon.c |    4 +++-\n 1 files changed, 3 insertions(+), 1 deletions(-)\n\ndiff --git a/daemon.c b/daemon.c\nindex 1cef309..8c317be 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -1118,7 +1118,9 @@ int main(int argc, char **argv)\n \t\tstruct sockaddr *peer = (struct sockaddr *)&ss;\n \t\tsocklen_t slen = sizeof(ss);\n \n-\t\tfreopen(\"/dev/null\", \"w\", stderr);\n+\t\tif (!freopen(\"/dev/null\", \"w\", stderr))\n+\t\t\tdie(\"failed to redirect stderr to /dev/null: %s\",\n+\t\t\t    strerror(errno));\n \n \t\tif (getpeername(0, peer, &slen))\n \t\t\tpeer = NULL;\n-- \n1.6.1\n"},{"id":"98717","messageId":"1230285717.6728.40.camel@ubuntu.ubuntu-domain","threadId":"16867","inReplyTo":"1230284785.6728.26.camel@ubuntu.ubuntu-domain","subject":"[PATCH 2/3] daemon: cleanup: replace loop with if","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2008-12-26T10:01:57Z","receivedAt":"2008-12-26T10:01:57Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Replace a loop around an enter_repo() call, which was used to retry\na single time with a different parameter in case the first call fails,\nwith two calls and an if.  This is shorter and cleaner.\n\nSigned-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\n daemon.c |   18 +++++-------------\n 1 files changed, 5 insertions(+), 13 deletions(-)\n\ndiff --git a/daemon.c b/daemon.c\nindex 8c317be..4468fb9 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -150,7 +150,6 @@ static char *path_ok(char *directory)\n {\n \tstatic char rpath[PATH_MAX];\n \tstatic char interp_path[PATH_MAX];\n-\tint retried_path = 0;\n \tchar *path;\n \tchar *dir;\n \n@@ -219,22 +218,15 @@ static char *path_ok(char *directory)\n \t\tdir = rpath;\n \t}\n \n-\tdo {\n-\t\tpath = enter_repo(dir, strict_paths);\n-\t\tif (path)\n-\t\t\tbreak;\n-\n+\tpath = enter_repo(dir, strict_paths);\n+\tif (!path && base_path && base_path_relaxed) {\n \t\t/*\n \t\t * if we fail and base_path_relaxed is enabled, try without\n \t\t * prefixing the base path\n \t\t */\n-\t\tif (base_path && base_path_relaxed && !retried_path) {\n-\t\t\tdir = directory;\n-\t\t\tretried_path = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tbreak;\n-\t} while (1);\n+\t\tdir = directory;\n+\t\tpath = enter_repo(dir, strict_paths);\n+\t}\n \n \tif (!path) {\n \t\tlogerror(\"'%s': unable to chdir or not a git archive\", dir);\n-- \n1.6.1\n"},{"id":"98718","messageId":"1230286335.6728.51.camel@ubuntu.ubuntu-domain","threadId":"16867","inReplyTo":"1230285717.6728.40.camel@ubuntu.ubuntu-domain","subject":"[PATCH 3/3] daemon: cleanup: factor out xstrdup_tolower()","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2008-12-26T10:12:15Z","receivedAt":"2008-12-26T10:12:15Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Add xstrdup_tolower(), a helper to get a lower case copy of a\nstring, and use it in two cases.\n\nSigned-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\n daemon.c |   34 +++++++++++++---------------------\n 1 files changed, 13 insertions(+), 21 deletions(-)\n\ndiff --git a/daemon.c b/daemon.c\nindex 4468fb9..60bf6c7 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -397,6 +397,14 @@ static void make_service_overridable(const char *name, int ena)\n \tdie(\"No such service %s\", name);\n }\n \n+static char *xstrdup_tolower(const char *str)\n+{\n+\tchar *p, *dup = xstrdup(str);\n+\tfor (p = dup; *p; p++)\n+\t\t*p = tolower(*p);\n+\treturn dup;\n+}\n+\n /*\n  * Separate the \"extra args\" information as supplied by the client connection.\n  */\n@@ -405,7 +413,6 @@ static void parse_extra_args(char *extra_args, int buflen)\n \tchar *val;\n \tint vallen;\n \tchar *end = extra_args + buflen;\n-\tchar *hp;\n \n \twhile (extra_args < end && *extra_args) {\n \t\tsaw_extended_args = 1;\n@@ -423,7 +430,7 @@ static void parse_extra_args(char *extra_args, int buflen)\n \t\t\t\t\ttcp_port = xstrdup(port);\n \t\t\t\t}\n \t\t\t\tfree(hostname);\n-\t\t\t\thostname = xstrdup(host);\n+\t\t\t\thostname = xstrdup_tolower(host);\n \t\t\t}\n \n \t\t\t/* On to the next one */\n@@ -432,19 +439,10 @@ static void parse_extra_args(char *extra_args, int buflen)\n \t}\n \n \t/*\n-\t * Replace literal host with lowercase-ized hostname.\n-\t */\n-\thp = hostname;\n-\tif (!hp)\n-\t\treturn;\n-\tfor ( ; *hp; hp++)\n-\t\t*hp = tolower(*hp);\n-\n-\t/*\n \t * Locate canonical hostname and its IP address.\n \t */\n+\tif (hostname) {\n #ifndef NO_IPV6\n-\t{\n \t\tstruct addrinfo hints;\n \t\tstruct addrinfo *ai, *ai0;\n \t\tint gai;\n@@ -468,9 +466,7 @@ static void parse_extra_args(char *extra_args, int buflen)\n \t\t\t}\n \t\t\tfreeaddrinfo(ai0);\n \t\t}\n-\t}\n #else\n-\t{\n \t\tstruct hostent *hent;\n \t\tstruct sockaddr_in sa;\n \t\tchar **ap;\n@@ -491,8 +487,8 @@ static void parse_extra_args(char *extra_args, int buflen)\n \t\tcanon_hostname = xstrdup(hent->h_name);\n \t\tfree(ip_address);\n \t\tip_address = xstrdup(addrbuf);\n-\t}\n #endif\n+\t}\n }\n \n \n@@ -945,12 +941,8 @@ int main(int argc, char **argv)\n \t\tchar *arg = argv[i];\n \n \t\tif (!prefixcmp(arg, \"--listen=\")) {\n-\t\t    char *p = arg + 9;\n-\t\t    char *ph = listen_addr = xmalloc(strlen(arg + 9) + 1);\n-\t\t    while (*p)\n-\t\t\t*ph++ = tolower(*p++);\n-\t\t    *ph = 0;\n-\t\t    continue;\n+\t\t\tlisten_addr = xstrdup_tolower(arg + 9);\n+\t\t\tcontinue;\n \t\t}\n \t\tif (!prefixcmp(arg, \"--port=\")) {\n \t\t\tchar *end;\n-- \n1.6.1\n"},{"id":"98719","messageId":"1230286624.6728.56.camel@ubuntu.ubuntu-domain","threadId":"16867","inReplyTo":"1230284785.6728.26.camel@ubuntu.ubuntu-domain","subject":"[PATCH] merge-file: handle freopen() failure","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2008-12-26T10:17:04Z","receivedAt":"2008-12-26T10:17:04Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Report the error if redirection of stderr to /dev/null failed.\n\nThis silences a compiler warning about ignoring the return value\nof freopen() on Ubuntu 8.10.\n\nSigned-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\n builtin-merge-file.c |    7 +++++--\n 1 files changed, 5 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin-merge-file.c b/builtin-merge-file.c\nindex 9d4e874..96edb97 100644\n--- a/builtin-merge-file.c\n+++ b/builtin-merge-file.c\n@@ -51,8 +51,11 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)\n \targc = parse_options(argc, argv, options, merge_file_usage, 0);\n \tif (argc != 3)\n \t\tusage_with_options(merge_file_usage, options);\n-\tif (quiet)\n-\t\tfreopen(\"/dev/null\", \"w\", stderr);\n+\tif (quiet) {\n+\t\tif (!freopen(\"/dev/null\", \"w\", stderr))\n+\t\t\treturn error(\"failed to redirect stderr to /dev/null: \"\n+\t\t\t\t     \"%s\\n\", strerror(errno));\n+\t}\n \n \tfor (i = 0; i < 3; i++) {\n \t\tif (!names[i])\n"}]}