listening addresses - Mailing list pgsql-patches
From | Andrew Dunstan |
---|---|
Subject | listening addresses |
Date | |
Msg-id | 405DC9AF.7040300@dunslane.net Whole thread Raw |
Responses |
Re: listening addresses
|
List | pgsql-patches |
I think this (undocumented!) patch implements what Tom and I thrashed out under this heading on -hackers. It would make the default configuration listen on localhost, and allow '*' as a listen address to be every available listen interface. -i would correspond to this latter setting. It also will not now error out unless there is absolutely no socket, Unix or TCP, to listen on. To turn off all TCP sockets you would use -h '' or listen_addresses = ''. Submitted for review. cheers andrew Index: src/backend/postmaster/postmaster.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/postmaster/postmaster.c,v retrieving revision 1.375 diff -c -r1.375 postmaster.c *** src/backend/postmaster/postmaster.c 15 Mar 2004 16:18:42 -0000 1.375 --- src/backend/postmaster/postmaster.c 21 Mar 2004 16:48:05 -0000 *************** *** 149,155 **** /* The socket number we are listening for connections on */ int PostPortNumber; char *UnixSocketDir; ! char *VirtualHost; /* * MaxBackends is the limit on the number of backends we can start. --- 149,155 ---- /* The socket number we are listening for connections on */ int PostPortNumber; char *UnixSocketDir; ! char *ListenAddresses = "localhost"; /* * MaxBackends is the limit on the number of backends we can start. *************** *** 202,208 **** static int SendStop = false; /* still more option variables */ - bool NetServer = false; /* listen on TCP/IP */ bool EnableSSL = false; bool SilentMode = false; /* silent mode (-S) */ --- 202,207 ---- *************** *** 412,417 **** --- 411,417 ---- char original_extraoptions[MAXPGPATH]; char *potential_DataDir = NULL; int i; + bool NetServer = false; *original_extraoptions = '\0'; *************** *** 513,522 **** SetConfigOption("fsync", "false", PGC_POSTMASTER, PGC_S_ARGV); break; case 'h': ! SetConfigOption("virtual_host", optarg, PGC_POSTMASTER, PGC_S_ARGV); break; case 'i': ! SetConfigOption("tcpip_socket", "true", PGC_POSTMASTER, PGC_S_ARGV); break; case 'k': SetConfigOption("unix_socket_directory", optarg, PGC_POSTMASTER, PGC_S_ARGV); --- 513,522 ---- SetConfigOption("fsync", "false", PGC_POSTMASTER, PGC_S_ARGV); break; case 'h': ! SetConfigOption("listen_addresses", optarg, PGC_POSTMASTER, PGC_S_ARGV); break; case 'i': ! SetConfigOption("listen_addresses", "*", PGC_POSTMASTER, PGC_S_ARGV); break; case 'k': SetConfigOption("unix_socket_directory", optarg, PGC_POSTMASTER, PGC_S_ARGV); *************** *** 700,705 **** --- 700,717 ---- (errmsg("%s: could not locate postgres executable", progname))); + /* + * check if ListenAddresses is empty or all spaces + */ + for (i=strlen(ListenAddresses)-1; i >= 0; i--) + { + if (ListenAddresses[i] != ' ') + { + NetServer = true; + break; + } + } + /* * Initialize SSL library, if specified. */ *************** *** 755,767 **** if (NetServer) { ! if (VirtualHost && VirtualHost[0]) { char *curhost, *endptr; char c = 0; ! curhost = VirtualHost; for (;;) { while (*curhost == ' ') /* skip any extra spaces */ --- 767,779 ---- if (NetServer) { ! if (strcmp(ListenAddresses,"*") != 0) { char *curhost, *endptr; char c = 0; ! curhost = ListenAddresses; for (;;) { while (*curhost == ' ') /* skip any extra spaces */ *************** *** 779,785 **** UnixSocketDir, ListenSocket, MAXLISTEN); if (status != STATUS_OK) ! ereport(FATAL, (errmsg("could not create listen socket for \"%s\"", curhost))); if (endptr) --- 791,797 ---- UnixSocketDir, ListenSocket, MAXLISTEN); if (status != STATUS_OK) ! ereport(WARNING, (errmsg("could not create listen socket for \"%s\"", curhost))); if (endptr) *************** *** 798,804 **** UnixSocketDir, ListenSocket, MAXLISTEN); if (status != STATUS_OK) ! ereport(FATAL, (errmsg("could not create TCP/IP listen socket"))); } --- 810,816 ---- UnixSocketDir, ListenSocket, MAXLISTEN); if (status != STATUS_OK) ! ereport(WARNING, (errmsg("could not create TCP/IP listen socket"))); } *************** *** 822,830 **** UnixSocketDir, ListenSocket, MAXLISTEN); if (status != STATUS_OK) ! ereport(FATAL, (errmsg("could not create Unix-domain socket"))); #endif XLOGPathInit(); --- 834,850 ---- UnixSocketDir, ListenSocket, MAXLISTEN); if (status != STATUS_OK) ! ereport(WARNING, (errmsg("could not create Unix-domain socket"))); #endif + + /* + * check that we have some socket to talk on + */ + + if (ListenSocket[0] == -1) + ereport(FATAL, + (errmsg("not listening on any socket"))); XLOGPathInit(); Index: src/backend/utils/misc/guc.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/misc/guc.c,v retrieving revision 1.190 diff -c -r1.190 guc.c *** src/backend/utils/misc/guc.c 15 Mar 2004 15:56:24 -0000 1.190 --- src/backend/utils/misc/guc.c 21 Mar 2004 16:48:06 -0000 *************** *** 444,457 **** false, NULL, NULL }, { - {"tcpip_socket", PGC_POSTMASTER, CONN_AUTH_SETTINGS, - gettext_noop("Makes the server accept TCP/IP connections."), - NULL - }, - &NetServer, - false, NULL, NULL - }, - { {"ssl", PGC_POSTMASTER, CONN_AUTH_SECURITY, gettext_noop("Enables SSL connections."), NULL --- 444,449 ---- *************** *** 1711,1722 **** }, { ! {"virtual_host", PGC_POSTMASTER, CONN_AUTH_SETTINGS, ! gettext_noop("Sets the host name or IP address to listen to."), NULL }, ! &VirtualHost, ! "", NULL, NULL }, { --- 1703,1714 ---- }, { ! {"listen_addresses", PGC_POSTMASTER, CONN_AUTH_SETTINGS, ! gettext_noop("Sets the host name or IP addresses to listen to."), NULL }, ! &ListenAddresses, ! "localhost", NULL, NULL }, { Index: src/backend/utils/misc/postgresql.conf.sample =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/misc/postgresql.conf.sample,v retrieving revision 1.108 diff -c -r1.108 postgresql.conf.sample *** src/backend/utils/misc/postgresql.conf.sample 15 Mar 2004 15:56:26 -0000 1.108 --- src/backend/utils/misc/postgresql.conf.sample 21 Mar 2004 16:48:06 -0000 *************** *** 27,33 **** # - Connection Settings - - #tcpip_socket = false #max_connections = 100 # note: increasing max_connections costs about 500 bytes of shared # memory per connection slot, in addition to costs from shared_buffers --- 27,32 ---- *************** *** 37,43 **** #unix_socket_directory = '' #unix_socket_group = '' #unix_socket_permissions = 0777 # octal ! #virtual_host = '' # what interface to listen on; defaults to any #rendezvous_name = '' # defaults to the computer name # - Security & Authentication - --- 36,43 ---- #unix_socket_directory = '' #unix_socket_group = '' #unix_socket_permissions = 0777 # octal ! #listen_addresses = 'localhost' # what interface to listen on; ! # defaults to localhost, '*' = any #rendezvous_name = '' # defaults to the computer name # - Security & Authentication - Index: src/include/miscadmin.h =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/include/miscadmin.h,v retrieving revision 1.153 diff -c -r1.153 miscadmin.h *** src/include/miscadmin.h 10 Feb 2004 03:42:45 -0000 1.153 --- src/include/miscadmin.h 21 Mar 2004 16:48:06 -0000 *************** *** 212,218 **** * A few postmaster startup options are exported here so the * configuration file processor can access them. */ - extern bool NetServer; extern bool EnableSSL; extern bool SilentMode; extern int MaxBackends; --- 212,217 ---- *************** *** 222,228 **** extern int Unix_socket_permissions; extern char *Unix_socket_group; extern char *UnixSocketDir; ! extern char *VirtualHost; /***************************************************************************** --- 221,227 ---- extern int Unix_socket_permissions; extern char *Unix_socket_group; extern char *UnixSocketDir; ! extern char *ListenAddresses; /*****************************************************************************
pgsql-patches by date: