11
11
*
12
12
*
13
13
* IDENTIFICATION
14
- * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.181 2000/11/09 11:25:59 vadim Exp $
14
+ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.182 2000/11/12 20:51:51 tgl Exp $
15
15
*
16
16
* NOTES
17
17
*
@@ -107,55 +107,45 @@ typedef struct bkend
107
107
Port * MyBackendPort = NULL ;
108
108
109
109
/* list of active backends. For garbage collection only now. */
110
-
111
110
static Dllist * BackendList ;
112
111
113
112
/* list of ports associated with still open, but incomplete connections */
114
113
static Dllist * PortList ;
115
114
115
+ /* The socket number we are listening for connections on */
116
116
int PostPortName ;
117
117
118
- /*
119
- * This is a boolean indicating that there is at least one backend that
120
- * is accessing the current shared memory and semaphores. Between the
121
- * time that we start up, or throw away shared memory segments and start
122
- * over, and the time we generate the next backend (because we received a
123
- * connection request), it is false. Other times, it is true.
124
- */
118
+ /*
119
+ * This is a sequence number that indicates how many times we've had to
120
+ * throw away the shared memory and start over because we doubted its
121
+ * integrity. It starts off at zero and is incremented every time we
122
+ * start over. We use this to ensure that we use a new IPC shared memory
123
+ * key for the new shared memory segment in case the old segment isn't
124
+ * entirely gone yet.
125
+ *
126
+ * The sequence actually cycles back to 0 after 9, so pathologically there
127
+ * could be an IPC failure if 10 sets of backends are all stuck and won't
128
+ * release IPC resources.
129
+ */
125
130
static short shmem_seq = 0 ;
126
131
127
- /*
128
- * This is a sequence number that indicates how many times we've had to
129
- * throw away the shared memory and start over because we doubted its
130
- * integrity. It starts off at zero and is incremented every time we
131
- * start over. We use this to ensure that we use a new IPC shared memory
132
- * key for the new shared memory segment in case the old segment isn't
133
- * entirely gone yet.
134
- *
135
- * The sequence actually cycles back to 0 after 9, so pathologically there
136
- * could be an IPC failure if 10 sets of backends are all stuck and won't
137
- * release IPC resources.
138
- */
139
-
132
+ /*
133
+ * This is the base IPC shared memory key. Other keys are generated by
134
+ * adding to this.
135
+ */
140
136
static IpcMemoryKey ipc_key ;
141
137
142
- /*
143
- * This is the base IPC shared memory key. Other keys are generated by
144
- * adding to this.
145
- */
146
-
138
+ /*
139
+ * MaxBackends is the actual limit on the number of backends we will
140
+ * start. The default is established by configure, but it can be
141
+ * readjusted from 1..MAXBACKENDS with the postmaster -N switch. Note
142
+ * that a larger MaxBackends value will increase the size of the shared
143
+ * memory area as well as cause the postmaster to grab more kernel
144
+ * semaphores, even if you never actually use that many backends.
145
+ */
147
146
int MaxBackends = DEF_MAXBACKENDS ;
148
147
149
- /*
150
- * MaxBackends is the actual limit on the number of backends we will
151
- * start. The default is established by configure, but it can be
152
- * readjusted from 1..MAXBACKENDS with the postmaster -N switch. Note
153
- * that a larger MaxBackends value will increase the size of the shared
154
- * memory area as well as cause the postmaster to grab more kernel
155
- * semaphores, even if you never actually use that many backends.
156
- */
157
148
158
- static int NextBackendTag = INT_MAX ; /* XXX why count down not up? */
159
149
static char * progname = (char * ) NULL ;
160
150
static char * * real_argv ;
161
151
static int real_argc ;
@@ -587,6 +577,22 @@ PostmasterMain(int argc, char *argv[])
587
577
exit (1 );
588
578
}
589
579
580
+ if (DebugLvl > 2 )
581
+ {
582
+ extern char * * environ ;
583
+ char * * p ;
584
+
585
+ fprintf (stderr , "%s: PostmasterMain: initial environ dump:\n" ,
586
+ progname );
587
+ fprintf (stderr , "-----------------------------------------\n" );
588
+ for (p = environ ; * p ; ++ p )
589
+ fprintf (stderr , "\t%s\n" , * p );
590
+ fprintf (stderr , "-----------------------------------------\n" );
591
+ }
592
+
593
+ /*
594
+ * Establish input sockets.
595
+ */
590
596
#ifdef USE_SSL
591
597
if (EnableSSL && !NetServer )
592
598
{
@@ -600,7 +606,8 @@ PostmasterMain(int argc, char *argv[])
600
606
601
607
if (NetServer )
602
608
{
603
- status = StreamServerPort (AF_INET , (unsigned short )PostPortName , & ServerSock_INET );
609
+ status = StreamServerPort (AF_INET , (unsigned short ) PostPortName ,
610
+ & ServerSock_INET );
604
611
if (status != STATUS_OK )
605
612
{
606
613
fprintf (stderr , "%s: cannot create INET stream port\n" ,
@@ -610,18 +617,20 @@ PostmasterMain(int argc, char *argv[])
610
617
}
611
618
612
619
#ifdef HAVE_UNIX_SOCKETS
613
- status = StreamServerPort (AF_UNIX , (unsigned short )PostPortName , & ServerSock_UNIX );
620
+ status = StreamServerPort (AF_UNIX , (unsigned short ) PostPortName ,
621
+ & ServerSock_UNIX );
614
622
if (status != STATUS_OK )
615
623
{
616
624
fprintf (stderr , "%s: cannot create UNIX stream port\n" ,
617
625
progname );
618
626
ExitPostmaster (1 );
619
627
}
620
628
#endif
629
+
621
630
/* set up shared memory and semaphores */
622
631
reset_shared (PostPortName );
623
632
624
- /* Init XLOG pathes */
633
+ /* Init XLOG paths */
625
634
snprintf (XLogDir , MAXPGPATH , "%s/pg_xlog" , DataDir );
626
635
snprintf (ControlFilePath , MAXPGPATH , "%s/global/pg_control" , DataDir );
627
636
@@ -1706,43 +1715,7 @@ static int
1706
1715
BackendStartup (Port * port )
1707
1716
{
1708
1717
Backend * bn ; /* for backend cleanup */
1709
- int pid ,
1710
- i ;
1711
-
1712
- #ifdef CYR_RECODE
1713
- #define NR_ENVIRONMENT_VBL 5
1714
- char ChTable [80 ];
1715
-
1716
- #else
1717
- #define NR_ENVIRONMENT_VBL 4
1718
- #endif
1719
-
1720
- static char envEntry [NR_ENVIRONMENT_VBL ][2 * ARGV_SIZE ];
1721
-
1722
- for (i = 0 ; i < NR_ENVIRONMENT_VBL ; ++ i )
1723
- MemSet (envEntry [i ], 0 , 2 * ARGV_SIZE );
1724
-
1725
- /*
1726
- * Set up the necessary environment variables for the backend This
1727
- * should really be some sort of message....
1728
- */
1729
- sprintf (envEntry [0 ], "POSTPORT=%d" , PostPortName );
1730
- putenv (envEntry [0 ]);
1731
- sprintf (envEntry [1 ], "POSTID=%d" , NextBackendTag );
1732
- putenv (envEntry [1 ]);
1733
- sprintf (envEntry [2 ], "PGDATA=%s" , DataDir );
1734
- putenv (envEntry [2 ]);
1735
- sprintf (envEntry [3 ], "IPC_KEY=%d" , ipc_key );
1736
- putenv (envEntry [3 ]);
1737
-
1738
- #ifdef CYR_RECODE
1739
- GetCharSetByHost (ChTable , port -> raddr .in .sin_addr .s_addr , DataDir );
1740
- if (* ChTable != '\0' )
1741
- {
1742
- sprintf (envEntry [4 ], "PG_RECODETABLE=%s" , ChTable );
1743
- putenv (envEntry [4 ]);
1744
- }
1745
- #endif
1718
+ int pid ;
1746
1719
1747
1720
/*
1748
1721
* Compute the cancel key that will be assigned to this backend. The
@@ -1751,19 +1724,6 @@ BackendStartup(Port *port)
1751
1724
*/
1752
1725
MyCancelKey = PostmasterRandom ();
1753
1726
1754
- if (DebugLvl > 2 )
1755
- {
1756
- char * * p ;
1757
- extern char * * environ ;
1758
-
1759
- fprintf (stderr , "%s: BackendStartup: environ dump:\n" ,
1760
- progname );
1761
- fprintf (stderr , "-----------------------------------------\n" );
1762
- for (p = environ ; * p ; ++ p )
1763
- fprintf (stderr , "\t%s\n" , * p );
1764
- fprintf (stderr , "-----------------------------------------\n" );
1765
- }
1766
-
1767
1727
/*
1768
1728
* Flush stdio channels just before fork, to avoid double-output
1769
1729
* problems. Ideally we'd use fflush(NULL) here, but there are still a
@@ -1779,12 +1739,30 @@ BackendStartup(Port *port)
1779
1739
/* Specific beos actions before backend startup */
1780
1740
beos_before_backend_startup ();
1781
1741
#endif
1742
+
1782
1743
if ((pid = fork ()) == 0 )
1783
1744
{ /* child */
1784
1745
#ifdef __BEOS__
1785
- /* Specific beos backend stratup actions */
1746
+ /* Specific beos backend startup actions */
1786
1747
beos_backend_startup ();
1787
1748
#endif
1749
+
1750
+ #ifdef CYR_RECODE
1751
+ {
1752
+ /* Save charset for this host while we still have client addr */
1753
+ char ChTable [80 ];
1754
+ static char cyrEnvironment [100 ];
1755
+
1756
+ GetCharSetByHost (ChTable , port -> raddr .in .sin_addr .s_addr , DataDir );
1757
+ if (* ChTable != '\0' )
1758
+ {
1759
+ snprintf (cyrEnvironment , sizeof (cyrEnvironment ),
1760
+ "PG_RECODETABLE=%s" , ChTable );
1761
+ putenv (cyrEnvironment );
1762
+ }
1763
+ }
1764
+ #endif
1765
+
1788
1766
if (DoBackend (port ))
1789
1767
{
1790
1768
fprintf (stderr , "%s child[%d]: BackendStartup: backend startup failed\n" ,
@@ -1799,7 +1777,7 @@ BackendStartup(Port *port)
1799
1777
if (pid < 0 )
1800
1778
{
1801
1779
#ifdef __BEOS__
1802
- /* Specific beos backend stratup actions */
1780
+ /* Specific beos backend startup actions */
1803
1781
beos_backend_startup_failed ();
1804
1782
#endif
1805
1783
fprintf (stderr , "%s: BackendStartup: fork failed: %s\n" ,
@@ -1812,14 +1790,6 @@ BackendStartup(Port *port)
1812
1790
progname , pid , port -> user , port -> database ,
1813
1791
port -> sock );
1814
1792
1815
- /* Generate a new backend tag for every backend we start */
1816
-
1817
- /*
1818
- * XXX theoretically this could wrap around, if you have the patience
1819
- * to start 2^31 backends ...
1820
- */
1821
- NextBackendTag -= 1 ;
1822
-
1823
1793
/*
1824
1794
* Everything's been successful, it's safe to add this backend to our
1825
1795
* list of backends.
@@ -2179,21 +2149,7 @@ static pid_t
2179
2149
SSDataBase (int xlop )
2180
2150
{
2181
2151
pid_t pid ;
2182
- int i ;
2183
2152
Backend * bn ;
2184
- static char ssEntry [4 ][2 * ARGV_SIZE ];
2185
-
2186
- for (i = 0 ; i < 4 ; ++ i )
2187
- MemSet (ssEntry [i ], 0 , 2 * ARGV_SIZE );
2188
-
2189
- sprintf (ssEntry [0 ], "POSTPORT=%d" , PostPortName );
2190
- putenv (ssEntry [0 ]);
2191
- sprintf (ssEntry [1 ], "POSTID=%d" , NextBackendTag );
2192
- putenv (ssEntry [1 ]);
2193
- sprintf (ssEntry [2 ], "PGDATA=%s" , DataDir );
2194
- putenv (ssEntry [2 ]);
2195
- sprintf (ssEntry [3 ], "IPC_KEY=%d" , ipc_key );
2196
- putenv (ssEntry [3 ]);
2197
2153
2198
2154
fflush (stdout );
2199
2155
fflush (stderr );
@@ -2258,8 +2214,6 @@ SSDataBase(int xlop)
2258
2214
ExitPostmaster (1 );
2259
2215
}
2260
2216
2261
- NextBackendTag -= 1 ;
2262
-
2263
2217
if (xlop != BS_XLOG_CHECKPOINT )
2264
2218
return (pid );
2265
2219
0 commit comments