From: Jeff Trawick Date: Mon, 19 Nov 2001 13:48:57 +0000 (+0000) Subject: APR-ize the resolver logic in mod_unique_id. This fixes a bug X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c7f92d661df8f347aeb928d8912d94e377a2dd9d;p=apache APR-ize the resolver logic in mod_unique_id. This fixes a bug in logging the error from a failed DNS lookup. Note: For a funky error scenario to work right (huge host name), this requires a tweak to apr_gethostname() which I have not yet committed. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@92032 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 87259bc9a2..026557cceb 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,8 @@ Changes with Apache 2.0.29-dev + *) APR-ize the resolver logic in mod_unique_id. This fixes a bug + in logging the error from a failed DNS lookup. [Jeff Trawick] + *) Added the missing macros AP_INIT_TAKE13 and AP_INIT_TAKE123. [Cliff Woolley] diff --git a/STATUS b/STATUS index a9670ff402..a0860fe01d 100644 --- a/STATUS +++ b/STATUS @@ -1,5 +1,5 @@ APACHE 2.0 STATUS: -*-text-*- -Last modified at [$Date: 2001/11/17 14:02:25 $] +Last modified at [$Date: 2001/11/19 13:48:57 $] Release: @@ -292,8 +292,6 @@ RELEASE NON-SHOWSTOPPERS BUT WOULD BE REAL NICE TO WRAP THESE UP: * shift stuff to mod_core.h - * APR-ize resolver stuff in mod_unique_id (Jeff volunteers) - * callers of ap_run_create_request() should check the return value for failure (Doug volunteers) diff --git a/modules/metadata/mod_unique_id.c b/modules/metadata/mod_unique_id.c index bc33cb32cd..8fbbde8878 100644 --- a/modules/metadata/mod_unique_id.c +++ b/modules/metadata/mod_unique_id.c @@ -64,20 +64,15 @@ */ #include "apr_general.h" /* for APR_XtOffsetOf */ +#include "apr_network_io.h" #include "httpd.h" #include "http_config.h" #include "http_log.h" #include "http_protocol.h" /* for ap_hook_post_read_request */ -#if APR_HAVE_NETDB_H -#include -#endif -#if APR_HAVE_ARPA_INET_H -#include -#endif #if APR_HAVE_UNISTD_H -#include +#include /* for getpid() */ #endif typedef struct { @@ -177,12 +172,11 @@ static unsigned short unique_id_rec_offset[UNIQUE_ID_REC_MAX], static void unique_id_global_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *main_server) { -#ifndef MAXHOSTNAMELEN -#define MAXHOSTNAMELEN 256 -#endif - char str[MAXHOSTNAMELEN + 1]; - struct hostent *hent; + char str[APRMAXHOSTLEN + 1]; apr_short_interval_time_t pause; + apr_status_t rv; + char *ipaddrstr; + apr_sockaddr_t *sockaddr; /* * Calculate the sizes and offsets in cur_unique_id. @@ -211,24 +205,27 @@ static void unique_id_global_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *p * of the addresses from the main_server, since those aren't as likely to * be unique as the physical address of the machine */ - if (gethostname(str, sizeof(str) - 1) != 0) { - ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, errno, main_server, - "gethostname: mod_unique_id requires the hostname of the server"); + if ((rv = apr_gethostname(str, sizeof(str) - 1, p)) != APR_SUCCESS) { + ap_log_error(APLOG_MARK, APLOG_ALERT, rv, main_server, + "mod_unique_id: unable to find hostname of the server"); exit(1); } - str[sizeof(str) - 1] = '\0'; - if ((hent = gethostbyname(str)) == NULL) { - ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, h_errno, main_server, - "mod_unique_id: unable to gethostbyname(\"%s\")", str); + /* XXX theoretically there are boxes out there which want to use + * mod_unique_id but which have no IPv4 address... send in a patch :) + */ + if ((rv = apr_sockaddr_info_get(&sockaddr, str, AF_INET, 0, 0, p)) != APR_SUCCESS) { + ap_log_error(APLOG_MARK, APLOG_ALERT, rv, main_server, + "mod_unique_id: unable to find IPv4 address of \"%s\"", str); exit(1); } - global_in_addr = ((struct in_addr *) hent->h_addr_list[0])->s_addr; + global_in_addr = sockaddr->sa.sin.sin_addr.s_addr; + apr_sockaddr_ip_get(&ipaddrstr, sockaddr); ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0, main_server, "mod_unique_id: using ip addr %s", - inet_ntoa(*(struct in_addr *) hent->h_addr_list[0])); + ipaddrstr); /* * If the server is pummelled with restart requests we could possibly end