Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 07bf378

Browse files
committed
process startup: Centralize pgwin32_signal_initialize() calls.
For one, the existing location lead to somewhat awkward code in main(). For another, the new location is easier to understand anyway. Author: Andres Freund <andres@anarazel.de> Reviewed-By: Kyotaro Horiguchi <horikyota.ntt@gmail.com> Reviewed-By: Robert Haas <robertmhaas@gmail.com> Discussion: https://postgr.es/m/20210802164124.ufo5buo4apl6yuvs@alap3.anarazel.de
1 parent f8dd4ec commit 07bf378

File tree

3 files changed

+27
-30
lines changed

3 files changed

+27
-30
lines changed

src/backend/main/main.c

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -181,35 +181,24 @@ main(int argc, char *argv[])
181181
* Dispatch to one of various subprograms depending on first argument.
182182
*/
183183

184-
#ifdef EXEC_BACKEND
185-
if (argc > 1 && strncmp(argv[1], "--fork", 6) == 0)
186-
SubPostmasterMain(argc, argv); /* does not return */
187-
#endif
188-
189-
#ifdef WIN32
190-
191-
/*
192-
* Start our win32 signal implementation
193-
*
194-
* SubPostmasterMain() will do this for itself, but the remaining modes
195-
* need it here
196-
*/
197-
pgwin32_signal_initialize();
198-
#endif
199-
200184
if (argc > 1 && strcmp(argv[1], "--check") == 0)
201185
BootstrapModeMain(argc, argv, true);
202186
else if (argc > 1 && strcmp(argv[1], "--boot") == 0)
203187
BootstrapModeMain(argc, argv, false);
188+
#ifdef EXEC_BACKEND
189+
else if (argc > 1 && strncmp(argv[1], "--fork", 6) == 0)
190+
SubPostmasterMain(argc, argv);
191+
#endif
204192
else if (argc > 1 && strcmp(argv[1], "--describe-config") == 0)
205-
GucInfoMain(); /* does not return */
193+
GucInfoMain();
206194
else if (argc > 1 && strcmp(argv[1], "--single") == 0)
207195
PostgresMain(argc, argv,
208196
NULL, /* no dbname */
209-
strdup(get_user_name_or_exit(progname))); /* does not return */
197+
strdup(get_user_name_or_exit(progname)));
210198
else
211-
PostmasterMain(argc, argv); /* does not return */
212-
abort(); /* should not get here */
199+
PostmasterMain(argc, argv);
200+
/* the functions above should not return */
201+
abort();
213202
}
214203

215204

src/backend/postmaster/postmaster.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4905,15 +4905,6 @@ SubPostmasterMain(int argc, char *argv[])
49054905
/* Close the postmaster's sockets (as soon as we know them) */
49064906
ClosePostmasterPorts(strcmp(argv[1], "--forklog") == 0);
49074907

4908-
/*
4909-
* Start our win32 signal implementation. This has to be done after we
4910-
* read the backend variables, because we need to pick up the signal pipe
4911-
* from the parent process.
4912-
*/
4913-
#ifdef WIN32
4914-
pgwin32_signal_initialize();
4915-
#endif
4916-
49174908
/* Setup as postmaster child */
49184909
InitPostmasterChild();
49194910

src/backend/utils/init/miscinit.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,23 @@ bool IgnoreSystemIndexes = false;
8787
/*
8888
* Initialize the basic environment for a postmaster child
8989
*
90-
* Should be called as early as possible after the child's startup.
90+
* Should be called as early as possible after the child's startup. However,
91+
* on EXEC_BACKEND builds it does need to be after read_backend_variables().
9192
*/
9293
void
9394
InitPostmasterChild(void)
9495
{
9596
IsUnderPostmaster = true; /* we are a postmaster subprocess now */
9697

98+
/*
99+
* Start our win32 signal implementation. This has to be done after we
100+
* read the backend variables, because we need to pick up the signal pipe
101+
* from the parent process.
102+
*/
103+
#ifdef WIN32
104+
pgwin32_signal_initialize();
105+
#endif
106+
97107
/*
98108
* Set reference point for stack-depth checking. We re-do that even in the
99109
* !EXEC_BACKEND case, because there are some edge cases where processes
@@ -166,6 +176,13 @@ InitStandaloneProcess(const char *argv0)
166176
{
167177
Assert(!IsPostmasterEnvironment);
168178

179+
/*
180+
* Start our win32 signal implementation
181+
*/
182+
#ifdef WIN32
183+
pgwin32_signal_initialize();
184+
#endif
185+
169186
InitProcessGlobals();
170187

171188
/* Initialize process-local latch support */

0 commit comments

Comments
 (0)