threads / bug / 8573

[BUG] 75d8ff1 fails on SunOS 5.9 (missing hsterror) from ba505322

Subject: [BUG] 75d8ff1 fails on SunOS 5.9 (missing hsterror) from ba505322

## tl;dr

11 messages between Jun 12, 2007 and Jun 18, 2007.

replies: 10people: 4as markdown or json

Randal L. Schwartz· Jun 12, 2007, 16:13 UTC · lore
    CC fetch-pack.o
fetch-pack.c: In function `get_pack':
fetch-pack.c:532: warning: int format, pid_t arg (arg 3)
    LINK git-fetch-pack
Undefined                       first referenced
 symbol                             in file
hstrerror                           libgit.a(connect.o)
ld: fatal: Symbol referencing errors. No output written to git-fetch-pack
collect2: ld returned 1 exit status
make: *** [git-fetch-pack] Error 1
I suspect this broke in ba505322 when connect.c added hsterror().

Yes, bumping to g18bece works fine. So it looks like we need a compat hsterror(), or it should be removed or ifdef'ed somehow. Paging Alex Riesen?

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Alex Riesen· Jun 12, 2007, 20:03 UTC · re: Randal L. Schwartz · lore

Re: [BUG] 75d8ff1 fails on SunOS 5.9 (missing hsterror) from ba505322

Randal L. Schwartz, Tue, Jun 12, 2007 18:13:40 +0200:
> I suspect this broke in ba505322 when connect.c added hsterror().
> 
> Yes, bumping to g18bece works fine.  So it looks like we need a compat
> hsterror(), or it should be removed or ifdef'ed somehow.  Paging Alex Riesen?
Looks like. What have they got instead to clarify what h_errno means?
Alex Riesen· Jun 12, 2007, 20:52 UTC · re: Randal L. Schwartz · lore

[PATCH] Do not use h_errno after connect(2): the function does not set it

Randal L. Schwartz noticed compilation problems on SunOS, which made me look at the code again. The thing is, h_errno is not used by connect(2), it is only for functions from netdb.h, like gethostbyname.

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---

This must fix your link problems (unless you want to use NO_IPV6=1, where another fix will be posted in a minute).

 connect.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/connect.c b/connect.c
index 7fab9c0..a5afd2a 100644
--- a/connect.c
+++ b/connect.c
@@ -224,11 +224,10 @@ static int git_tcp_connect_sock(char *host, int flags)
 		}
 		if (connect(sockfd, ai->ai_addr, ai->ai_addrlen) < 0) {
 			saved_errno = errno;
-			fprintf(stderr, "%s[%d: %s]: net=%s, errno=%s\n",
+			fprintf(stderr, "%s[%d: %s]: errno=%s\n",
 				host,
 				cnt,
 				ai_name(ai),
-				hstrerror(h_errno),
 				strerror(saved_errno));
 			close(sockfd);
 			sockfd = -1;
@@ -315,11 +314,10 @@ static int git_tcp_connect_sock(char *host, int flags)
 
 		if (connect(sockfd, (struct sockaddr *)&sa, sizeof sa) < 0) {
 			saved_errno = errno;
-			fprintf(stderr, "%s[%d: %s]: net=%s, errno=%s\n",
+			fprintf(stderr, "%s[%d: %s]: errno=%s\n",
 				host,
 				cnt,
 				inet_ntoa(*(struct in_addr *)&sa.sin_addr),
-				hstrerror(h_errno),
 				strerror(saved_errno));
 			close(sockfd);
 			sockfd = -1;
-- 
1.5.2.1.191.gc01a
Alex Riesen· Jun 12, 2007, 21:31 UTC · re: Alex Riesen · lore

[PATCH] Add a local implementation of hstrerror for the system which do not have it

The function converts the value of h_errno (last error of name resolver library, see netdb.h). One of systems which supposedly do not have the function is SunOS. POSIX does not mandate its presence.

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---

Randal, you seem to have access to a SunOS system. Could you try to compile your git with NO_IPV6 (if you already applied the previous fix, which removed superflous calls to hstrerror), and than again without it (just to be sure)?

 Makefile           |    5 +++++
 compat/hstrerror.c |   21 +++++++++++++++++++++
 git-compat-util.h  |    5 +++++
 3 files changed, 31 insertions(+), 0 deletions(-)
 create mode 100644 compat/hstrerror.c
diff --git a/Makefile b/Makefile
index 0f6540c..e054bc7 100644
--- a/Makefile
+++ b/Makefile
@@ -410,6 +410,7 @@ ifeq ($(uname_S),SunOS)
 	NEEDS_NSL = YesPlease
 	SHELL_PATH = /bin/bash
 	NO_STRCASESTR = YesPlease
+	NO_HSTRERROR = YesPlease
 	ifeq ($(uname_R),5.8)
 		NEEDS_LIBICONV = YesPlease
 		NO_UNSETENV = YesPlease
@@ -654,6 +655,10 @@ endif
 ifdef NO_PERL_MAKEMAKER
 	export NO_PERL_MAKEMAKER
 endif
+ifdef NO_HSTRERROR
+	COMPAT_CFLAGS += -DNO_HSTRERROR
+	COMPAT_OBJS += compat/hstrerror.o
+endif
 
 ifeq ($(TCLTK_PATH),)
 NO_TCLTK=NoThanks
diff --git a/compat/hstrerror.c b/compat/hstrerror.c
new file mode 100644
index 0000000..c59b808
--- /dev/null
+++ b/compat/hstrerror.c
@@ -0,0 +1,21 @@
+#include <string.h>
+#include <stdio.h>
+#include <netdb.h>
+
+const char *githstrerror(int err)
+{
+	static char buffer[32];
+	switch (err)
+	{
+	case HOST_NOT_FOUND:
+		return "Authoritative answer: host not found";
+	case NO_DATA:
+		return "Valid name, no data record of requested type";
+	case NO_RECOVERY:
+		return "Non recoverable errors, FORMERR, REFUSED, NOTIMP";
+	case TRY_AGAIN:
+		return "Non-authoritative \"host not found\", or SERVERFAIL";
+	}
+	sprintf(buffer, "Name resolution error %d", err);
+	return buffer;
+}
diff --git a/git-compat-util.h b/git-compat-util.h
index 6bd8987..b2ab3f8 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -167,6 +167,11 @@ extern size_t gitstrlcpy(char *, const char *, size_t);
 extern uintmax_t gitstrtoumax(const char *, char **, int);
 #endif
 
+#ifdef NO_HSTRERROR
+#define hstrerror githstrerror
+extern const char *githstrerror(int herror);
+#endif
+
 extern void release_pack_memory(size_t, int);
 
 static inline char* xstrdup(const char *str)
-- 
1.5.2.1.191.gc01a
Johannes Sixt· Jun 13, 2007, 07:05 UTC · re: Alex Riesen · lore

Re: [PATCH] Add a local implementation of hstrerror for the system which do not have it

Alex Riesen wrote:
> +       static char buffer[32];
> ...
> +       sprintf(buffer, "Name resolution error %d", err);

I don't think it's a problem for any current implementation, but it would be better to err on the conservative side: The buffer should be at least 44 chars wide to account for 20 digit negative numbers (thats the maximum if int is 64 bits wide).

-- Hannes
Brandon Casey· Jun 18, 2007, 21:28 UTC · re: Alex Riesen · lore

Re: [PATCH] Add a local implementation of hstrerror for the system which do not have it

Alex Riesen wrote:
> The function converts the value of h_errno (last error of name
> resolver library, see netdb.h). One of systems which supposedly do
> not have the function is SunOS. POSIX does not mandate its presence.

I saw a comment on another mailing list that hstrerror() is in the resolv library.

    So adding -lresolv should do it.
A quick compile works for my test program.
-brandon
Brandon Casey· Jun 18, 2007, 21:34 UTC · re: Brandon Casey · lore

Re: [PATCH] Add a local implementation of hstrerror for the system which do not have it

Brandon Casey wrote:
Show 11 quoted lines
> Alex Riesen wrote:
>> The function converts the value of h_errno (last error of name
>> resolver library, see netdb.h). One of systems which supposedly do
>> not have the function is SunOS. POSIX does not mandate its presence.
> 
> I saw a comment on another mailing list that hstrerror() is in the
> resolv library.
> 
>    So adding -lresolv should do it.
> 
> A quick compile works for my test program.
Here's a SunOS5.9 man page for hstrerror:
http://bama.ua.edu/cgi-bin/man-cgi?hstrerror+3RESOLV
which shows:
    cc [ flag ... ] file ... -lresolv  -lsocket  -lnsl [ library ... ]
-brandon
Alex Riesen· Jun 18, 2007, 21:37 UTC · re: Brandon Casey · lore

Re: [PATCH] Add a local implementation of hstrerror for the system which do not have it

Brandon Casey, Mon, Jun 18, 2007 23:28:10 +0200:
Show 12 quoted lines
> Alex Riesen wrote:
> >The function converts the value of h_errno (last error of name
> >resolver library, see netdb.h). One of systems which supposedly do
> >not have the function is SunOS. POSIX does not mandate its presence.
> 
> I saw a comment on another mailing list that hstrerror() is in the
> resolv library.
> 
>    So adding -lresolv should do it.
> 
> A quick compile works for my test program.
> 
Ah-ha. Good to know, thanks!
Still, the patch is correct: no need for hstrerror there.
Brandon Casey· Jun 18, 2007, 21:53 UTC · re: Alex Riesen · lore

Re: [PATCH] Add a local implementation of hstrerror for the system which do not have it

Alex Riesen wrote:
Show 16 quoted lines
> Brandon Casey, Mon, Jun 18, 2007 23:28:10 +0200:
>> Alex Riesen wrote:
>>> The function converts the value of h_errno (last error of name
>>> resolver library, see netdb.h). One of systems which supposedly do
>>> not have the function is SunOS. POSIX does not mandate its presence.
>> I saw a comment on another mailing list that hstrerror() is in the
>> resolv library.
>>
>>    So adding -lresolv should do it.
>>
>> A quick compile works for my test program.
>>
> 
> Ah-ha. Good to know, thanks!
> 
> Still, the patch is correct: no need for hstrerror there.
I see, right, just the NO_IPV6 case.
-brandon
Alex Riesen· Jun 13, 2007, 18:54 UTC · lore

[PATCH] Add a local implementation of hstrerror for the system which do not have it

The function converts the value of h_errno (last error of name resolver library, see netdb.h). One of systems which supposedly do not have the function is SunOS. POSIX does not mandate its presence.

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
 Makefile           |    5 +++++
 compat/hstrerror.c |   21 +++++++++++++++++++++
 git-compat-util.h  |    5 +++++
 3 files changed, 31 insertions(+), 0 deletions(-)
 create mode 100644 compat/hstrerror.c
diff --git a/Makefile b/Makefile
index 0f6540c..e054bc7 100644
--- a/Makefile
+++ b/Makefile
@@ -410,6 +410,7 @@ ifeq ($(uname_S),SunOS)
 	NEEDS_NSL = YesPlease
 	SHELL_PATH = /bin/bash
 	NO_STRCASESTR = YesPlease
+	NO_HSTRERROR = YesPlease
 	ifeq ($(uname_R),5.8)
 		NEEDS_LIBICONV = YesPlease
 		NO_UNSETENV = YesPlease
@@ -654,6 +655,10 @@ endif
 ifdef NO_PERL_MAKEMAKER
 	export NO_PERL_MAKEMAKER
 endif
+ifdef NO_HSTRERROR
+	COMPAT_CFLAGS += -DNO_HSTRERROR
+	COMPAT_OBJS += compat/hstrerror.o
+endif
 
 ifeq ($(TCLTK_PATH),)
 NO_TCLTK=NoThanks
diff --git a/compat/hstrerror.c b/compat/hstrerror.c
new file mode 100644
index 0000000..069c555
--- /dev/null
+++ b/compat/hstrerror.c
@@ -0,0 +1,21 @@
+#include <string.h>
+#include <stdio.h>
+#include <netdb.h>
+
+const char *githstrerror(int err)
+{
+	static char buffer[48];
+	switch (err)
+	{
+	case HOST_NOT_FOUND:
+		return "Authoritative answer: host not found";
+	case NO_DATA:
+		return "Valid name, no data record of requested type";
+	case NO_RECOVERY:
+		return "Non recoverable errors, FORMERR, REFUSED, NOTIMP";
+	case TRY_AGAIN:
+		return "Non-authoritative \"host not found\", or SERVERFAIL";
+	}
+	sprintf(buffer, "Name resolution error %d", err);
+	return buffer;
+}
diff --git a/git-compat-util.h b/git-compat-util.h
index 6bd8987..b2ab3f8 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -167,6 +167,11 @@ extern size_t gitstrlcpy(char *, const char *, size_t);
 extern uintmax_t gitstrtoumax(const char *, char **, int);
 #endif
 
+#ifdef NO_HSTRERROR
+#define hstrerror githstrerror
+extern const char *githstrerror(int herror);
+#endif
+
 extern void release_pack_memory(size_t, int);
 
 static inline char* xstrdup(const char *str)
-- 
1.5.2.1.270.g288d3f
Randal L. Schwartz· Jun 16, 2007, 15:21 UTC · re: Alex Riesen · lore

Re: [PATCH] Add a local implementation of hstrerror for the system which do not have it

>>>>> "Alex" == Alex Riesen <raa.lkml@gmail.com> writes:

Alex> The function converts the value of h_errno (last error of name Alex> resolver library, see netdb.h). Alex> One of systems which supposedly do not have the function is SunOS. Alex> POSIX does not mandate its presence.

Thanks... 952c8c5 compiles and installs fine on sunos now.
-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

← back to recent threads