37
37
*
38
38
*
39
39
* IDENTIFICATION
40
- * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.440 2004/11/17 08:30:09 neilc Exp $
40
+ * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.441 2004/12/29 21:36:03 tgl Exp $
41
41
*
42
42
* NOTES
43
43
*
@@ -1584,10 +1584,8 @@ processCancelRequest(Port *port, void *pkt)
1584
1584
int backendPID ;
1585
1585
long cancelAuthCode ;
1586
1586
Backend * bp ;
1587
-
1588
1587
#ifndef EXEC_BACKEND
1589
1588
Dlelem * curr ;
1590
-
1591
1589
#else
1592
1590
int i ;
1593
1591
#endif
@@ -3152,10 +3150,31 @@ SubPostmasterMain(int argc, char *argv[])
3152
3150
3153
3151
MyProcPid = getpid (); /* reset MyProcPid */
3154
3152
3155
- /* Read in file-based context */
3153
+ /* In EXEC_BACKEND case we will not have inherited these settings */
3154
+ IsPostmasterEnvironment = true;
3155
+ whereToSendOutput = None ;
3156
+
3157
+ /* Setup essential subsystems (to ensure elog() behaves sanely) */
3158
+ MemoryContextInit ();
3159
+ InitializeGUCOptions ();
3160
+
3161
+ /* Read in the variables file */
3156
3162
memset (& port , 0 , sizeof (Port ));
3157
3163
read_backend_variables (argv [2 ], & port );
3158
3164
3165
+ /* Check we got appropriate args */
3166
+ if (argc < 3 )
3167
+ elog (FATAL , "invalid subpostmaster invocation" );
3168
+
3169
+ /*
3170
+ * If appropriate, physically re-attach to shared memory segment.
3171
+ * We want to do this before going any further to ensure that we
3172
+ * can attach at the same address the postmaster used.
3173
+ */
3174
+ if (strcmp (argv [1 ], "-forkbackend" ) == 0 ||
3175
+ strcmp (argv [1 ], "-forkboot" ) == 0 )
3176
+ PGSharedMemoryReAttach ();
3177
+
3159
3178
/*
3160
3179
* Start our win32 signal implementation. This has to be done
3161
3180
* after we read the backend variables, because we need to pick
@@ -3166,19 +3185,9 @@ SubPostmasterMain(int argc, char *argv[])
3166
3185
#endif
3167
3186
3168
3187
/* In EXEC_BACKEND case we will not have inherited these settings */
3169
- IsPostmasterEnvironment = true;
3170
- whereToSendOutput = None ;
3171
3188
pqinitmask ();
3172
3189
PG_SETMASK (& BlockSig );
3173
3190
3174
- /* Setup essential subsystems */
3175
- MemoryContextInit ();
3176
- InitializeGUCOptions ();
3177
-
3178
- /* Check we got appropriate args */
3179
- if (argc < 3 )
3180
- elog (FATAL , "invalid subpostmaster invocation" );
3181
-
3182
3191
/* Read in remaining GUC variables */
3183
3192
read_nondefault_variables ();
3184
3193
@@ -3187,7 +3196,7 @@ SubPostmasterMain(int argc, char *argv[])
3187
3196
{
3188
3197
/* BackendRun will close sockets */
3189
3198
3190
- /* Attach process to shared segments */
3199
+ /* Attach process to shared data structures */
3191
3200
CreateSharedMemoryAndSemaphores (false, MaxBackends , 0 );
3192
3201
3193
3202
#ifdef USE_SSL
@@ -3208,7 +3217,7 @@ SubPostmasterMain(int argc, char *argv[])
3208
3217
/* Close the postmaster's sockets */
3209
3218
ClosePostmasterPorts (false);
3210
3219
3211
- /* Attach process to shared segments */
3220
+ /* Attach process to shared data structures */
3212
3221
CreateSharedMemoryAndSemaphores (false, MaxBackends , 0 );
3213
3222
3214
3223
BootstrapMain (argc - 2 , argv + 2 );
@@ -3259,6 +3268,7 @@ SubPostmasterMain(int argc, char *argv[])
3259
3268
3260
3269
return 1 ; /* shouldn't get here */
3261
3270
}
3271
+
3262
3272
#endif /* EXEC_BACKEND */
3263
3273
3264
3274
@@ -3767,10 +3777,11 @@ read_inheritable_socket(SOCKET *dest, InheritableSocket *src)
3767
3777
static void
3768
3778
read_backend_variables (char * id , Port * port )
3769
3779
{
3780
+ BackendParameters param ;
3781
+
3770
3782
#ifndef WIN32
3771
3783
/* Non-win32 implementation reads from file */
3772
3784
FILE * fp ;
3773
- BackendParameters param ;
3774
3785
3775
3786
/* Open file */
3776
3787
fp = AllocateFile (id , PG_BINARY_R );
@@ -3796,25 +3807,23 @@ read_backend_variables(char *id, Port *port)
3796
3807
id , strerror (errno ));
3797
3808
exit (1 );
3798
3809
}
3799
-
3800
- restore_backend_variables (& param , port );
3801
3810
#else
3802
3811
/* Win32 version uses mapped file */
3803
3812
HANDLE paramHandle ;
3804
- BackendParameters * param ;
3813
+ BackendParameters * paramp ;
3805
3814
3806
3815
paramHandle = (HANDLE )atol (id );
3807
- param = MapViewOfFile (paramHandle , FILE_MAP_READ , 0 , 0 , 0 );
3808
- if (!param )
3816
+ paramp = MapViewOfFile (paramHandle , FILE_MAP_READ , 0 , 0 , 0 );
3817
+ if (!paramp )
3809
3818
{
3810
3819
write_stderr ("could not map view of backend variables: error code %d\n" ,
3811
3820
(int ) GetLastError ());
3812
3821
exit (1 );
3813
3822
}
3814
3823
3815
- restore_backend_variables ( param , port );
3824
+ memcpy ( & param , paramp , sizeof ( BackendParameters ) );
3816
3825
3817
- if (!UnmapViewOfFile (param ))
3826
+ if (!UnmapViewOfFile (paramp ))
3818
3827
{
3819
3828
write_stderr ("could not unmap view of backend variables: error code %d\n" ,
3820
3829
(int ) GetLastError ());
@@ -3828,6 +3837,8 @@ read_backend_variables(char *id, Port *port)
3828
3837
exit (1 );
3829
3838
}
3830
3839
#endif
3840
+
3841
+ restore_backend_variables (& param , port );
3831
3842
}
3832
3843
3833
3844
/* Restore critical backend variables from the BackendParameters struct */
@@ -3930,6 +3941,7 @@ ShmemBackendArrayRemove(pid_t pid)
3930
3941
(errmsg_internal ("could not find backend entry with pid %d" ,
3931
3942
(int ) pid )));
3932
3943
}
3944
+
3933
3945
#endif /* EXEC_BACKEND */
3934
3946
3935
3947
0 commit comments