Skip to content

Commit 1c91838

Browse files
committed
Clean up order in miscinit.c a bit
The code around InitPostmasterChild() from commit 31c4531 somehow ended up in the middle of a block of code related to "User ID state". Move it into its own block instead.
1 parent aaa3aed commit 1c91838

File tree

2 files changed

+118
-114
lines changed

2 files changed

+118
-114
lines changed

src/backend/utils/init/miscinit.c

Lines changed: 113 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,119 @@ static Latch LocalLatchData;
7575
bool IgnoreSystemIndexes = false;
7676

7777

78+
/* ----------------------------------------------------------------
79+
* common process startup code
80+
* ----------------------------------------------------------------
81+
*/
82+
83+
/*
84+
* Initialize the basic environment for a postmaster child
85+
*
86+
* Should be called as early as possible after the child's startup.
87+
*/
88+
void
89+
InitPostmasterChild(void)
90+
{
91+
IsUnderPostmaster = true; /* we are a postmaster subprocess now */
92+
93+
InitProcessGlobals();
94+
95+
/*
96+
* make sure stderr is in binary mode before anything can possibly be
97+
* written to it, in case it's actually the syslogger pipe, so the pipe
98+
* chunking protocol isn't disturbed. Non-logpipe data gets translated on
99+
* redirection (e.g. via pg_ctl -l) anyway.
100+
*/
101+
#ifdef WIN32
102+
_setmode(fileno(stderr), _O_BINARY);
103+
#endif
104+
105+
/* We don't want the postmaster's proc_exit() handlers */
106+
on_exit_reset();
107+
108+
/* Initialize process-local latch support */
109+
InitializeLatchSupport();
110+
MyLatch = &LocalLatchData;
111+
InitLatch(MyLatch);
112+
113+
/*
114+
* If possible, make this process a group leader, so that the postmaster
115+
* can signal any child processes too. Not all processes will have
116+
* children, but for consistency we make all postmaster child processes do
117+
* this.
118+
*/
119+
#ifdef HAVE_SETSID
120+
if (setsid() < 0)
121+
elog(FATAL, "setsid() failed: %m");
122+
#endif
123+
124+
/* Request a signal if the postmaster dies, if possible. */
125+
PostmasterDeathSignalInit();
126+
}
127+
128+
/*
129+
* Initialize the basic environment for a standalone process.
130+
*
131+
* argv0 has to be suitable to find the program's executable.
132+
*/
133+
void
134+
InitStandaloneProcess(const char *argv0)
135+
{
136+
Assert(!IsPostmasterEnvironment);
137+
138+
InitProcessGlobals();
139+
140+
/* Initialize process-local latch support */
141+
InitializeLatchSupport();
142+
MyLatch = &LocalLatchData;
143+
InitLatch(MyLatch);
144+
145+
/* Compute paths, no postmaster to inherit from */
146+
if (my_exec_path[0] == '\0')
147+
{
148+
if (find_my_exec(argv0, my_exec_path) < 0)
149+
elog(FATAL, "%s: could not locate my own executable path",
150+
argv0);
151+
}
152+
153+
if (pkglib_path[0] == '\0')
154+
get_pkglib_path(my_exec_path, pkglib_path);
155+
}
156+
157+
void
158+
SwitchToSharedLatch(void)
159+
{
160+
Assert(MyLatch == &LocalLatchData);
161+
Assert(MyProc != NULL);
162+
163+
MyLatch = &MyProc->procLatch;
164+
165+
if (FeBeWaitSet)
166+
ModifyWaitEvent(FeBeWaitSet, 1, WL_LATCH_SET, MyLatch);
167+
168+
/*
169+
* Set the shared latch as the local one might have been set. This
170+
* shouldn't normally be necessary as code is supposed to check the
171+
* condition before waiting for the latch, but a bit care can't hurt.
172+
*/
173+
SetLatch(MyLatch);
174+
}
175+
176+
void
177+
SwitchBackToLocalLatch(void)
178+
{
179+
Assert(MyLatch != &LocalLatchData);
180+
Assert(MyProc != NULL && MyLatch == &MyProc->procLatch);
181+
182+
MyLatch = &LocalLatchData;
183+
184+
if (FeBeWaitSet)
185+
ModifyWaitEvent(FeBeWaitSet, 1, WL_LATCH_SET, MyLatch);
186+
187+
SetLatch(MyLatch);
188+
}
189+
190+
78191
/* ----------------------------------------------------------------
79192
* database path / name support stuff
80193
* ----------------------------------------------------------------
@@ -262,113 +375,6 @@ static int SecurityRestrictionContext = 0;
262375
/* We also remember if a SET ROLE is currently active */
263376
static bool SetRoleIsActive = false;
264377

265-
/*
266-
* Initialize the basic environment for a postmaster child
267-
*
268-
* Should be called as early as possible after the child's startup.
269-
*/
270-
void
271-
InitPostmasterChild(void)
272-
{
273-
IsUnderPostmaster = true; /* we are a postmaster subprocess now */
274-
275-
InitProcessGlobals();
276-
277-
/*
278-
* make sure stderr is in binary mode before anything can possibly be
279-
* written to it, in case it's actually the syslogger pipe, so the pipe
280-
* chunking protocol isn't disturbed. Non-logpipe data gets translated on
281-
* redirection (e.g. via pg_ctl -l) anyway.
282-
*/
283-
#ifdef WIN32
284-
_setmode(fileno(stderr), _O_BINARY);
285-
#endif
286-
287-
/* We don't want the postmaster's proc_exit() handlers */
288-
on_exit_reset();
289-
290-
/* Initialize process-local latch support */
291-
InitializeLatchSupport();
292-
MyLatch = &LocalLatchData;
293-
InitLatch(MyLatch);
294-
295-
/*
296-
* If possible, make this process a group leader, so that the postmaster
297-
* can signal any child processes too. Not all processes will have
298-
* children, but for consistency we make all postmaster child processes do
299-
* this.
300-
*/
301-
#ifdef HAVE_SETSID
302-
if (setsid() < 0)
303-
elog(FATAL, "setsid() failed: %m");
304-
#endif
305-
306-
/* Request a signal if the postmaster dies, if possible. */
307-
PostmasterDeathSignalInit();
308-
}
309-
310-
/*
311-
* Initialize the basic environment for a standalone process.
312-
*
313-
* argv0 has to be suitable to find the program's executable.
314-
*/
315-
void
316-
InitStandaloneProcess(const char *argv0)
317-
{
318-
Assert(!IsPostmasterEnvironment);
319-
320-
InitProcessGlobals();
321-
322-
/* Initialize process-local latch support */
323-
InitializeLatchSupport();
324-
MyLatch = &LocalLatchData;
325-
InitLatch(MyLatch);
326-
327-
/* Compute paths, no postmaster to inherit from */
328-
if (my_exec_path[0] == '\0')
329-
{
330-
if (find_my_exec(argv0, my_exec_path) < 0)
331-
elog(FATAL, "%s: could not locate my own executable path",
332-
argv0);
333-
}
334-
335-
if (pkglib_path[0] == '\0')
336-
get_pkglib_path(my_exec_path, pkglib_path);
337-
}
338-
339-
void
340-
SwitchToSharedLatch(void)
341-
{
342-
Assert(MyLatch == &LocalLatchData);
343-
Assert(MyProc != NULL);
344-
345-
MyLatch = &MyProc->procLatch;
346-
347-
if (FeBeWaitSet)
348-
ModifyWaitEvent(FeBeWaitSet, 1, WL_LATCH_SET, MyLatch);
349-
350-
/*
351-
* Set the shared latch as the local one might have been set. This
352-
* shouldn't normally be necessary as code is supposed to check the
353-
* condition before waiting for the latch, but a bit care can't hurt.
354-
*/
355-
SetLatch(MyLatch);
356-
}
357-
358-
void
359-
SwitchBackToLocalLatch(void)
360-
{
361-
Assert(MyLatch != &LocalLatchData);
362-
Assert(MyProc != NULL && MyLatch == &MyProc->procLatch);
363-
364-
MyLatch = &LocalLatchData;
365-
366-
if (FeBeWaitSet)
367-
ModifyWaitEvent(FeBeWaitSet, 1, WL_LATCH_SET, MyLatch);
368-
369-
SetLatch(MyLatch);
370-
}
371-
372378
/*
373379
* GetUserId - get the current effective user ID.
374380
*

src/include/miscadmin.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,13 @@ extern char *DatabasePath;
303303
/* now in utils/init/miscinit.c */
304304
extern void InitPostmasterChild(void);
305305
extern void InitStandaloneProcess(const char *argv0);
306+
extern void SwitchToSharedLatch(void);
307+
extern void SwitchBackToLocalLatch(void);
306308

307309
extern void SetDatabasePath(const char *path);
310+
extern void checkDataDir(void);
311+
extern void SetDataDir(const char *dir);
312+
extern void ChangeToDataDir(void);
308313

309314
extern char *GetUserNameFromId(Oid roleid, bool noerr);
310315
extern Oid GetUserId(void);
@@ -324,13 +329,6 @@ extern void SetSessionAuthorization(Oid userid, bool is_superuser);
324329
extern Oid GetCurrentRoleId(void);
325330
extern void SetCurrentRoleId(Oid roleid, bool is_superuser);
326331

327-
extern void checkDataDir(void);
328-
extern void SetDataDir(const char *dir);
329-
extern void ChangeToDataDir(void);
330-
331-
extern void SwitchToSharedLatch(void);
332-
extern void SwitchBackToLocalLatch(void);
333-
334332
/* in utils/misc/superuser.c */
335333
extern bool superuser(void); /* current user is superuser */
336334
extern bool superuser_arg(Oid roleid); /* given user is superuser */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy