3737 *
3838 *
3939 * IDENTIFICATION
40- * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.267 2002/02/23 01:31:35 petere Exp $
40+ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.268 2002/03/02 20:46:12 tgl Exp $
4141 *
4242 * NOTES
4343 *
@@ -769,6 +769,14 @@ pmdaemonize(int argc, char *argv[])
769769{
770770int i ;
771771pid_t pid ;
772+ #ifdef LINUX_PROFILE
773+ struct itimerval prof_itimer ;
774+ #endif
775+
776+ #ifdef LINUX_PROFILE
777+ /* see comments in BackendStartup */
778+ getitimer (ITIMER_PROF ,& prof_itimer );
779+ #endif
772780
773781pid = fork ();
774782if (pid == (pid_t )- 1 )
@@ -783,6 +791,10 @@ pmdaemonize(int argc, char *argv[])
783791_exit (0 );
784792}
785793
794+ #ifdef LINUX_PROFILE
795+ setitimer (ITIMER_PROF ,& prof_itimer ,NULL );
796+ #endif
797+
786798MyProcPid = getpid ();/* reset MyProcPid to child */
787799
788800/* GH: If there's no setsid(), we hopefully don't need silent mode.
@@ -1801,13 +1813,16 @@ SignalChildren(int signal)
18011813/*
18021814 * BackendStartup -- start backend process
18031815 *
1804- * returns: STATUS_ERROR if the fork/exec failed, STATUS_OK otherwise.
1816+ * returns: STATUS_ERROR if the fork failed, STATUS_OK otherwise.
18051817 */
18061818static int
18071819BackendStartup (Port * port )
18081820{
18091821Backend * bn ;/* for backend cleanup */
18101822pid_t pid ;
1823+ #ifdef LINUX_PROFILE
1824+ struct itimerval prof_itimer ;
1825+ #endif
18111826
18121827/*
18131828 * Compute the cancel key that will be assigned to this backend. The
@@ -1838,6 +1853,16 @@ BackendStartup(Port *port)
18381853fflush (stdout );
18391854fflush (stderr );
18401855
1856+ #ifdef LINUX_PROFILE
1857+ /*
1858+ * Linux's fork() resets the profiling timer in the child process.
1859+ * If we want to profile child processes then we need to save and restore
1860+ * the timer setting. This is a waste of time if not profiling, however,
1861+ * so only do it if commanded by specific -DLINUX_PROFILE switch.
1862+ */
1863+ getitimer (ITIMER_PROF ,& prof_itimer );
1864+ #endif
1865+
18411866#ifdef __BEOS__
18421867/* Specific beos actions before backend startup */
18431868beos_before_backend_startup ();
@@ -1849,6 +1874,10 @@ BackendStartup(Port *port)
18491874{
18501875int status ;
18511876
1877+ #ifdef LINUX_PROFILE
1878+ setitimer (ITIMER_PROF ,& prof_itimer ,NULL );
1879+ #endif
1880+
18521881#ifdef __BEOS__
18531882/* Specific beos backend startup actions */
18541883beos_backend_startup ();
@@ -2487,10 +2516,18 @@ SSDataBase(int xlop)
24872516{
24882517pid_t pid ;
24892518Backend * bn ;
2519+ #ifdef LINUX_PROFILE
2520+ struct itimerval prof_itimer ;
2521+ #endif
24902522
24912523fflush (stdout );
24922524fflush (stderr );
24932525
2526+ #ifdef LINUX_PROFILE
2527+ /* see comments in BackendStartup */
2528+ getitimer (ITIMER_PROF ,& prof_itimer );
2529+ #endif
2530+
24942531#ifdef __BEOS__
24952532/* Specific beos actions before backend startup */
24962533beos_before_backend_startup ();
@@ -2505,6 +2542,10 @@ SSDataBase(int xlop)
25052542char dbbuf [ARGV_SIZE ];
25062543char xlbuf [ARGV_SIZE ];
25072544
2545+ #ifdef LINUX_PROFILE
2546+ setitimer (ITIMER_PROF ,& prof_itimer ,NULL );
2547+ #endif
2548+
25082549#ifdef __BEOS__
25092550/* Specific beos actions after backend startup */
25102551beos_backend_startup ();
@@ -2603,7 +2644,7 @@ SSDataBase(int xlop)
26032644 */
26042645if (xlop == BS_XLOG_CHECKPOINT )
26052646{
2606- if (!(bn = (Backend * )calloc ( 1 , sizeof (Backend ))))
2647+ if (!(bn = (Backend * )malloc ( sizeof (Backend ))))
26072648{
26082649elog (DEBUG ,"CheckPointDataBase: malloc failed" );
26092650ExitPostmaster (1 );