|
11 | 11 | *
|
12 | 12 | *
|
13 | 13 | * IDENTIFICATION
|
14 |
| - * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.204 2001/01/27 00:05:31 tgl Exp $ |
| 14 | + * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.205 2001/02/08 00:35:10 tgl Exp $ |
15 | 15 | *
|
16 | 16 | * NOTES
|
17 | 17 | *
|
@@ -202,6 +202,7 @@ extern void GetRedoRecPtr(void);
|
202 | 202 | static void pmdaemonize(int argc, char *argv[]);
|
203 | 203 | static Port *ConnCreate(int serverFd);
|
204 | 204 | static void ConnFree(Port *port);
|
| 205 | +static void ClosePostmasterPorts(Port *myConn); |
205 | 206 | static void reset_shared(unsigned short port);
|
206 | 207 | static void SIGHUP_handler(SIGNAL_ARGS);
|
207 | 208 | static void pmdie(SIGNAL_ARGS);
|
@@ -1285,6 +1286,51 @@ ConnFree(Port *conn)
|
1285 | 1286 | free(conn);
|
1286 | 1287 | }
|
1287 | 1288 |
|
| 1289 | +/* |
| 1290 | + * ClosePostmasterPorts -- close all the postmaster's open sockets |
| 1291 | + * |
| 1292 | + * This is called during child process startup to release file descriptors |
| 1293 | + * that are not needed by that child process. All descriptors other than |
| 1294 | + * the one for myConn (if it's not null) are closed. |
| 1295 | + * |
| 1296 | + * Note that closing the child's descriptor does not destroy the client |
| 1297 | + * connection prematurely, since the parent (postmaster) process still |
| 1298 | + * has the socket open. |
| 1299 | + */ |
| 1300 | +static void |
| 1301 | +ClosePostmasterPorts(Port *myConn) |
| 1302 | +{ |
| 1303 | + Dlelem *curr; |
| 1304 | + |
| 1305 | + /* Close the listen sockets */ |
| 1306 | + if (NetServer) |
| 1307 | + StreamClose(ServerSock_INET); |
| 1308 | + ServerSock_INET = INVALID_SOCK; |
| 1309 | +#ifdef HAVE_UNIX_SOCKETS |
| 1310 | + StreamClose(ServerSock_UNIX); |
| 1311 | + ServerSock_UNIX = INVALID_SOCK; |
| 1312 | +#endif |
| 1313 | + |
| 1314 | + /* Close any sockets for other clients, and release memory too */ |
| 1315 | + curr = DLGetHead(PortList); |
| 1316 | + |
| 1317 | + while (curr) |
| 1318 | + { |
| 1319 | + Port *port = (Port *) DLE_VAL(curr); |
| 1320 | + Dlelem *next = DLGetSucc(curr); |
| 1321 | + |
| 1322 | + if (port != myConn) |
| 1323 | + { |
| 1324 | + StreamClose(port->sock); |
| 1325 | + DLRemove(curr); |
| 1326 | + ConnFree(port); |
| 1327 | + DLFreeElem(curr); |
| 1328 | + } |
| 1329 | + |
| 1330 | + curr = next; |
| 1331 | + } |
| 1332 | +} |
| 1333 | + |
1288 | 1334 |
|
1289 | 1335 | /*
|
1290 | 1336 | * reset_shared -- reset shared memory and semaphores
|
@@ -1918,21 +1964,15 @@ DoBackend(Port *port)
|
1918 | 1964 | * Signal handlers setting is moved to tcop/postgres...
|
1919 | 1965 | */
|
1920 | 1966 |
|
1921 |
| - /* Close the postmaster sockets */ |
1922 |
| - if (NetServer) |
1923 |
| - StreamClose(ServerSock_INET); |
1924 |
| - ServerSock_INET = INVALID_SOCK; |
1925 |
| -#ifdef HAVE_UNIX_SOCKETS |
1926 |
| - StreamClose(ServerSock_UNIX); |
1927 |
| - ServerSock_UNIX = INVALID_SOCK; |
1928 |
| -#endif |
1929 |
| - |
1930 | 1967 | /* Save port etc. for ps status */
|
1931 | 1968 | MyProcPort = port;
|
1932 | 1969 |
|
1933 | 1970 | /* Reset MyProcPid to new backend's pid */
|
1934 | 1971 | MyProcPid = getpid();
|
1935 | 1972 |
|
| 1973 | + /* Close the postmaster's other sockets */ |
| 1974 | + ClosePostmasterPorts(port); |
| 1975 | + |
1936 | 1976 | /*
|
1937 | 1977 | * Don't want backend to be able to see the postmaster random number
|
1938 | 1978 | * generator state. We have to clobber the static random_seed *and*
|
@@ -2225,13 +2265,9 @@ SSDataBase(int xlop)
|
2225 | 2265 | /* Lose the postmaster's on-exit routines and port connections */
|
2226 | 2266 | on_exit_reset();
|
2227 | 2267 |
|
2228 |
| - if (NetServer) |
2229 |
| - StreamClose(ServerSock_INET); |
2230 |
| - ServerSock_INET = INVALID_SOCK; |
2231 |
| -#ifdef HAVE_UNIX_SOCKETS |
2232 |
| - StreamClose(ServerSock_UNIX); |
2233 |
| - ServerSock_UNIX = INVALID_SOCK; |
2234 |
| -#endif |
| 2268 | + /* Close the postmaster's sockets */ |
| 2269 | + ClosePostmasterPorts(NULL); |
| 2270 | + |
2235 | 2271 |
|
2236 | 2272 | av[ac++] = "postgres";
|
2237 | 2273 |
|
|
0 commit comments