3737 *
3838 *
3939 * IDENTIFICATION
40- * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.445 2005/02/22 04:36:36 momjian Exp $
40+ * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.446 2005/03/10 07:14:03 neilc Exp $
4141 *
4242 * NOTES
4343 *
9292#include <DNSServiceDiscovery/DNSServiceDiscovery.h>
9393#endif
9494
95+ #include "access/xlog.h"
96+ #include "bootstrap/bootstrap.h"
9597#include "catalog/pg_control.h"
9698#include "catalog/pg_database.h"
9799#include "commands/async.h"
103105#include "libpq/pqsignal.h"
104106#include "miscadmin.h"
105107#include "nodes/nodes.h"
106- #include "postmaster/postmaster.h"
108+ #include "pgstat.h"
109+ #include "postmaster/fork_process.h"
107110#include "postmaster/pgarch.h"
111+ #include "postmaster/postmaster.h"
108112#include "postmaster/syslogger.h"
113+ #include "storage/bufmgr.h"
109114#include "storage/fd.h"
110115#include "storage/ipc.h"
111116#include "storage/pg_shmem.h"
112117#include "storage/pmsignal.h"
113118#include "storage/proc.h"
114- #include "storage/bufmgr.h"
115- #include "access/xlog.h"
116119#include "tcop/tcopprot.h"
117120#include "utils/builtins.h"
118121#include "utils/guc.h"
119122#include "utils/memutils.h"
120123#include "utils/ps_status.h"
121- #include "bootstrap/bootstrap.h"
122- #include "pgstat.h"
123124
124125#ifdef EXEC_BACKEND
125126#include "storage/spin.h"
@@ -1008,16 +1009,7 @@ pmdaemonize(void)
10081009 int i ;
10091010 pid_t pid ;
10101011
1011- #ifdef LINUX_PROFILE
1012- struct itimerval prof_itimer ;
1013- #endif
1014-
1015- #ifdef LINUX_PROFILE
1016- /* see comments in BackendStartup */
1017- getitimer (ITIMER_PROF , & prof_itimer );
1018- #endif
1019-
1020- pid = fork ();
1012+ pid = fork_process ();
10211013 if (pid == (pid_t ) - 1 )
10221014 {
10231015 write_stderr ("%s: could not fork background process: %s\n" ,
@@ -1030,10 +1022,6 @@ pmdaemonize(void)
10301022 _exit (0 );
10311023 }
10321024
1033- #ifdef LINUX_PROFILE
1034- setitimer (ITIMER_PROF , & prof_itimer , NULL );
1035- #endif
1036-
10371025 MyProcPid = PostmasterPid = getpid (); /* reset PID vars to child */
10381026
10391027/* GH: If there's no setsid(), we hopefully don't need silent mode.
@@ -2382,10 +2370,6 @@ BackendStartup(Port *port)
23822370 Backend * bn ; /* for backend cleanup */
23832371 pid_t pid ;
23842372
2385- #ifdef LINUX_PROFILE
2386- struct itimerval prof_itimer ;
2387- #endif
2388-
23892373 /*
23902374 * Compute the cancel key that will be assigned to this backend. The
23912375 * backend will have its own copy in the forked-off process' value of
@@ -2409,54 +2393,13 @@ BackendStartup(Port *port)
24092393 /* Pass down canAcceptConnections state (kluge for EXEC_BACKEND case) */
24102394 port -> canAcceptConnections = canAcceptConnections ();
24112395
2412- /*
2413- * Flush stdio channels just before fork, to avoid double-output
2414- * problems. Ideally we'd use fflush(NULL) here, but there are still a
2415- * few non-ANSI stdio libraries out there (like SunOS 4.1.x) that
2416- * coredump if we do. Presently stdout and stderr are the only stdio
2417- * output channels used by the postmaster, so fflush'ing them should
2418- * be sufficient.
2419- */
2420- fflush (stdout );
2421- fflush (stderr );
2422-
24232396#ifdef EXEC_BACKEND
2424-
24252397 pid = backend_forkexec (port );
2426-
24272398#else /* !EXEC_BACKEND */
2428-
2429- #ifdef LINUX_PROFILE
2430-
2431- /*
2432- * Linux's fork() resets the profiling timer in the child process. If
2433- * we want to profile child processes then we need to save and restore
2434- * the timer setting. This is a waste of time if not profiling,
2435- * however, so only do it if commanded by specific -DLINUX_PROFILE
2436- * switch.
2437- */
2438- getitimer (ITIMER_PROF , & prof_itimer );
2439- #endif
2440-
2441- #ifdef __BEOS__
2442- /* Specific beos actions before backend startup */
2443- beos_before_backend_startup ();
2444- #endif
2445-
2446- pid = fork ();
2447-
2399+ pid = fork_process ();
24482400 if (pid == 0 ) /* child */
24492401 {
2450- #ifdef LINUX_PROFILE
2451- setitimer (ITIMER_PROF , & prof_itimer , NULL );
2452- #endif
2453-
2454- #ifdef __BEOS__
2455- /* Specific beos backend startup actions */
2456- beos_backend_startup ();
2457- #endif
24582402 free (bn );
2459-
24602403 proc_exit (BackendRun (port ));
24612404 }
24622405#endif /* EXEC_BACKEND */
@@ -2466,10 +2409,6 @@ BackendStartup(Port *port)
24662409 /* in parent, fork failed */
24672410 int save_errno = errno ;
24682411
2469- #ifdef __BEOS__
2470- /* Specific beos backend startup actions */
2471- beos_backend_startup_failed ();
2472- #endif
24732412 free (bn );
24742413 errno = save_errno ;
24752414 ereport (LOG ,
@@ -2945,7 +2884,7 @@ internal_forkexec(int argc, char *argv[], Port *port)
29452884 argv [2 ] = tmpfilename ;
29462885
29472886 /* Fire off execv in child */
2948- if ((pid = fork ()) == 0 )
2887+ if ((pid = fork_process ()) == 0 )
29492888 {
29502889 if (execv (postgres_exec_path , argv ) < 0 )
29512890 {
@@ -3465,10 +3404,6 @@ StartChildProcess(int xlop)
34653404 int ac = 0 ;
34663405 char xlbuf [32 ];
34673406
3468- #ifdef LINUX_PROFILE
3469- struct itimerval prof_itimer ;
3470- #endif
3471-
34723407 /*
34733408 * Set up command-line arguments for subprocess
34743409 */
@@ -3488,41 +3423,13 @@ StartChildProcess(int xlop)
34883423 av [ac ] = NULL ;
34893424 Assert (ac < lengthof (av ));
34903425
3491- /*
3492- * Flush stdio channels (see comments in BackendStartup)
3493- */
3494- fflush (stdout );
3495- fflush (stderr );
3496-
34973426#ifdef EXEC_BACKEND
3498-
34993427 pid = postmaster_forkexec (ac , av );
3500-
35013428#else /* !EXEC_BACKEND */
3502-
3503- #ifdef LINUX_PROFILE
3504- /* see comments in BackendStartup */
3505- getitimer (ITIMER_PROF , & prof_itimer );
3506- #endif
3507-
3508- #ifdef __BEOS__
3509- /* Specific beos actions before backend startup */
3510- beos_before_backend_startup ();
3511- #endif
3512-
3513- pid = fork ();
3429+ pid = fork_process ();
35143430
35153431 if (pid == 0 ) /* child */
35163432 {
3517- #ifdef LINUX_PROFILE
3518- setitimer (ITIMER_PROF , & prof_itimer , NULL );
3519- #endif
3520-
3521- #ifdef __BEOS__
3522- /* Specific beos actions after backend startup */
3523- beos_backend_startup ();
3524- #endif
3525-
35263433 IsUnderPostmaster = true; /* we are a postmaster subprocess
35273434 * now */
35283435
@@ -3546,11 +3453,6 @@ StartChildProcess(int xlop)
35463453 {
35473454 /* in parent, fork failed */
35483455 int save_errno = errno ;
3549-
3550- #ifdef __BEOS__
3551- /* Specific beos actions before backend startup */
3552- beos_backend_startup_failed ();
3553- #endif
35543456 errno = save_errno ;
35553457 switch (xlop )
35563458 {
0 commit comments