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

11 messages from 2007-06-12 to 2007-06-18. Participants: Randal L. Schwartz, Alex Riesen, Johannes Sixt, Brandon Casey.
Thread: https://gitlist.dev/t/8573

## Randal L. Schwartz, 2007-06-12 16:13

Subject: [BUG] 75d8ff1 fails on SunOS 5.9 (missing hsterror) from ba505322
Message-ID: <86ejkh40cr.fsf@blue.stonehenge.com>
URL: https://gitlist.dev/e/86ejkh40cr.fsf%40blue.stonehenge.com

```

    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, 2007-06-12 20:03

Subject: Re: [BUG] 75d8ff1 fails on SunOS 5.9 (missing hsterror) from ba505322
Message-ID: <20070612200307.GB2459@steel.home>
URL: https://gitlist.dev/e/20070612200307.GB2459%40steel.home
In-Reply-To: <86ejkh40cr.fsf@blue.stonehenge.com>

```
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, 2007-06-12 20:52

Subject: [PATCH] Do not use h_errno after connect(2): the function does not set it
Message-ID: <20070612205210.GC2459@steel.home>
URL: https://gitlist.dev/e/20070612205210.GC2459%40steel.home
In-Reply-To: <86ejkh40cr.fsf@blue.stonehenge.com>

```
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, 2007-06-12 21:31

Subject: [PATCH] Add a local implementation of hstrerror for the system which do not have it
Message-ID: <20070612213129.GD2459@steel.home>
URL: https://gitlist.dev/e/20070612213129.GD2459%40steel.home
In-Reply-To: <20070612205210.GC2459@steel.home>

```
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, 2007-06-13 07:05

Subject: Re: [PATCH] Add a local implementation of hstrerror for the system which do not have it
Message-ID: <466F971F.C74761E2@eudaptics.com>
URL: https://gitlist.dev/e/466F971F.C74761E2%40eudaptics.com
In-Reply-To: <20070612213129.GD2459@steel.home>

```
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

```

## Alex Riesen, 2007-06-13 18:54

Subject: [PATCH] Add a local implementation of hstrerror for the system which do not have it
Message-ID: <20070613185432.GA3412@steel.home>
URL: https://gitlist.dev/e/20070613185432.GA3412%40steel.home
In-Reply-To: <81b0412b0706130051l570e6ab7y48d6eea8c6b2d97e@mail.gmail.com>

```
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, 2007-06-16 15:21

Subject: Re: [PATCH] Add a local implementation of hstrerror for the system which do not have it
Message-ID: <86tzt7udq2.fsf@blue.stonehenge.com>
URL: https://gitlist.dev/e/86tzt7udq2.fsf%40blue.stonehenge.com
In-Reply-To: <20070613185432.GA3412@steel.home>

```
>>>>> "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!

```

## Brandon Casey, 2007-06-18 21:28

Subject: Re: [PATCH] Add a local implementation of hstrerror for the system which do not have it
Message-ID: <4676F8EA.1030305@nrlssc.navy.mil>
URL: https://gitlist.dev/e/4676F8EA.1030305%40nrlssc.navy.mil
In-Reply-To: <20070612213129.GD2459@steel.home>

```
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, 2007-06-18 21:34

Subject: Re: [PATCH] Add a local implementation of hstrerror for the system which do not have it
Message-ID: <4676FA59.5040602@nrlssc.navy.mil>
URL: https://gitlist.dev/e/4676FA59.5040602%40nrlssc.navy.mil
In-Reply-To: <4676F8EA.1030305@nrlssc.navy.mil>

```
Brandon Casey wrote:
> 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, 2007-06-18 21:37

Subject: Re: [PATCH] Add a local implementation of hstrerror for the system which do not have it
Message-ID: <20070618213749.GB16397@steel.home>
URL: https://gitlist.dev/e/20070618213749.GB16397%40steel.home
In-Reply-To: <4676F8EA.1030305@nrlssc.navy.mil>

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

```

## Brandon Casey, 2007-06-18 21:53

Subject: Re: [PATCH] Add a local implementation of hstrerror for the system which do not have it
Message-ID: <4676FED4.70905@nrlssc.navy.mil>
URL: https://gitlist.dev/e/4676FED4.70905%40nrlssc.navy.mil
In-Reply-To: <20070618213749.GB16397@steel.home>

```
Alex Riesen wrote:
> 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

```
