Patch: update Bonjour support to the newer non-deprecated API - Mailing list pgsql-hackers
From | Tom Lane |
---|---|
Subject | Patch: update Bonjour support to the newer non-deprecated API |
Date | |
Msg-id | 17824.1252293423@sss.pgh.pa.us Whole thread Raw |
Responses |
Re: Patch: update Bonjour support to the newer non-deprecated API
Re: Patch: update Bonjour support to the newer non-deprecated API Re: Patch: update Bonjour support to the newer non-deprecated API |
List | pgsql-hackers |
I've grown a bit tired of reading the "'DNSServiceRegistrationCreate' is deprecated" warnings in OS X builds, and I'm also wondering whether any of the recently reported problems with Snow Leopard might trace to our use of an API that Apple has been deprecating since 2003. Hence, attached is a patch that replaces our use of the DNSServiceDiscovery.h API with the more modern dns_sd.h API. As-is, this would break Bonjour functionality in OS X 10.2 and before, but I really doubt that anyone still cares about that --- any objections out there? Like the original coding, this will bind the Bonjour service name on all available interfaces. I suspect that we ought to do something different if we have been told to bind to a subset of interfaces, but it's not entirely clear to me how to get the appropriate "interface indexes" given the information we have (particularly, the listening socket FDs). In any case, fixing that seems like added functionality. In principle this might enable use of Bonjour on non-Apple OSes, but I'm not personally interested enough to test that ... Comments, objections? regards, tom lane Index: configure.in =================================================================== RCS file: /cvsroot/pgsql/configure.in,v retrieving revision 1.609 diff -c -r1.609 configure.in *** configure.in 26 Aug 2009 22:24:42 -0000 1.609 --- configure.in 7 Sep 2009 03:00:24 -0000 *************** *** 1066,1072 **** 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])]) fi # for contrib/uuid-ossp --- 1066,1072 ---- fi if test "$with_bonjour" = yes ; then ! AC_CHECK_HEADER(dns_sd.h, [], [AC_MSG_ERROR([header file <dns_sd.h> is required for Bonjour])]) fi # for contrib/uuid-ossp Index: src/backend/postmaster/postmaster.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v retrieving revision 1.594 diff -c -r1.594 postmaster.c *** src/backend/postmaster/postmaster.c 31 Aug 2009 19:41:00 -0000 1.594 --- src/backend/postmaster/postmaster.c 7 Sep 2009 03:00:24 -0000 *************** *** 89,95 **** #endif #ifdef USE_BONJOUR ! #include <DNSServiceDiscovery/DNSServiceDiscovery.h> #endif #include "access/transam.h" --- 89,95 ---- #endif #ifdef USE_BONJOUR ! #include <dns_sd.h> #endif #include "access/transam.h" *************** *** 309,324 **** extern int optreset; /* might not be declared by system headers */ #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); --- 309,323 ---- 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); static void pmdaemonize(void); static Port *ConnCreate(int serverFd); static void ConnFree(Port *port); *************** *** 855,869 **** #ifdef USE_BONJOUR /* Register for Bonjour only if we opened TCP socket(s) */ ! if (ListenSocket[0] != -1 && bonjour_name != NULL) { ! DNSServiceRegistrationCreate(bonjour_name, ! "_postgresql._tcp.", ! "", ! htons(PostPortNumber), ! "", ! (DNSServiceRegistrationReply) reg_reply, ! NULL); } #endif --- 854,891 ---- #ifdef USE_BONJOUR /* Register for Bonjour only if we opened TCP socket(s) */ ! if (ListenSocket[0] != -1) { ! DNSServiceErrorType err; ! ! /* ! * We pass 0 for interface_index, which will result in registering ! * for all available 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 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,1209 **** } - #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) * --- 1214,1219 ---- *************** *** 2004,2009 **** --- 2014,2025 ---- 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 }
pgsql-hackers by date: