mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
pgindent files for Tom.
This commit is contained in:
@ -13,7 +13,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/main/main.c,v 1.82 2004/05/25 01:00:20 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/main/main.c,v 1.83 2004/05/27 15:07:40 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -50,6 +50,7 @@ int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int len;
|
||||
|
||||
#ifndef WIN32
|
||||
struct passwd *pw;
|
||||
#endif
|
||||
@ -130,14 +131,14 @@ main(int argc, char *argv[])
|
||||
/*
|
||||
* Remember the physical location of the initially given argv[] array
|
||||
* for possible use by ps display. On some platforms, the argv[]
|
||||
* storage must be overwritten in order to set the process title for ps.
|
||||
* In such cases save_ps_display_args makes and returns a new copy of
|
||||
* the argv[] array.
|
||||
* storage must be overwritten in order to set the process title for
|
||||
* ps. In such cases save_ps_display_args makes and returns a new copy
|
||||
* of the argv[] array.
|
||||
*
|
||||
* save_ps_display_args may also move the environment strings to make
|
||||
* extra room. Therefore this should be done as early as possible during
|
||||
* startup, to avoid entanglements with code that might save a getenv()
|
||||
* result pointer.
|
||||
* extra room. Therefore this should be done as early as possible
|
||||
* during startup, to avoid entanglements with code that might save a
|
||||
* getenv() result pointer.
|
||||
*/
|
||||
argv = save_ps_display_args(argc, argv);
|
||||
|
||||
@ -145,20 +146,21 @@ main(int argc, char *argv[])
|
||||
* Set up locale information from environment. Note that LC_CTYPE and
|
||||
* LC_COLLATE will be overridden later from pg_control if we are in an
|
||||
* already-initialized database. We set them here so that they will
|
||||
* be available to fill pg_control during initdb. LC_MESSAGES will get
|
||||
* set later during GUC option processing, but we set it here to allow
|
||||
* startup error messages to be localized.
|
||||
* be available to fill pg_control during initdb. LC_MESSAGES will
|
||||
* get set later during GUC option processing, but we set it here to
|
||||
* allow startup error messages to be localized.
|
||||
*/
|
||||
|
||||
set_pglocale(argv[0], "postgres");
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
/*
|
||||
* Windows uses codepages rather than the environment, so we work around
|
||||
* that by querying the environment explicitly first for LC_COLLATE
|
||||
* and LC_CTYPE. We have to do this because initdb passes those values
|
||||
* in the environment. If there is nothing there we fall back on the
|
||||
* codepage.
|
||||
* Windows uses codepages rather than the environment, so we work
|
||||
* around that by querying the environment explicitly first for
|
||||
* LC_COLLATE and LC_CTYPE. We have to do this because initdb passes
|
||||
* those values in the environment. If there is nothing there we fall
|
||||
* back on the codepage.
|
||||
*/
|
||||
|
||||
if ((env_locale = getenv("LC_COLLATE")) != NULL)
|
||||
@ -241,8 +243,8 @@ main(int argc, char *argv[])
|
||||
/*
|
||||
* Now dispatch to one of PostmasterMain, PostgresMain, GucInfoMain,
|
||||
* SubPostmasterMain, pgstat_main, pgstat_mainChild or BootstrapMain
|
||||
* depending on the program name (and possibly first argument) we
|
||||
* were called with. The lack of consistency here is historical.
|
||||
* depending on the program name (and possibly first argument) we were
|
||||
* called with. The lack of consistency here is historical.
|
||||
*/
|
||||
len = strlen(argv[0]);
|
||||
|
||||
@ -264,9 +266,11 @@ main(int argc, char *argv[])
|
||||
exit(BootstrapMain(argc - 1, argv + 1));
|
||||
|
||||
#ifdef EXEC_BACKEND
|
||||
|
||||
/*
|
||||
* If the first argument is "-forkexec", then invoke SubPostmasterMain. Note
|
||||
* we remove "-forkexec" from the arguments passed on to SubPostmasterMain.
|
||||
* If the first argument is "-forkexec", then invoke
|
||||
* SubPostmasterMain. Note we remove "-forkexec" from the arguments
|
||||
* passed on to SubPostmasterMain.
|
||||
*/
|
||||
if (argc > 1 && strcmp(argv[1], "-forkexec") == 0)
|
||||
{
|
||||
|
@ -37,7 +37,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.395 2004/05/26 18:35:35 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.396 2004/05/27 15:07:41 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
*
|
||||
@ -180,6 +180,7 @@ static int ListenSocket[MAXLISTEN];
|
||||
/* Used to reduce macros tests */
|
||||
#ifdef EXEC_BACKEND
|
||||
const bool ExecBackend = true;
|
||||
|
||||
#else
|
||||
const bool ExecBackend = false;
|
||||
#endif
|
||||
@ -833,8 +834,9 @@ PostmasterMain(int argc, char *argv[])
|
||||
reset_shared(PostPortNumber);
|
||||
|
||||
/*
|
||||
* Estimate number of openable files. This must happen after setting up
|
||||
* semaphores, because on some platforms semaphores count as open files.
|
||||
* Estimate number of openable files. This must happen after setting
|
||||
* up semaphores, because on some platforms semaphores count as open
|
||||
* files.
|
||||
*/
|
||||
set_max_safe_fds();
|
||||
|
||||
@ -844,6 +846,7 @@ PostmasterMain(int argc, char *argv[])
|
||||
BackendList = DLNewList();
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
/*
|
||||
* Initialize the child pid/HANDLE arrays
|
||||
*/
|
||||
@ -1105,16 +1108,14 @@ ServerLoop(void)
|
||||
}
|
||||
|
||||
/*
|
||||
* If no background writer process is running and we should
|
||||
* do background writing, start one. It doesn't matter if
|
||||
* this fails, we'll just try again later.
|
||||
* If no background writer process is running and we should do
|
||||
* background writing, start one. It doesn't matter if this fails,
|
||||
* we'll just try again later.
|
||||
*/
|
||||
if (BgWriterPID == 0 && BgWriterPercent > 0 &&
|
||||
StartupPID == 0 && Shutdown == NoShutdown &&
|
||||
!FatalError && random_seed != 0)
|
||||
{
|
||||
BgWriterPID = StartBackgroundWriter();
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait for something to happen.
|
||||
@ -1523,8 +1524,10 @@ processCancelRequest(Port *port, void *pkt)
|
||||
int backendPID;
|
||||
long cancelAuthCode;
|
||||
Backend *bp;
|
||||
|
||||
#ifndef EXEC_BACKEND
|
||||
Dlelem *curr;
|
||||
|
||||
#else
|
||||
int i;
|
||||
#endif
|
||||
@ -1733,8 +1736,8 @@ SIGHUP_handler(SIGNAL_ARGS)
|
||||
load_ident();
|
||||
|
||||
/*
|
||||
* Tell the background writer to terminate so that we
|
||||
* will start a new one with a possibly changed config
|
||||
* Tell the background writer to terminate so that we will start a
|
||||
* new one with a possibly changed config
|
||||
*/
|
||||
if (BgWriterPID != 0)
|
||||
kill(BgWriterPID, SIGTERM);
|
||||
@ -1829,8 +1832,8 @@ pmdie(SIGNAL_ARGS)
|
||||
* No children left. Shutdown data base system.
|
||||
*
|
||||
* Unlike the previous case, it is not an error for the shutdown
|
||||
* process to be running already (we could get SIGTERM followed
|
||||
* shortly later by SIGINT).
|
||||
* process to be running already (we could get SIGTERM
|
||||
* followed shortly later by SIGINT).
|
||||
*/
|
||||
if (StartupPID > 0 || FatalError) /* let reaper() handle
|
||||
* this */
|
||||
@ -1874,6 +1877,7 @@ reaper(SIGNAL_ARGS)
|
||||
|
||||
#ifdef HAVE_WAITPID
|
||||
int status; /* backend exit status */
|
||||
|
||||
#else
|
||||
#ifndef WIN32
|
||||
union wait status; /* backend exit status */
|
||||
@ -1899,10 +1903,10 @@ reaper(SIGNAL_ARGS)
|
||||
while ((pid = win32_waitpid(&exitstatus)) > 0)
|
||||
{
|
||||
/*
|
||||
* We need to do this here, and not in CleanupProc, since this
|
||||
* is to be called on all children when we are done with them.
|
||||
* Could move to LogChildExit, but that seems like asking for
|
||||
* future trouble...
|
||||
* We need to do this here, and not in CleanupProc, since this is
|
||||
* to be called on all children when we are done with them. Could
|
||||
* move to LogChildExit, but that seems like asking for future
|
||||
* trouble...
|
||||
*/
|
||||
win32_RemoveChild(pid);
|
||||
#endif
|
||||
@ -2141,9 +2145,7 @@ CleanupProc(int pid,
|
||||
checkpointed = 0;
|
||||
}
|
||||
else if (pid == BgWriterPID)
|
||||
{
|
||||
BgWriterPID = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
@ -2473,6 +2475,7 @@ BackendInit(Port *port)
|
||||
remote_host, sizeof(remote_host),
|
||||
remote_port, sizeof(remote_port),
|
||||
NI_NUMERICHOST | NI_NUMERICSERV);
|
||||
|
||||
if (ret)
|
||||
ereport(WARNING,
|
||||
(errmsg("getnameinfo_all() failed: %s",
|
||||
@ -2558,8 +2561,8 @@ BackendRun(Port *port)
|
||||
int i;
|
||||
|
||||
/*
|
||||
* Let's clean up ourselves as the postmaster child, and
|
||||
* close the postmaster's other sockets
|
||||
* Let's clean up ourselves as the postmaster child, and close the
|
||||
* postmaster's other sockets
|
||||
*/
|
||||
ClosePostmasterPorts(true);
|
||||
|
||||
@ -2742,7 +2745,9 @@ Backend_forkexec(Port *port)
|
||||
{
|
||||
pid_t pid;
|
||||
char *av[5];
|
||||
int ac = 0, bufc = 0, i;
|
||||
int ac = 0,
|
||||
bufc = 0,
|
||||
i;
|
||||
char buf[2][MAXPGPATH];
|
||||
|
||||
if (!write_backend_variables(port))
|
||||
@ -2770,15 +2775,15 @@ Backend_forkexec(Port *port)
|
||||
#else
|
||||
/* Fire off execv in child */
|
||||
if ((pid = fork()) == 0 && (execv(postgres_exec_path, av) == -1))
|
||||
|
||||
/*
|
||||
* FIXME: [fork/exec] suggestions for what to do here?
|
||||
* Probably OK to issue error (unlike pgstat case)
|
||||
* FIXME: [fork/exec] suggestions for what to do here? Probably OK
|
||||
* to issue error (unlike pgstat case)
|
||||
*/
|
||||
abort();
|
||||
#endif
|
||||
return pid; /* Parent returns pid */
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -2865,8 +2870,9 @@ sigusr1_handler(SIGNAL_ARGS)
|
||||
if (CheckPostmasterSignal(PMSIGNAL_WAKEN_CHILDREN))
|
||||
{
|
||||
/*
|
||||
* Send SIGUSR1 to all children (triggers CatchupInterruptHandler).
|
||||
* See storage/ipc/sinval[adt].c for the use of this.
|
||||
* Send SIGUSR1 to all children (triggers
|
||||
* CatchupInterruptHandler). See storage/ipc/sinval[adt].c for the
|
||||
* use of this.
|
||||
*/
|
||||
if (Shutdown == NoShutdown)
|
||||
SignalChildren(SIGUSR1);
|
||||
@ -2999,8 +3005,7 @@ SSDataBaseInit(int xlop)
|
||||
{
|
||||
const char *statmsg;
|
||||
|
||||
IsUnderPostmaster = true; /* we are a postmaster subprocess
|
||||
* now */
|
||||
IsUnderPostmaster = true; /* we are a postmaster subprocess now */
|
||||
|
||||
#ifdef EXEC_BACKEND
|
||||
/* In EXEC case we will not have inherited these settings */
|
||||
@ -3044,6 +3049,7 @@ SSDataBase(int xlop)
|
||||
{
|
||||
pid_t pid;
|
||||
Backend *bn;
|
||||
|
||||
#ifndef EXEC_BACKEND
|
||||
#ifdef LINUX_PROFILE
|
||||
struct itimerval prof_itimer;
|
||||
@ -3190,8 +3196,8 @@ SSDataBase(int xlop)
|
||||
|
||||
/*
|
||||
* The startup and shutdown processes are not considered normal
|
||||
* backends, but the checkpoint and bgwriter processes are.
|
||||
* They must be added to the list of backends.
|
||||
* backends, but the checkpoint and bgwriter processes are. They must
|
||||
* be added to the list of backends.
|
||||
*/
|
||||
if (xlop == BS_XLOG_CHECKPOINT || xlop == BS_XLOG_BGWRITER)
|
||||
{
|
||||
@ -3309,6 +3315,7 @@ write_backend_variables(Port *port)
|
||||
{
|
||||
char filename[MAXPGPATH];
|
||||
FILE *fp;
|
||||
|
||||
get_tmp_backend_file_name(filename, ++tmpBackendFileNum);
|
||||
|
||||
/* Open file */
|
||||
@ -3317,6 +3324,7 @@ write_backend_variables(Port *port)
|
||||
{
|
||||
/* As per OpenTemporaryFile... */
|
||||
char dirname[MAXPGPATH];
|
||||
|
||||
sprintf(dirname, "%s/%s", DataDir, PG_TEMP_FILES_DIR);
|
||||
mkdir(dirname, S_IRWXU);
|
||||
|
||||
@ -3382,6 +3390,7 @@ read_backend_variables(unsigned long id, Port *port)
|
||||
{
|
||||
char filename[MAXPGPATH];
|
||||
FILE *fp;
|
||||
|
||||
get_tmp_backend_file_name(filename, id);
|
||||
|
||||
/* Open file */
|
||||
@ -3438,21 +3447,26 @@ read_backend_variables(unsigned long id, Port *port)
|
||||
}
|
||||
|
||||
|
||||
size_t ShmemBackendArraySize(void)
|
||||
size_t
|
||||
ShmemBackendArraySize(void)
|
||||
{
|
||||
return (NUM_BACKENDARRAY_ELEMS * sizeof(Backend));
|
||||
}
|
||||
|
||||
void ShmemBackendArrayAllocation(void)
|
||||
void
|
||||
ShmemBackendArrayAllocation(void)
|
||||
{
|
||||
size_t size = ShmemBackendArraySize();
|
||||
|
||||
ShmemBackendArray = (Backend *) ShmemAlloc(size);
|
||||
memset(ShmemBackendArray, 0, size);
|
||||
}
|
||||
|
||||
static void ShmemBackendArrayAdd(Backend *bn)
|
||||
static void
|
||||
ShmemBackendArrayAdd(Backend *bn)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NUM_BACKENDARRAY_ELEMS; i++)
|
||||
{
|
||||
/* Find an empty slot */
|
||||
@ -3467,9 +3481,11 @@ static void ShmemBackendArrayAdd(Backend *bn)
|
||||
(errmsg_internal("unable to add backend entry")));
|
||||
}
|
||||
|
||||
static void ShmemBackendArrayRemove(pid_t pid)
|
||||
static void
|
||||
ShmemBackendArrayRemove(pid_t pid)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NUM_BACKENDARRAY_ELEMS; i++)
|
||||
{
|
||||
if (ShmemBackendArray[i].pid == pid)
|
||||
@ -3484,12 +3500,12 @@ static void ShmemBackendArrayRemove(pid_t pid)
|
||||
(errmsg_internal("unable to find backend entry with pid %d",
|
||||
pid)));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
pid_t win32_forkexec(const char* path, char *argv[])
|
||||
pid_t
|
||||
win32_forkexec(const char *path, char *argv[])
|
||||
{
|
||||
STARTUPINFO si;
|
||||
PROCESS_INFORMATION pi;
|
||||
@ -3510,12 +3526,13 @@ pid_t win32_forkexec(const char* path, char *argv[])
|
||||
}
|
||||
|
||||
/*
|
||||
* The following snippet can disappear when we consistently
|
||||
* use forward slashes.
|
||||
* The following snippet can disappear when we consistently use
|
||||
* forward slashes.
|
||||
*/
|
||||
p = cmdLine;
|
||||
while (*(p++) != '\0')
|
||||
if (*p == '/') *p = '\\';
|
||||
if (*p == '/')
|
||||
*p = '\\';
|
||||
|
||||
memset(&pi, 0, sizeof(pi));
|
||||
memset(&si, 0, sizeof(si));
|
||||
@ -3562,7 +3579,8 @@ pid_t win32_forkexec(const char* path, char *argv[])
|
||||
* each call to win32_waitpid.
|
||||
*/
|
||||
|
||||
static void win32_AddChild(pid_t pid, HANDLE handle)
|
||||
static void
|
||||
win32_AddChild(pid_t pid, HANDLE handle)
|
||||
{
|
||||
Assert(win32_childPIDArray && win32_childHNDArray);
|
||||
if (win32_numChildren < NUM_BACKENDARRAY_ELEMS)
|
||||
@ -3577,9 +3595,11 @@ static void win32_AddChild(pid_t pid, HANDLE handle)
|
||||
pid)));
|
||||
}
|
||||
|
||||
static void win32_RemoveChild(pid_t pid)
|
||||
static void
|
||||
win32_RemoveChild(pid_t pid)
|
||||
{
|
||||
int i;
|
||||
|
||||
Assert(win32_childPIDArray && win32_childHNDArray);
|
||||
|
||||
for (i = 0; i < win32_numChildren; i++)
|
||||
@ -3601,7 +3621,8 @@ static void win32_RemoveChild(pid_t pid)
|
||||
pid)));
|
||||
}
|
||||
|
||||
static pid_t win32_waitpid(int *exitstatus)
|
||||
static pid_t
|
||||
win32_waitpid(int *exitstatus)
|
||||
{
|
||||
Assert(win32_childPIDArray && win32_childHNDArray);
|
||||
elog(DEBUG3, "waiting on %lu children", win32_numChildren);
|
||||
@ -3609,8 +3630,8 @@ static pid_t win32_waitpid(int *exitstatus)
|
||||
if (win32_numChildren > 0)
|
||||
{
|
||||
/*
|
||||
* Note: Do NOT use WaitForMultipleObjectsEx, as we don't
|
||||
* want to run queued APCs here.
|
||||
* Note: Do NOT use WaitForMultipleObjectsEx, as we don't want to
|
||||
* run queued APCs here.
|
||||
*/
|
||||
int index;
|
||||
DWORD exitCode;
|
||||
@ -3629,13 +3650,19 @@ static pid_t win32_waitpid(int *exitstatus)
|
||||
return -1;
|
||||
|
||||
default:
|
||||
/* Get the exit code, and return the PID of, the respective process */
|
||||
|
||||
/*
|
||||
* Get the exit code, and return the PID of, the
|
||||
* respective process
|
||||
*/
|
||||
index = ret - WAIT_OBJECT_0;
|
||||
Assert(index >= 0 && index < win32_numChildren);
|
||||
if (!GetExitCodeProcess(win32_childHNDArray[index], &exitCode))
|
||||
|
||||
/*
|
||||
* If we get this far, this should never happen, but, then again...
|
||||
* No choice other than to assume a catastrophic failure.
|
||||
* If we get this far, this should never happen, but,
|
||||
* then again... No choice other than to assume a
|
||||
* catastrophic failure.
|
||||
*/
|
||||
ereport(FATAL,
|
||||
(errmsg_internal("failed to get exit code for child %lu",
|
||||
@ -3651,10 +3678,13 @@ static pid_t win32_waitpid(int *exitstatus)
|
||||
|
||||
/* Note! Code belows executes on separate threads, one for
|
||||
each child process created */
|
||||
static DWORD WINAPI win32_sigchld_waiter(LPVOID param) {
|
||||
static DWORD WINAPI
|
||||
win32_sigchld_waiter(LPVOID param)
|
||||
{
|
||||
HANDLE procHandle = (HANDLE) param;
|
||||
|
||||
DWORD r = WaitForSingleObject(procHandle, INFINITE);
|
||||
|
||||
if (r == WAIT_OBJECT_0)
|
||||
pg_queue_signal(SIGCHLD);
|
||||
else
|
||||
|
Reference in New Issue
Block a user