[CDRIVER-2015] Detect socket API param types with Autotools for HP-UX Created: 02/Feb/17  Updated: 15/Mar/17  Resolved: 15/Mar/17

Status: Closed
Project: C Driver
Component/s: Build, libmongoc
Affects Version/s: 1.6.0
Fix Version/s: 1.6.2

Type: Bug Priority: Major - P3
Reporter: Aleksander Melnikov Assignee: A. Jesse Jiryu Davis
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

HPUX 11.31
Itanium LP64
gcc-4.8.5


Issue Links:
Related
is related to CDRIVER-1973 Add support for HPUX Closed
is related to CDRIVER-2080 Check param types of getpeername, etc... Closed

 Description   

mongoc_socklen_t must choice type on HPUX by checking _XOPEN_SOURCE_EXTENDED
More info here: https://curl.haxx.se/mail/lib-2009-04/0287.html



 Comments   
Comment by Aleksander Melnikov [ 15/Mar/17 ]

done https://github.com/mongodb/mongo-c-driver/pull/427

Comment by A. Jesse Jiryu Davis [ 15/Mar/17 ]

r1.6: https://github.com/mongodb/mongo-c-driver/commit/33a0d77966c796a7037350f3f9d9fcf87dccc247

Comment by Githook User [ 15/Mar/17 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-2015 getpeername and getsockopt params, part 2
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/63757304e5e97a8beb4f6d1bac18c7723a6f421d

Comment by A. Jesse Jiryu Davis [ 15/Mar/17 ]

Cool! If you offer a pull request here we can try it out:

https://github.com/mongodb/mongo-c-driver/blob/master/CMakeLists.txt

Please put "CDRIVER-2080" in the commit message.

Comment by Aleksander Melnikov [ 15/Mar/17 ]

I'm propose next contribution to CMakeLists.txt:

cmake_minimum_required(VERSION 3.2)
 
set(MONGOC_ACCEPT_ARG2_LIST "struct sockaddr" "void")
set(MONGOC_ACCEPT_ARG3_LIST "socklen_t" "size_t" "int")
 
 
list(LENGTH MONGOC_ACCEPT_ARG2_LIST MONGOC_ACCEPT_ARG2_LIST_LEN)
math(EXPR MONGOC_ACCEPT_ARG2_LIST_LEN_R "${MONGOC_ACCEPT_ARG2_LIST_LEN} - 1")
list(LENGTH MONGOC_ACCEPT_ARG3_LIST MONGOC_ACCEPT_ARG3_LIST_LEN)
math(EXPR MONGOC_ACCEPT_ARG3_LIST_LEN_R "${MONGOC_ACCEPT_ARG3_LIST_LEN} - 1")
 
foreach(MONGOC_ACCEPT_ARG2_L RANGE ${MONGOC_ACCEPT_ARG2_LIST_LEN_R})
foreach(MONGOC_ACCEPT_ARG3_L RANGE ${MONGOC_ACCEPT_ARG3_LIST_LEN_R})
 
list(GET MONGOC_ACCEPT_ARG2_LIST ${MONGOC_ACCEPT_ARG2_L} MONGOC_ACCEPT_ARG2_VAL)
list(GET MONGOC_ACCEPT_ARG3_LIST ${MONGOC_ACCEPT_ARG3_L} MONGOC_ACCEPT_ARG3_VAL)
 
FILE(WRITE accept_test.cxx
"#include <sys/types.h>
 #include <sys/socket.h>
 
 int main ()
 {
   int a = 0;
   ${MONGOC_ACCEPT_ARG2_VAL} *b = 0;
   ${MONGOC_ACCEPT_ARG3_VAL} *c = 0;
   accept (a, b, c);
   return 0;
}
")
  message(STATUS "${MONGOC_ACCEPT_ARG2_VAL} & ${MONGOC_ACCEPT_ARG3_VAL} ${RES}")
  TRY_COMPILE(RES ${CMAKE_CURRENT_BINARY_DIR}
  ${CMAKE_CURRENT_SOURCE_DIR}/accept_test.cxx CMAKE_FLAGS
  "-DCMAKE_CXX_LINK_EXECUTABLE='echo not linking now...'" OUTPUT_VARIABLE
  LOG2)
  if (RES)
   set(MONGOC_SOCKET_ARG2 ${MONGOC_ACCEPT_ARG2_VAL})
   set(MONGOC_SOCKET_ARG3 ${MONGOC_ACCEPT_ARG3_VAL})
   break()
   break()
  endif ()
endforeach()
endforeach()
 
message(STATUS "OK ${MONGOC_SOCKET_ARG2}  ${MONGOC_SOCKET_ARG3}")

Comment by A. Jesse Jiryu Davis [ 15/Mar/17 ]

Thanks! If you'd like to update our CMakeLists.txt to work well on HP-UX too, then I'd appreciate your contribution.

Comment by Aleksander Melnikov [ 15/Mar/17 ]

My mistake, sorry.
I'm was make cmake built.
But should to autoconf.

Comment by A. Jesse Jiryu Davis [ 15/Mar/17 ]

Hmm, on my system I get:

#define MONGOC_HAVE_SOCKLEN 1
 
/* ... comments omitted ... */
 
#define MONGOC_SOCKET_ARG2 struct sockaddr
#define MONGOC_SOCKET_ARG3 int

The third argument is set to "int" on my system, not to "socklen_t".

My system is HP-UX 11.31 rented from SiteOx.com:

% uname -a
HP-UX sovmh360 B.11.31 U ia64 2019596366 unlimited-user license

This is a big-endian machine:

% cat src/libbson/src/bson/bson-config.h
/*
 * Define to 1234 for Little Endian, 4321 for Big Endian.
 */
#define BSON_BYTE_ORDER 4321

Maybe I don't really understand this issue. But it seems to me that with my new configure check, if your system can compile a call to "accept()" with types "struct sockaddr" and "socklen_t *", then those are the right parameter types for your system. Is that true, or can you explain to me why I'm wrong?

Comment by Aleksander Melnikov [ 10/Mar/17 ]

looks better, but produce same output:

/*
 * MONGOC_HAVE_SOCKLEN is set from configure to determine if we
 * need to emulate the type.
 */
#define MONGOC_HAVE_SOCKLEN 1
 
#if MONGOC_HAVE_SOCKLEN != 1
#  undef MONGOC_HAVE_SOCKLEN
#endif
 
 
/*
 * Set from configure, see
 * https://curl.haxx.se/mail/lib-2009-04/0287.html
 */
#define MONGOC_SOCKET_ARG2 struct sockaddr
#define MONGOC_SOCKET_ARG3 socklen_t

How about add the following check:

#ifdef __hpux__
#if defind (_XOPEN_SOURCE_EXTENDED) && defined(HAVE_SOCKLEN_T)
#define MONGOC_USE_SOCKLEN_T 1
#else
#define MONGOC_USE_SOCKLEN_T 0
#endif
#else
#if defined(HAVE_SOCKLEN_T)
#define MONGOC_USE_SOCKLEN_T 1
#else
#define MONGOC_USE_SOCKLEN_T 0
#endif
#endif
 
#ifdef MONGOC_USE_SOCKLEN_T
typedef socklen_t mongoc_socklen_t;
#else
typedef int mongoc_socklen_t;
#endif

Comment by A. Jesse Jiryu Davis [ 09/Mar/17 ]

Thanks Aleksander, how does this look to you?:

https://github.com/ajdavis/mongo-c-driver/commit/2266c96a4a4c66e61ee272f5c5d64f755c52e826

Comment by Aleksander Melnikov [ 09/Mar/17 ]

As the HPUX have socklen_t type, it is set to aviable in mongoc-config.h:

/*
 * MONGOC_HAVE_SOCKLEN is set from configure to determine if we
 * need to emulate the type.
 */
#define MONGOC_HAVE_SOCKLEN 1
 
#if MONGOC_HAVE_SOCKLEN != 1
#  undef MONGOC_HAVE_SOCKLEN
#endif

the next define set mongoc_socklen_t to socklen_t

 
#ifdef MONGOC_HAVE_SOCKLEN
typedef socklen_t mongoc_socklen_t;
#else
typedef int mongoc_socklen_t;
#endif

Not all call replaced by new defines:

src/mongoc/mongoc-socket.c: In function 'mongoc_socket_accept_ex':
src/mongoc/mongoc-socket.c:430:35: warning: passing argument 3 of 'accept' from incompatible pointer type [enabled by default]
    sd = accept (sock->sd, (struct sockaddr *) &addr, &addrlen);
                                   ^
In file included from /usr/include/netdb.h:69:0,
                 from src/mongoc/mongoc-socket.h:33,
                 from src/mongoc/mongoc-socket-private.h:24,
                 from src/mongoc/mongoc-socket.c:23:
/usr/include/sys/socket.h:711:15: note: expected 'int *' but argument is of type 'mongoc_socklen_t *'
    extern int accept __((int, void *, int *));
               ^
src/mongoc/mongoc-socket.c: In function 'mongoc_socket_getsockname':
src/mongoc/mongoc-socket.c:1189:4: warning: passing argument 3 of 'getsockname' from incompatible pointer type [enabled by default]
    ret = getsockname (sock->sd, addr, addrlen);
    ^
In file included from /usr/include/netdb.h:69:0,
                 from src/mongoc/mongoc-socket.h:33,
                 from src/mongoc/mongoc-socket-private.h:24,
                 from src/mongoc/mongoc-socket.c:23:
/usr/include/sys/socket.h:715:15: note: expected 'int *' but argument is of type 'mongoc_socklen_t *'
    extern int getsockname __((int, void *, int *));
               ^

by this way, of implementation the type mongoc_socklen_t probably unnecessary.
why simple not use mongoc_socklen_t to switch type?

Comment by A. Jesse Jiryu Davis [ 08/Mar/17 ]

Thanks! I've tested it once on a HPUX machine I rented from SiteOx. If you can confirm it works on your system, I would appreciate it.

Comment by Aleksander Melnikov [ 08/Mar/17 ]

I will try to test

Comment by A. Jesse Jiryu Davis [ 08/Mar/17 ]

r1.6: https://github.com/mongodb/mongo-c-driver/commit/6e24289417568c013f2c83f1ed4b1da94711d524

Comment by Githook User [ 08/Mar/17 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-2015 getpeername and getsockopt params vary

Call getpeername and getsockopt with the right parameters on each
platform where we use the Autotools build system. Set reasonable
defaults in CMake builds.
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/d9478760c9df97bd4310c157040fabef453fb3d5

Comment by A. Jesse Jiryu Davis [ 02/Feb/17 ]

Thanks for the info!

Comment by Aleksander Melnikov [ 02/Feb/17 ]

more info here https://github.com/mongodb/mongo-c-driver/pull/409#issuecomment-276873933

Generated at Wed Feb 07 21:13:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.