cURL / Mailing Lists / curl-library / Single Mail

curl-library

curl tests issue with gethostname on illumos

From: Alexander Pyhalov <alp_at_rsu.ru>
Date: Sat, 10 Jan 2015 02:40:17 +0300

Hello.
I've just looked at updating OpenIndiana Hipster (illumos distribution)
curl version to 7.39 and found one interesting issue.

curl_setup_once.h includes unistd.h
and in unistd.h gethostname is defined as

int gethostname(char *name, int namelen)

However, in curl_setup.h we read

#ifndef GETHOSTNAME_TYPE_ARG2
# ifdef USE_WINSOCK
# define GETHOSTNAME_TYPE_ARG2 int
# else
# define GETHOSTNAME_TYPE_ARG2 size_t
# endif
#endif

So, when we try to compile gethostname function used by tests (gmake
check), we receive

In file included from
/export/home/alp/srcs/oi-userland/components/curl/curl-7.39.0/tests/libtest/sethostname.c:24:0:
/export/home/alp/srcs/oi-userland/components/curl/curl-7.39.0/tests/libtest/sethostname.h:44:3:
error: conflicting types for 'gethostname'
    gethostname(char *name, GETHOSTNAME_TYPE_ARG2 namelen);
    ^
In file included from
/export/home/alp/srcs/oi-userland/components/curl/curl-7.39.0/lib/curl_setup_once.h:77:0,
                  from
/export/home/alp/srcs/oi-userland/components/curl/curl-7.39.0/lib/curl_setup.h:654,
                  from
/export/home/alp/srcs/oi-userland/components/curl/curl-7.39.0/tests/libtest/sethostname.c:22:
/usr/include/unistd.h:352:12: note: previous declaration of
'gethostname' was here
  extern int gethostname(char *, int);
             ^
/export/home/alp/srcs/oi-userland/components/curl/curl-7.39.0/tests/libtest/sethostname.c:30:5:
error: conflicting types for 'gethostname'
  int gethostname(char *name, GETHOSTNAME_TYPE_ARG2 namelen)
      ^
In file included from
/export/home/alp/srcs/oi-userland/components/curl/curl-7.39.0/lib/curl_setup_once.h:77:0,
                  from
/export/home/alp/srcs/oi-userland/components/curl/curl-7.39.0/lib/curl_setup.h:654,
                  from
/export/home/alp/srcs/oi-userland/components/curl/curl-7.39.0/tests/libtest/sethostname.c:22:
/usr/include/unistd.h:352:12: note: previous declaration of
'gethostname' was here
  extern int gethostname(char *, int);

I don't think that changing GETHOSTNAME_TYPE_ARG2 definition is a good
idea, because this leads to ABI breakage.
Earlier this issue was hidden, because setup.h file didn't include
unistd.h.

For me the following patch solves this problem.

--- curl-7.39.0/tests/libtest/sethostname.h.~1~ 2015-01-10
02:26:18.633049476 +0300
+++ curl-7.39.0/tests/libtest/sethostname.h 2015-01-10
02:27:03.481546638 +0300
@@ -41,5 +41,9 @@
  #endif

  LIBHOSTNAME_EXTERN int FUNCALLCONV
+#ifdef __sun
+ gethostname(char *name, int namelen);
+#else
    gethostname(char *name, GETHOSTNAME_TYPE_ARG2 namelen);
+#endif

--- curl-7.39.0/tests/libtest/sethostname.c.~1~ 2015-01-10
02:24:55.256879968 +0300
+++ curl-7.39.0/tests/libtest/sethostname.c 2015-01-10
02:26:08.492685662 +0300
@@ -27,7 +27,11 @@
   * we force our own host name, in order to make some tests machine
independent
   */

+#ifdef __sun
+int gethostname(char *name, int namelen)
+#else
  int gethostname(char *name, GETHOSTNAME_TYPE_ARG2 namelen)
+#endif
  {
    const char *force_hostname = getenv("CURL_GETHOSTNAME");
    if(force_hostname) {

-- 
System Administrator of Southern Federal University Computer Center
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2015-01-10