[CDRIVER-4249] Undeclared DNS constants and symbols when building with POSIX 2008 Created: 20/Dec/21  Updated: 28/Oct/23  Resolved: 05/Jan/22

Status: Closed
Project: C Driver
Component/s: libmongoc
Affects Version/s: None
Fix Version/s: 1.21.0

Type: Bug Priority: Unknown
Reporter: Jeremy Mikola Assignee: Ezra Chung
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to PHPC-2270 Define constants for POSIX features a... Closed
is related to CDRIVER-4028 Wrong error message printed when DNS ... Closed
is related to CDRIVER-4227 Use a shared_mutex when locking in sh... Closed

 Description   

8d1af19 for CDRIVER-4227 introduced -D_XOPEN_SOURCE=700, which specifies POSIX 2008. When adding that to PHPC's CFLAGS, I now see errors that several DNS constants and symbols are no longer defined. The Conforming To section of h_errno(3) states:

POSIX.1-2008 removes the specifications of gethostbyname(), gethostbyaddr(), and _h_errno_, recommending the use of getaddrinfo(3) and getnameinfo(3) instead.

Seems relevant, but I'm not sure why libmongoc didn't require additional changes (mongodb/mongo-c-driver#910) when instituting that change. Build errors follow:
 

phpc/src/libmongoc/src/libmongoc/src/mongoc/mongoc-client.c: In function ‘_mongoc_hstrerror’:
phpc/src/libmongoc/src/libmongoc/src/mongoc/mongoc-client.c:306:9: error: ‘HOST_NOT_FOUND’ undeclared (first use in this function)
  306 |    case HOST_NOT_FOUND:
      |         ^~~~~~~~~~~~~~
phpc/src/libmongoc/src/libmongoc/src/mongoc/mongoc-client.c:306:9: note: each undeclared identifier is reported only once for each function it appears in
phpc/src/libmongoc/src/libmongoc/src/mongoc/mongoc-client.c:308:9: error: ‘NO_ADDRESS’ undeclared (first use in this function)
  308 |    case NO_ADDRESS:
      |         ^~~~~~~~~~
phpc/src/libmongoc/src/libmongoc/src/mongoc/mongoc-client.c:310:9: error: ‘NO_RECOVERY’ undeclared (first use in this function)
  310 |    case NO_RECOVERY:
      |         ^~~~~~~~~~~
phpc/src/libmongoc/src/libmongoc/src/mongoc/mongoc-client.c:312:9: error: ‘TRY_AGAIN’ undeclared (first use in this function); did you mean ‘EAI_AGAIN’?
  312 |    case TRY_AGAIN:
      |         ^~~~~~~~~
      |         EAI_AGAIN
phpc/src/libmongoc/src/libmongoc/src/mongoc/mongoc-client.c: In function ‘srv_callback’:
phpc/src/libmongoc/src/libmongoc/src/mongoc/mongoc-client.c:349:37: error: ‘h_errno’ undeclared (first use in this function); did you mean ‘errno’?
  349 |                  _mongoc_hstrerror (h_errno));
      |                                     ^~~~~~~
phpc/src/libmongoc/src/libmongoc/src/mongoc/mongoc-client.c:99:23: note: in definition of macro ‘DNS_ERROR’
   99 |                       __VA_ARGS__);                        \
      |                       ^~~~~~~~~~~
phpc/src/libmongoc/src/libmongoc/src/mongoc/mongoc-client.c: In function ‘_mongoc_get_rr_search’:
phpc/src/libmongoc/src/libmongoc/src/mongoc/mongoc-client.c:495:40: error: ‘h_errno’ undeclared (first use in this function); did you mean ‘errno’?
  495 |                     _mongoc_hstrerror (h_errno));
      |                                        ^~~~~~~
phpc/src/libmongoc/src/libmongoc/src/mongoc/mongoc-client.c:99:23: note: in definition of macro ‘DNS_ERROR’
   99 |                       __VA_ARGS__);                        \
      |                       ^~~~~~~~~~~



 Comments   
Comment by Githook User [ 05/Jan/22 ]

Author:

{'name': 'Jeremy Mikola', 'email': 'jmikola@gmail.com', 'username': 'jmikola'}

Message: PHPC-1647: Use mongoc_client_new_from_uri_with_error

This allows PHPC to defer entirely to libmongoc for cross-option URI validation

Bump libmongoc to 1.21-dev

Build changes are ported from upstream CMake changes (see: CDRIVER-4249)
Branch: master
https://github.com/mongodb/mongo-php-driver/commit/ab44b0cbeb52361db568e8a506a78d038544d3d5

Comment by Githook User [ 05/Jan/22 ]

Author:

{'name': 'Ezra Chung', 'email': '88335979+eramongodb@users.noreply.github.com', 'username': 'eramongodb'}

Message: CDRIVER-4249 Apply _DEFAULT_SOURCE to all subdirectories (#920)

Comment by Jeremy Mikola [ 20/Dec/21 ]

Just to follow-up, I did add #define _XOPEN_SOURCE 700 to PHPC's AC_LANG_PROGRAM prologues used to detect res_nsearch and res_search. That had no effect on the detection logic (testing locally on Ubuntu 20.04). That's not surprising, as the example programs for linker checks don't reference any of the constants/symbols from the OP.

Comment by Jeremy Mikola [ 20/Dec/21 ]

Some of the undeclared constants were introduced in CDRIVER-4028 and the code in which these errors appear is gated in the following conditional:

#elif (defined(MONGOC_HAVE_RES_NSEARCH) || defined(MONGOC_HAVE_RES_SEARCH))

The detection logic for MONGOC_HAVE_RES_NSEARCH and MONGOC_HAVE_RES_SEARCH dates back to build/cmake/FindResSearch.cmake, which has not been recently changed. I wonder if this is related to 1523c42 also adding -D_XOPEN_SOURCE=700 to CMAKE_REQUIRED_DEFINITIONS (not just the libmongoc build flags).

The equivalent m4 scripts in PHPC for detecting these DNS APIs are in scripts/autotools/libmongoc/CheckResolv.m4. I'm not sure if there's an equivalent API for defining -D_XOPEN_SOURCE=700 for those Autotools checks, but I'll look into that.

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