diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2009-09-08 16:08:26 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2009-09-08 16:08:26 +0000 |
commit | 59b9f3d36d56fa2bc998c4169f650b0a501874ea (patch) | |
tree | 711d368eff299a53b540dba9d0eec549f8104071 /src | |
parent | 4d3456e85dabfbe4182f94178ecb8789d9592bf7 (diff) | |
download | postgresql-59b9f3d36d56fa2bc998c4169f650b0a501874ea.tar.gz postgresql-59b9f3d36d56fa2bc998c4169f650b0a501874ea.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/postmaster/postmaster.c | 70 |
1 files changed, 43 insertions, 27 deletions
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index c4d8d8ae8d7..424bb72236d 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -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 } |