From 78850061868f8855a097393e199b43fe22846068 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 8 Sep 2009 17:08:36 +0000 Subject: [PATCH] Add a boolean GUC parameter "bonjour" to control whether a Bonjour-enabled build actually attempts to advertise itself via Bonjour. Formerly it always did so, which meant that packagers had to decide for their users whether this behavior was wanted or not. The default is "off" to be on the safe side, though this represents a change in the default behavior of a Bonjour-enabled build. Per discussion. --- doc/src/sgml/config.sgml | 16 +++++++++++- src/backend/postmaster/postmaster.c | 3 ++- src/backend/utils/misc/guc.c | 26 ++++++++++++++++++- src/backend/utils/misc/postgresql.conf.sample | 2 ++ src/include/postmaster/postmaster.h | 1 + 5 files changed, 45 insertions(+), 3 deletions(-) diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index 7c828355f6..a775c52e54 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -472,6 +472,20 @@ SET ENABLE_SEQSCAN TO OFF; + + bonjour (boolean) + + bonjour configuration parameter + + + + Enables advertising the server's existence via + Bonjour. The default is off. + This parameter can only be set at server start. + + + + bonjour_name (string) @@ -479,7 +493,7 @@ SET ENABLE_SEQSCAN TO OFF; - Specifies the Bonjour broadcast + Specifies the Bonjour service name. The computer name is used if this parameter is set to the empty string '' (which is the default). This parameter is ignored if the server was not compiled with diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 0bb523391b..e94181a8c1 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -200,6 +200,7 @@ bool log_hostname; /* for ps display and logging */ bool Log_connections = false; bool Db_user_namespace = false; +bool enable_bonjour = false; char *bonjour_name; /* PIDs of special child processes; 0 when not running */ @@ -854,7 +855,7 @@ PostmasterMain(int argc, char *argv[]) #ifdef USE_BONJOUR /* Register for Bonjour only if we opened TCP socket(s) */ - if (ListenSocket[0] != -1) + if (enable_bonjour && ListenSocket[0] != -1) { DNSServiceErrorType err; diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 6d363b0da6..63bb329492 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -152,6 +152,7 @@ static bool assign_phony_autocommit(bool newval, bool doit, GucSource source); static const char *assign_custom_variable_classes(const char *newval, bool doit, GucSource source); static bool assign_debug_assertions(bool newval, bool doit, GucSource source); +static bool assign_bonjour(bool newval, bool doit, GucSource source); static bool assign_ssl(bool newval, bool doit, GucSource source); static bool assign_stage_log_stats(bool newval, bool doit, GucSource source); static bool assign_log_stats(bool newval, bool doit, GucSource source); @@ -681,6 +682,14 @@ static struct config_bool ConfigureNamesBool[] = &session_auth_is_superuser, false, NULL, NULL }, + { + {"bonjour", PGC_POSTMASTER, CONN_AUTH_SETTINGS, + gettext_noop("Enables advertising the server via Bonjour."), + NULL + }, + &enable_bonjour, + false, assign_bonjour, NULL + }, { {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY, gettext_noop("Enables SSL connections."), @@ -2199,7 +2208,7 @@ static struct config_string ConfigureNamesString[] = { {"bonjour_name", PGC_POSTMASTER, CONN_AUTH_SETTINGS, - gettext_noop("Sets the Bonjour broadcast service name."), + gettext_noop("Sets the Bonjour service name."), NULL }, &bonjour_name, @@ -7394,6 +7403,21 @@ assign_debug_assertions(bool newval, bool doit, GucSource source) return true; } +static bool +assign_bonjour(bool newval, bool doit, GucSource source) +{ +#ifndef USE_BONJOUR + if (newval) + { + ereport(GUC_complaint_elevel(source), + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("Bonjour is not supported by this build"))); + return false; + } +#endif + return true; +} + static bool assign_ssl(bool newval, bool doit, GucSource source) { diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample index c6c02fcd81..4a361391f2 100644 --- a/src/backend/utils/misc/postgresql.conf.sample +++ b/src/backend/utils/misc/postgresql.conf.sample @@ -69,6 +69,8 @@ #unix_socket_group = '' # (change requires restart) #unix_socket_permissions = 0777 # begin with 0 to use octal notation # (change requires restart) +#bonjour = off # advertise server via Bonjour + # (change requires restart) #bonjour_name = '' # defaults to the computer name # (change requires restart) diff --git a/src/include/postmaster/postmaster.h b/src/include/postmaster/postmaster.h index bb110c2bbd..1a8cdc4033 100644 --- a/src/include/postmaster/postmaster.h +++ b/src/include/postmaster/postmaster.h @@ -27,6 +27,7 @@ extern int PreAuthDelay; extern int AuthenticationTimeout; extern bool Log_connections; extern bool log_hostname; +extern bool enable_bonjour; extern char *bonjour_name; #ifdef WIN32 -- 2.39.5