Replace use of the long-deprecated Bonjour API DNSServiceRegistrationCreate

with the not-so-deprecated DNSServiceRegister.  This patch shouldn't change
any user-visible behavior, it just gets rid of a deprecation warning in
--with-bonjour builds.  The new code will fail on OS X releases before 10.3,
but it seems unlikely that anyone will want to run Postgres 8.5 on 10.2.
This commit is contained in:
Tom Lane 2009-09-08 16:08:26 +00:00
parent 4d3456e85d
commit 59b9f3d36d
3 changed files with 82 additions and 66 deletions

74
configure vendored
View File

@ -13439,18 +13439,18 @@ done
fi
if test "$with_bonjour" = yes ; then
if test "${ac_cv_header_DNSServiceDiscovery_DNSServiceDiscovery_h+set}" = set; then
{ $as_echo "$as_me:$LINENO: checking for DNSServiceDiscovery/DNSServiceDiscovery.h" >&5
$as_echo_n "checking for DNSServiceDiscovery/DNSServiceDiscovery.h... " >&6; }
if test "${ac_cv_header_DNSServiceDiscovery_DNSServiceDiscovery_h+set}" = set; then
if test "${ac_cv_header_dns_sd_h+set}" = set; then
{ $as_echo "$as_me:$LINENO: checking for dns_sd.h" >&5
$as_echo_n "checking for dns_sd.h... " >&6; }
if test "${ac_cv_header_dns_sd_h+set}" = set; then
$as_echo_n "(cached) " >&6
fi
{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_DNSServiceDiscovery_DNSServiceDiscovery_h" >&5
$as_echo "$ac_cv_header_DNSServiceDiscovery_DNSServiceDiscovery_h" >&6; }
{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_dns_sd_h" >&5
$as_echo "$ac_cv_header_dns_sd_h" >&6; }
else
# Is the header compilable?
{ $as_echo "$as_me:$LINENO: checking DNSServiceDiscovery/DNSServiceDiscovery.h usability" >&5
$as_echo_n "checking DNSServiceDiscovery/DNSServiceDiscovery.h usability... " >&6; }
{ $as_echo "$as_me:$LINENO: checking dns_sd.h usability" >&5
$as_echo_n "checking dns_sd.h usability... " >&6; }
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
@ -13458,7 +13458,7 @@ cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
$ac_includes_default
#include <DNSServiceDiscovery/DNSServiceDiscovery.h>
#include <dns_sd.h>
_ACEOF
rm -f conftest.$ac_objext
if { (ac_try="$ac_compile"
@ -13491,15 +13491,15 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
$as_echo "$ac_header_compiler" >&6; }
# Is the header present?
{ $as_echo "$as_me:$LINENO: checking DNSServiceDiscovery/DNSServiceDiscovery.h presence" >&5
$as_echo_n "checking DNSServiceDiscovery/DNSServiceDiscovery.h presence... " >&6; }
{ $as_echo "$as_me:$LINENO: checking dns_sd.h presence" >&5
$as_echo_n "checking dns_sd.h presence... " >&6; }
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
#include <DNSServiceDiscovery/DNSServiceDiscovery.h>
#include <dns_sd.h>
_ACEOF
if { (ac_try="$ac_cpp conftest.$ac_ext"
case "(($ac_try" in
@ -13533,25 +13533,25 @@ $as_echo "$ac_header_preproc" >&6; }
# So? What about this header?
case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
yes:no: )
{ $as_echo "$as_me:$LINENO: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: accepted by the compiler, rejected by the preprocessor!" >&5
$as_echo "$as_me: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
{ $as_echo "$as_me:$LINENO: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: proceeding with the compiler's result" >&5
$as_echo "$as_me: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: proceeding with the compiler's result" >&2;}
{ $as_echo "$as_me:$LINENO: WARNING: dns_sd.h: accepted by the compiler, rejected by the preprocessor!" >&5
$as_echo "$as_me: WARNING: dns_sd.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
{ $as_echo "$as_me:$LINENO: WARNING: dns_sd.h: proceeding with the compiler's result" >&5
$as_echo "$as_me: WARNING: dns_sd.h: proceeding with the compiler's result" >&2;}
ac_header_preproc=yes
;;
no:yes:* )
{ $as_echo "$as_me:$LINENO: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: present but cannot be compiled" >&5
$as_echo "$as_me: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: present but cannot be compiled" >&2;}
{ $as_echo "$as_me:$LINENO: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: check for missing prerequisite headers?" >&5
$as_echo "$as_me: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: check for missing prerequisite headers?" >&2;}
{ $as_echo "$as_me:$LINENO: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: see the Autoconf documentation" >&5
$as_echo "$as_me: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: see the Autoconf documentation" >&2;}
{ $as_echo "$as_me:$LINENO: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: section \"Present But Cannot Be Compiled\"" >&5
$as_echo "$as_me: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: section \"Present But Cannot Be Compiled\"" >&2;}
{ $as_echo "$as_me:$LINENO: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: proceeding with the preprocessor's result" >&5
$as_echo "$as_me: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: proceeding with the preprocessor's result" >&2;}
{ $as_echo "$as_me:$LINENO: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: in the future, the compiler will take precedence" >&5
$as_echo "$as_me: WARNING: DNSServiceDiscovery/DNSServiceDiscovery.h: in the future, the compiler will take precedence" >&2;}
{ $as_echo "$as_me:$LINENO: WARNING: dns_sd.h: present but cannot be compiled" >&5
$as_echo "$as_me: WARNING: dns_sd.h: present but cannot be compiled" >&2;}
{ $as_echo "$as_me:$LINENO: WARNING: dns_sd.h: check for missing prerequisite headers?" >&5
$as_echo "$as_me: WARNING: dns_sd.h: check for missing prerequisite headers?" >&2;}
{ $as_echo "$as_me:$LINENO: WARNING: dns_sd.h: see the Autoconf documentation" >&5
$as_echo "$as_me: WARNING: dns_sd.h: see the Autoconf documentation" >&2;}
{ $as_echo "$as_me:$LINENO: WARNING: dns_sd.h: section \"Present But Cannot Be Compiled\"" >&5
$as_echo "$as_me: WARNING: dns_sd.h: section \"Present But Cannot Be Compiled\"" >&2;}
{ $as_echo "$as_me:$LINENO: WARNING: dns_sd.h: proceeding with the preprocessor's result" >&5
$as_echo "$as_me: WARNING: dns_sd.h: proceeding with the preprocessor's result" >&2;}
{ $as_echo "$as_me:$LINENO: WARNING: dns_sd.h: in the future, the compiler will take precedence" >&5
$as_echo "$as_me: WARNING: dns_sd.h: in the future, the compiler will take precedence" >&2;}
( cat <<\_ASBOX
## ---------------------------------------- ##
## Report this to pgsql-bugs@postgresql.org ##
@ -13560,22 +13560,22 @@ _ASBOX
) | sed "s/^/$as_me: WARNING: /" >&2
;;
esac
{ $as_echo "$as_me:$LINENO: checking for DNSServiceDiscovery/DNSServiceDiscovery.h" >&5
$as_echo_n "checking for DNSServiceDiscovery/DNSServiceDiscovery.h... " >&6; }
if test "${ac_cv_header_DNSServiceDiscovery_DNSServiceDiscovery_h+set}" = set; then
{ $as_echo "$as_me:$LINENO: checking for dns_sd.h" >&5
$as_echo_n "checking for dns_sd.h... " >&6; }
if test "${ac_cv_header_dns_sd_h+set}" = set; then
$as_echo_n "(cached) " >&6
else
ac_cv_header_DNSServiceDiscovery_DNSServiceDiscovery_h=$ac_header_preproc
ac_cv_header_dns_sd_h=$ac_header_preproc
fi
{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_DNSServiceDiscovery_DNSServiceDiscovery_h" >&5
$as_echo "$ac_cv_header_DNSServiceDiscovery_DNSServiceDiscovery_h" >&6; }
{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_dns_sd_h" >&5
$as_echo "$ac_cv_header_dns_sd_h" >&6; }
fi
if test "x$ac_cv_header_DNSServiceDiscovery_DNSServiceDiscovery_h" = x""yes; then
if test "x$ac_cv_header_dns_sd_h" = x""yes; then
:
else
{ { $as_echo "$as_me:$LINENO: error: header file <DNSServiceDiscovery/DNSServiceDiscovery.h> is required for Bonjour" >&5
$as_echo "$as_me: error: header file <DNSServiceDiscovery/DNSServiceDiscovery.h> is required for Bonjour" >&2;}
{ { $as_echo "$as_me:$LINENO: error: header file <dns_sd.h> is required for Bonjour" >&5
$as_echo "$as_me: error: header file <dns_sd.h> is required for Bonjour" >&2;}
{ (exit 1); exit 1; }; }
fi

View File

@ -1,5 +1,5 @@
dnl Process this file with autoconf to produce a configure script.
dnl $PostgreSQL: pgsql/configure.in,v 1.609 2009/08/26 22:24:42 petere Exp $
dnl $PostgreSQL: pgsql/configure.in,v 1.610 2009/09/08 16:08:26 tgl Exp $
dnl
dnl Developers, please strive to achieve this order:
dnl
@ -1066,7 +1066,7 @@ if test "$with_ldap" = yes ; then
fi
if test "$with_bonjour" = yes ; then
AC_CHECK_HEADER(DNSServiceDiscovery/DNSServiceDiscovery.h, [], [AC_MSG_ERROR([header file <DNSServiceDiscovery/DNSServiceDiscovery.h> is required for Bonjour])])
AC_CHECK_HEADER(dns_sd.h, [], [AC_MSG_ERROR([header file <dns_sd.h> is required for Bonjour])])
fi
# for contrib/uuid-ossp

View File

@ -37,7 +37,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.594 2009/08/31 19:41:00 tgl Exp $
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.595 2009/09/08 16:08:26 tgl Exp $
*
* NOTES
*
@ -89,7 +89,7 @@
#endif
#ifdef USE_BONJOUR
#include <DNSServiceDiscovery/DNSServiceDiscovery.h>
#include <dns_sd.h>
#endif
#include "access/transam.h"
@ -309,16 +309,15 @@ extern int optind,
extern int optreset; /* might not be declared by system headers */
#endif
#ifdef USE_BONJOUR
static DNSServiceRef bonjour_sdref = NULL;
#endif
/*
* postmaster.c - function prototypes
*/
static void getInstallationPaths(const char *argv0);
static void checkDataDir(void);
#ifdef USE_BONJOUR
static void reg_reply(DNSServiceRegistrationReplyErrorType errorCode,
void *context);
#endif
static void pmdaemonize(void);
static Port *ConnCreate(int serverFd);
static void ConnFree(Port *port);
@ -855,15 +854,38 @@ PostmasterMain(int argc, char *argv[])
#ifdef USE_BONJOUR
/* Register for Bonjour only if we opened TCP socket(s) */
if (ListenSocket[0] != -1 && bonjour_name != NULL)
if (ListenSocket[0] != -1)
{
DNSServiceRegistrationCreate(bonjour_name,
"_postgresql._tcp.",
"",
htons(PostPortNumber),
"",
(DNSServiceRegistrationReply) reg_reply,
NULL);
DNSServiceErrorType err;
/*
* We pass 0 for interface_index, which will result in registering on
* all "applicable" interfaces. It's not entirely clear from the
* DNS-SD docs whether this would be appropriate if we have bound to
* just a subset of the available network interfaces.
*/
err = DNSServiceRegister(&bonjour_sdref,
0,
0,
bonjour_name,
"_postgresql._tcp.",
NULL,
NULL,
htons(PostPortNumber),
0,
NULL,
NULL,
NULL);
if (err != kDNSServiceErr_NoError)
elog(LOG, "DNSServiceRegister() failed: error code %ld",
(long) err);
/*
* We don't bother to read the mDNS daemon's reply, and we expect
* that it will automatically terminate our registration when the
* socket is closed at postmaster termination. So there's nothing
* more to be done here. However, the bonjour_sdref is kept around
* so that forked children can close their copies of the socket.
*/
}
#endif
@ -1192,18 +1214,6 @@ checkDataDir(void)
}
#ifdef USE_BONJOUR
/*
* empty callback function for DNSServiceRegistrationCreate()
*/
static void
reg_reply(DNSServiceRegistrationReplyErrorType errorCode, void *context)
{
}
#endif /* USE_BONJOUR */
/*
* Fork away from the controlling terminal (silent_mode option)
*
@ -2004,6 +2014,12 @@ ClosePostmasterPorts(bool am_syslogger)
syslogPipe[0] = 0;
#endif
}
#ifdef USE_BONJOUR
/* If using Bonjour, close the connection to the mDNS daemon */
if (bonjour_sdref)
close(DNSServiceRefSockFD(bonjour_sdref));
#endif
}