Commit 7414d619 authored by Marc G. Fournier's avatar Marc G. Fournier

From: Massimo Dal Zotto <dz@cs.unitn.it>

> tprintf.patch
>
>       tprintf.patch
>
>       adds functions and macros which implement a conditional trace package
>       with the ability to change flags and numeric options of running
>       backends at runtime.
>       Options/flags can be specified in the command line and/or read from
>       the file pg_options in the data directory.
parent 51e8e187
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.29 1998/08/19 02:01:16 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.30 1998/08/25 21:33:56 scrappy Exp $
* *
* NOTES * NOTES
* This file contains only the public interface routines. * This file contains only the public interface routines.
...@@ -35,8 +35,8 @@ ...@@ -35,8 +35,8 @@
#ifdef BTREE_BUILD_STATS #ifdef BTREE_BUILD_STATS
#include <tcop/tcopprot.h> #include <tcop/tcopprot.h>
extern int ShowExecutorStats; #include <utils/trace.h>
#define ShowExecutorStats pg_options[TRACE_EXECUTORSTATS]
#endif #endif
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Id: nbtsort.c,v 1.30 1998/06/15 19:27:59 momjian Exp $ * $Id: nbtsort.c,v 1.31 1998/08/25 21:33:57 scrappy Exp $
* *
* NOTES * NOTES
* *
...@@ -64,8 +64,8 @@ ...@@ -64,8 +64,8 @@
#ifdef BTREE_BUILD_STATS #ifdef BTREE_BUILD_STATS
#include "tcop/tcopprot.h" #include "tcop/tcopprot.h"
extern int ShowExecutorStats; #include <utils/trace.h>
#define ShowExecutorStats pg_options[TRACE_EXECUTORSTATS]
#endif #endif
static BTItem _bt_buildadd(Relation index, void *pstate, BTItem bti, int flags); static BTItem _bt_buildadd(Relation index, void *pstate, BTItem bti, int flags);
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.94 1998/08/25 21:04:36 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.95 1998/08/25 21:33:59 scrappy Exp $
* *
* NOTES * NOTES
* *
...@@ -92,6 +92,7 @@ ...@@ -92,6 +92,7 @@
#include "port-protos.h" /* For gethostname() */ #include "port-protos.h" /* For gethostname() */
#endif #endif
#include "storage/fd.h" #include "storage/fd.h"
#include "utils/trace.h"
#if !defined(MAXINT) #if !defined(MAXINT)
#define MAXINT INT_MAX #define MAXINT INT_MAX
...@@ -116,6 +117,8 @@ typedef struct bkend ...@@ -116,6 +117,8 @@ typedef struct bkend
long cancel_key; /* cancel key for cancels for this backend */ long cancel_key; /* cancel key for cancels for this backend */
} Backend; } Backend;
Port *MyBackendPort = NULL;
/* list of active backends. For garbage collection only now. */ /* list of active backends. For garbage collection only now. */
static Dllist *BackendList; static Dllist *BackendList;
...@@ -232,6 +235,7 @@ static int processCancelRequest(Port *port, PacketLen len, void *pkt); ...@@ -232,6 +235,7 @@ static int processCancelRequest(Port *port, PacketLen len, void *pkt);
static int initMasks(fd_set *rmask, fd_set *wmask); static int initMasks(fd_set *rmask, fd_set *wmask);
static long PostmasterRandom(void); static long PostmasterRandom(void);
static void RandomSalt(char *salt); static void RandomSalt(char *salt);
static void SignalChildren(SIGNAL_ARGS);
#ifdef CYR_RECODE #ifdef CYR_RECODE
void GetCharSetByHost(char *, int, char *); void GetCharSetByHost(char *, int, char *);
...@@ -314,16 +318,16 @@ PostmasterMain(int argc, char *argv[]) ...@@ -314,16 +318,16 @@ PostmasterMain(int argc, char *argv[])
* We need three params so we can display status. If we don't * We need three params so we can display status. If we don't
* get them from the user, let's make them ourselves. * get them from the user, let's make them ourselves.
*/ */
if (argc < 4) if (argc < 5)
{ {
int i; int i;
char *new_argv[5]; char *new_argv[6];
for (i=0; i < argc; i++) for (i=0; i < argc; i++)
new_argv[i] = argv[i]; new_argv[i] = argv[i];
for (; i < 4; i++) for (; i < 5; i++)
new_argv[i] = ""; new_argv[i] = "";
new_argv[4] = NULL; new_argv[5] = NULL;
if (!Execfile[0] && FindExec(Execfile, argv[0], "postmaster") < 0) if (!Execfile[0] && FindExec(Execfile, argv[0], "postmaster") < 0)
{ {
...@@ -363,6 +367,7 @@ PostmasterMain(int argc, char *argv[]) ...@@ -363,6 +367,7 @@ PostmasterMain(int argc, char *argv[])
hostName = hostbuf; hostName = hostbuf;
} }
MyProcPid = getpid();
DataDir = getenv("PGDATA"); /* default value */ DataDir = getenv("PGDATA"); /* default value */
opterr = 0; opterr = 0;
...@@ -424,6 +429,7 @@ PostmasterMain(int argc, char *argv[]) ...@@ -424,6 +429,7 @@ PostmasterMain(int argc, char *argv[])
} }
else else
DebugLvl = 1; DebugLvl = 1;
pg_options[TRACE_VERBOSE] = DebugLvl;
break; break;
case 'i': case 'i':
NetServer = true; NetServer = true;
...@@ -535,14 +541,17 @@ PostmasterMain(int argc, char *argv[]) ...@@ -535,14 +541,17 @@ PostmasterMain(int argc, char *argv[])
* Set up signal handlers for the postmaster process. * Set up signal handlers for the postmaster process.
*/ */
pqsignal(SIGINT, pmdie); pqsignal(SIGHUP, pmdie); /* send SIGHUP, don't die */
pqsignal(SIGCHLD, reaper); pqsignal(SIGINT, pmdie); /* die */
pqsignal(SIGTTIN, SIG_IGN); pqsignal(SIGQUIT, pmdie); /* send SIGTERM and die */
pqsignal(SIGTTOU, SIG_IGN); pqsignal(SIGTERM, pmdie); /* send SIGTERM,SIGKILL and die */
pqsignal(SIGHUP, pmdie); pqsignal(SIGPIPE, SIG_IGN); /* ignored */
pqsignal(SIGTERM, pmdie); pqsignal(SIGUSR1, pmdie); /* send SIGUSR1 and die */
pqsignal(SIGCONT, dumpstatus); pqsignal(SIGUSR2, pmdie); /* send SIGUSR2, don't die */
pqsignal(SIGPIPE, SIG_IGN); pqsignal(SIGCHLD, reaper); /* handle child termination */
pqsignal(SIGTTIN, SIG_IGN); /* ignored */
pqsignal(SIGTTOU, SIG_IGN); /* ignored */
pqsignal(SIGWINCH, dumpstatus); /* dump port status */
status = ServerLoop(); status = ServerLoop();
...@@ -980,6 +989,52 @@ reset_shared(short port) ...@@ -980,6 +989,52 @@ reset_shared(short port)
static void static void
pmdie(SIGNAL_ARGS) pmdie(SIGNAL_ARGS)
{ {
int i;
TPRINTF(TRACE_VERBOSE, "pmdie %d", postgres_signal_arg);
/*
* Kill self and/or children processes depending on signal number.
*/
switch (postgres_signal_arg) {
case SIGHUP:
/* Send SIGHUP to all children (update options flags) */
SignalChildren(SIGHUP);
/* Don't die */
return;
case SIGINT:
/* Die without killing children */
break;
case SIGQUIT:
/* Shutdown all children with SIGTERM */
SignalChildren(SIGTERM);
/* Don't die */
return;
case SIGTERM:
/* Shutdown all children with SIGTERM and SIGKILL, then die */
SignalChildren(SIGTERM);
for (i=0; i<10; i++) {
if (!DLGetHead(BackendList)) {
break;
}
sleep(1);
}
if (DLGetHead(BackendList)) {
SignalChildren(SIGKILL);
}
break;
case SIGUSR1:
/* Quick die all children with SIGUSR1 and die */
SignalChildren(SIGUSR1);
break;
case SIGUSR2:
/* Send SIGUSR2 to all children (AsyncNotifyHandler) */
SignalChildren(SIGUSR2);
/* Don't die */
return;
}
/* exit postmaster */
proc_exit(0); proc_exit(0);
} }
...@@ -1122,6 +1177,35 @@ CleanupProc(int pid, ...@@ -1122,6 +1177,35 @@ CleanupProc(int pid,
} }
} }
/*
* Send a signal to all chidren processes.
*/
static void
SignalChildren(int signal)
{
Dlelem *curr,
*next;
Backend *bp;
int mypid = getpid();
curr = DLGetHead(BackendList);
while (curr)
{
next = DLGetSucc(curr);
bp = (Backend *) DLE_VAL(curr);
if (bp->pid != mypid)
{
TPRINTF(TRACE_VERBOSE,
"SignalChildren: sending signal %d to process %d",
signal, bp->pid);
kill(bp->pid, signal);
}
curr = next;
}
}
/* /*
* BackendStartup -- start backend process * BackendStartup -- start backend process
* *
...@@ -1342,6 +1426,9 @@ DoBackend(Port *port) ...@@ -1342,6 +1426,9 @@ DoBackend(Port *port)
StreamClose(ServerSock_INET); StreamClose(ServerSock_INET);
StreamClose(ServerSock_UNIX); StreamClose(ServerSock_UNIX);
/* Save port for ps status */
MyProcPort = port;
/* /*
* Don't want backend to be able to see the postmaster random number * Don't want backend to be able to see the postmaster random number
* generator state. We have to clobber the static random_seed *and* * generator state. We have to clobber the static random_seed *and*
...@@ -1368,7 +1455,13 @@ DoBackend(Port *port) ...@@ -1368,7 +1455,13 @@ DoBackend(Port *port)
* a big win. * a big win.
*/ */
#ifndef linux
/*
* This doesn't work on linux and overwrites the only valid
* pointer to the argv buffer. See PS_INIT_STATUS macro.
*/
real_argv[0] = Execfile; real_argv[0] = Execfile;
#endif
/* Tell the backend it is being called from the postmaster */ /* Tell the backend it is being called from the postmaster */
av[ac++] = "-p"; av[ac++] = "-p";
...@@ -1386,8 +1479,6 @@ DoBackend(Port *port) ...@@ -1386,8 +1479,6 @@ DoBackend(Port *port)
sprintf(debugbuf, "-d%d", DebugLvl); sprintf(debugbuf, "-d%d", DebugLvl);
av[ac++] = debugbuf; av[ac++] = debugbuf;
} }
else
av[ac++] = "-Q";
/* Pass the requested debugging output file */ /* Pass the requested debugging output file */
if (port->tty[0]) if (port->tty[0])
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipc.c,v 1.30 1998/07/12 04:43:28 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipc.c,v 1.31 1998/08/25 21:34:01 scrappy Exp $
* *
* NOTES * NOTES
* *
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <sys/shm.h> #include <sys/shm.h>
#include "utils/memutils.h" #include "utils/memutils.h"
#include "libpq/libpq.h" #include "libpq/libpq.h"
#include "utils/trace.h"
#if defined(solaris_sparc) #if defined(solaris_sparc)
#include <string.h> #include <string.h>
...@@ -113,17 +114,26 @@ proc_exit(int code) ...@@ -113,17 +114,26 @@ proc_exit(int code)
{ {
int i; int i;
TPRINTF(TRACE_VERBOSE, "proc_exit(%d) [#%d]", code, proc_exit_inprogress);
/*
* If proc_exit is called too many times something bad is
* happenig, so exit immediately.
*/
if (proc_exit_inprogress > 9) {
elog(ERROR, "infinite recursion in proc_exit");
goto exit;
}
/* ---------------- /* ----------------
* if proc_exit_inprocess is true, then it means that we * if proc_exit_inprocess is true, then it means that we
* are being invoked from within an on_exit() handler * are being invoked from within an on_exit() handler
* and so we return immediately to avoid recursion. * and so we return immediately to avoid recursion.
* ---------------- * ----------------
*/ */
if (proc_exit_inprogress) if (proc_exit_inprogress++)
return; return;
proc_exit_inprogress = 1;
/* do our shared memory exits first */ /* do our shared memory exits first */
shmem_exit(code); shmem_exit(code);
...@@ -134,6 +144,8 @@ proc_exit(int code) ...@@ -134,6 +144,8 @@ proc_exit(int code)
for (i = on_proc_exit_index - 1; i >= 0; --i) for (i = on_proc_exit_index - 1; i >= 0; --i)
(*on_proc_exit_list[i].function) (code, on_proc_exit_list[i].arg); (*on_proc_exit_list[i].function) (code, on_proc_exit_list[i].arg);
exit:
TPRINTF(TRACE_VERBOSE, "exit(%d)", code);
exit(code); exit(code);
} }
...@@ -150,17 +162,27 @@ shmem_exit(int code) ...@@ -150,17 +162,27 @@ shmem_exit(int code)
{ {
int i; int i;
TPRINTF(TRACE_VERBOSE, "shmem_exit(%d) [#%d]",
code, shmem_exit_inprogress);
/*
* If shmem_exit is called too many times something bad is
* happenig, so exit immediately.
*/
if (shmem_exit_inprogress > 9) {
elog(ERROR, "infinite recursion in shmem_exit");
exit(-1);
}
/* ---------------- /* ----------------
* if shmem_exit_inprocess is true, then it means that we * if shmem_exit_inprocess is true, then it means that we
* are being invoked from within an on_exit() handler * are being invoked from within an on_exit() handler
* and so we return immediately to avoid recursion. * and so we return immediately to avoid recursion.
* ---------------- * ----------------
*/ */
if (shmem_exit_inprogress) if (shmem_exit_inprogress++)
return; return;
shmem_exit_inprogress = 1;
/* ---------------- /* ----------------
* call all the callbacks registered before calling exit(). * call all the callbacks registered before calling exit().
* ---------------- * ----------------
...@@ -315,7 +337,7 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey, ...@@ -315,7 +337,7 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey,
{ {
*status = IpcSemIdNotExist; /* there doesn't exist a semaphore */ *status = IpcSemIdNotExist; /* there doesn't exist a semaphore */
#ifdef DEBUG_IPC #ifdef DEBUG_IPC
fprintf(stderr, "calling semget with %d, %d , %d\n", EPRINTF("calling semget with %d, %d , %d\n",
semKey, semKey,
semNum, semNum,
IPC_CREAT | permission); IPC_CREAT | permission);
...@@ -324,8 +346,9 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey, ...@@ -324,8 +346,9 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey,
if (semId < 0) if (semId < 0)
{ {
perror("semget"); EPRINTF("IpcSemaphoreCreate: semget failed (%s) "
IpcConfigTip(); "key=%d, num=%d, permission=%o",
strerror(errno), semKey, semNum, permission);
proc_exit(3); proc_exit(3);
} }
for (i = 0; i < semNum; i++) for (i = 0; i < semNum; i++)
...@@ -334,8 +357,8 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey, ...@@ -334,8 +357,8 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey,
errStatus = semctl(semId, 0, SETALL, semun); errStatus = semctl(semId, 0, SETALL, semun);
if (errStatus == -1) if (errStatus == -1)
{ {
perror("semctl"); EPRINTF("IpcSemaphoreCreate: semctl failed (%s) id=%d",
IpcConfigTip(); strerror(errno), semId);
} }
if (removeOnExit) if (removeOnExit)
...@@ -349,7 +372,7 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey, ...@@ -349,7 +372,7 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey,
} }
#ifdef DEBUG_IPC #ifdef DEBUG_IPC
fprintf(stderr, "\nIpcSemaphoreCreate, status %d, returns %d\n", EPRINTF("\nIpcSemaphoreCreate, status %d, returns %d\n",
*status, *status,
semId); semId);
fflush(stdout); fflush(stdout);
...@@ -379,8 +402,8 @@ IpcSemaphoreSet(int semId, int semno, int value) ...@@ -379,8 +402,8 @@ IpcSemaphoreSet(int semId, int semno, int value)
if (errStatus == -1) if (errStatus == -1)
{ {
perror("semctl"); EPRINTF("IpcSemaphoreSet: semctl failed (%s) id=%d",
IpcConfigTip(); strerror(errno), semId);
} }
} }
...@@ -441,8 +464,8 @@ IpcSemaphoreLock(IpcSemaphoreId semId, int sem, int lock) ...@@ -441,8 +464,8 @@ IpcSemaphoreLock(IpcSemaphoreId semId, int sem, int lock)
if (errStatus == -1) if (errStatus == -1)
{ {
perror("semop"); EPRINTF("IpcSemaphoreLock: semop failed (%s) id=%d",
IpcConfigTip(); strerror(errno), semId);
proc_exit(255); proc_exit(255);
} }
} }
...@@ -486,8 +509,8 @@ IpcSemaphoreUnlock(IpcSemaphoreId semId, int sem, int lock) ...@@ -486,8 +509,8 @@ IpcSemaphoreUnlock(IpcSemaphoreId semId, int sem, int lock)
if (errStatus == -1) if (errStatus == -1)
{ {
perror("semop"); EPRINTF("IpcSemaphoreUnlock: semop failed (%s) id=%d",
IpcConfigTip(); strerror(errno), semId);
proc_exit(255); proc_exit(255);
} }
} }
...@@ -534,10 +557,9 @@ IpcMemoryCreate(IpcMemoryKey memKey, uint32 size, int permission) ...@@ -534,10 +557,9 @@ IpcMemoryCreate(IpcMemoryKey memKey, uint32 size, int permission)
if (shmid < 0) if (shmid < 0)
{ {
fprintf(stderr, "IpcMemoryCreate: memKey=%d , size=%d , permission=%d", EPRINTF("IpcMemoryCreate: shmget failed (%s) "
memKey, size, permission); "key=%d, size=%d, permission=%o",
perror("IpcMemoryCreate: shmget(..., create, ...) failed"); strerror(errno), memKey, size, permission);
IpcConfigTip();
return (IpcMemCreationFailed); return (IpcMemCreationFailed);
} }
...@@ -560,10 +582,9 @@ IpcMemoryIdGet(IpcMemoryKey memKey, uint32 size) ...@@ -560,10 +582,9 @@ IpcMemoryIdGet(IpcMemoryKey memKey, uint32 size)
if (shmid < 0) if (shmid < 0)
{ {
fprintf(stderr, "IpcMemoryIdGet: memKey=%d , size=%d , permission=%d", EPRINTF("IpcMemoryIdGet: shmget failed (%s) "
memKey, size, 0); "key=%d, size=%d, permission=%o",
perror("IpcMemoryIdGet: shmget() failed"); strerror(errno), memKey, size, 0);
IpcConfigTip();
return (IpcMemIdGetFailed); return (IpcMemIdGetFailed);
} }
...@@ -602,8 +623,8 @@ IpcMemoryAttach(IpcMemoryId memId) ...@@ -602,8 +623,8 @@ IpcMemoryAttach(IpcMemoryId memId)
/* if ( *memAddress == -1) { XXX ??? */ /* if ( *memAddress == -1) { XXX ??? */
if (memAddress == (char *) -1) if (memAddress == (char *) -1)
{ {
perror("IpcMemoryAttach: shmat() failed"); EPRINTF("IpcMemoryAttach: shmat failed (%s) id=%d",
IpcConfigTip(); strerror(errno), memId);
return (IpcMemAttachFailed); return (IpcMemAttachFailed);
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/Attic/spin.c,v 1.14 1998/06/27 15:47:45 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/ipc/Attic/spin.c,v 1.15 1998/08/25 21:34:03 scrappy Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "storage/shmem.h" #include "storage/shmem.h"
#include "storage/spin.h" #include "storage/spin.h"
#include "storage/proc.h" #include "storage/proc.h"
#include "utils/trace.h"
#ifndef HAS_TEST_AND_SET #ifndef HAS_TEST_AND_SET
#include <sys/sem.h> #include <sys/sem.h>
...@@ -81,10 +82,12 @@ InitSpinLocks(int init, IPCKey key) ...@@ -81,10 +82,12 @@ InitSpinLocks(int init, IPCKey key)
} }
#ifdef LOCKDEBUG #ifdef LOCKDEBUG
#define PRINT_LOCK(LOCK) printf("(locklock = %d, flag = %d, nshlocks = %d, \ #define PRINT_LOCK(LOCK) \
shlock = %d, exlock =%d)\n", LOCK->locklock, \ TPRINTF(TRACE_SPINLOCKS, \
LOCK->flag, LOCK->nshlocks, LOCK->shlock, \ "(locklock = %d, flag = %d, nshlocks = %d, shlock = %d, " \
LOCK->exlock) "exlock =%d)\n", LOCK->locklock, \
LOCK->flag, LOCK->nshlocks, LOCK->shlock, \
LOCK->exlock)
#endif #endif
/* from ipc.c */ /* from ipc.c */
...@@ -98,8 +101,7 @@ SpinAcquire(SPINLOCK lockid) ...@@ -98,8 +101,7 @@ SpinAcquire(SPINLOCK lockid)
/* This used to be in ipc.c, but move here to reduce function calls */ /* This used to be in ipc.c, but move here to reduce function calls */
slckP = &(SLockArray[lockid]); slckP = &(SLockArray[lockid]);
#ifdef LOCKDEBUG #ifdef LOCKDEBUG
printf("SpinAcquire(%d)\n", lockid); TPRINTF(TRACE_SPINLOCKS, "SpinAcquire: %d", lockid);
printf("IN: ");
PRINT_LOCK(slckP); PRINT_LOCK(slckP);
#endif #endif
ex_try_again: ex_try_again:
...@@ -112,7 +114,7 @@ ex_try_again: ...@@ -112,7 +114,7 @@ ex_try_again:
S_LOCK(&(slckP->shlock)); S_LOCK(&(slckP->shlock));
S_UNLOCK(&(slckP->locklock)); S_UNLOCK(&(slckP->locklock));
#ifdef LOCKDEBUG #ifdef LOCKDEBUG
printf("OUT: "); TPRINTF(TRACE_SPINLOCKS, "OUT: ");
PRINT_LOCK(slckP); PRINT_LOCK(slckP);
#endif #endif
break; break;
...@@ -124,6 +126,9 @@ ex_try_again: ...@@ -124,6 +126,9 @@ ex_try_again:
goto ex_try_again; goto ex_try_again;
} }
PROC_INCR_SLOCK(lockid); PROC_INCR_SLOCK(lockid);
#ifdef LOCKDEBUG
TPRINTF(TRACE_SPINLOCKS, "SpinAcquire: got %d", lockid);
#endif
} }
void void
...@@ -131,13 +136,23 @@ SpinRelease(SPINLOCK lockid) ...@@ -131,13 +136,23 @@ SpinRelease(SPINLOCK lockid)
{ {
SLock *slckP; SLock *slckP;
PROC_DECR_SLOCK(lockid);
/* This used to be in ipc.c, but move here to reduce function calls */ /* This used to be in ipc.c, but move here to reduce function calls */
slckP = &(SLockArray[lockid]); slckP = &(SLockArray[lockid]);
#ifdef USE_ASSERT_CHECKING
/*
* Check that we are actually holding the lock we are releasing.
* This can be done only after MyProc has been initialized.
*/
if (MyProc)
Assert(MyProc->sLocks[lockid] > 0);
Assert(slckP->flag != NOLOCK);
#endif
PROC_DECR_SLOCK(lockid);
#ifdef LOCKDEBUG #ifdef LOCKDEBUG
printf("SpinRelease(%d)\n", lockid); TPRINTF("SpinRelease: %d\n", lockid);
printf("IN: ");
PRINT_LOCK(slckP); PRINT_LOCK(slckP);
#endif #endif
S_LOCK(&(slckP->locklock)); S_LOCK(&(slckP->locklock));
...@@ -160,7 +175,7 @@ SpinRelease(SPINLOCK lockid) ...@@ -160,7 +175,7 @@ SpinRelease(SPINLOCK lockid)
S_UNLOCK(&(slckP->exlock)); S_UNLOCK(&(slckP->exlock));
S_UNLOCK(&(slckP->locklock)); S_UNLOCK(&(slckP->locklock));
#ifdef LOCKDEBUG #ifdef LOCKDEBUG
printf("OUT: "); TPRINTF(TRACE_SPINLOCKS, "SpinRelease: released %d", lockid);
PRINT_LOCK(slckP); PRINT_LOCK(slckP);
#endif #endif
} }
......
This diff is collapsed.
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/error/assert.c,v 1.9 1998/06/18 16:35:38 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/error/assert.c,v 1.10 1998/08/25 21:34:06 scrappy Exp $
* *
* NOTE * NOTE
* This should eventually work with elog(), dlog(), etc. * This should eventually work with elog(), dlog(), etc.
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "utils/module.h" #include "utils/module.h"
#include "utils/exc.h" #include "utils/exc.h"
#include "utils/trace.h"
int int
ExceptionalCondition(char *conditionName, ExceptionalCondition(char *conditionName,
...@@ -39,7 +40,7 @@ ExceptionalCondition(char *conditionName, ...@@ -39,7 +40,7 @@ ExceptionalCondition(char *conditionName,
|| !PointerIsValid(fileName) || !PointerIsValid(fileName)
|| !PointerIsValid(exceptionP)) || !PointerIsValid(exceptionP))
{ {
fprintf(stderr, "ExceptionalCondition: bad arguments\n"); EPRINTF("TRAP: ExceptionalCondition: bad arguments\n");
ExcAbort(exceptionP, ExcAbort(exceptionP,
(ExcDetail) detail, (ExcDetail) detail,
...@@ -48,9 +49,9 @@ ExceptionalCondition(char *conditionName, ...@@ -48,9 +49,9 @@ ExceptionalCondition(char *conditionName,
} }
else else
{ {
fprintf(stderr, EPRINTF("TRAP: %s(\"%s:%s\", File: \"%s\", Line: %d)\n",
"%s(\"%s:%s\", File: \"%s\", Line: %d)\n", exceptionP->message, conditionName,
exceptionP->message, conditionName, detail == NULL ? "" : detail, (detail == NULL ? "" : detail),
fileName, lineNumber); fileName, lineNumber);
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.31 1998/07/07 22:00:31 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.32 1998/08/25 21:34:08 scrappy Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -24,10 +24,29 @@ ...@@ -24,10 +24,29 @@
#include <unistd.h> #include <unistd.h>
#include <signal.h> #include <signal.h>
#ifdef USE_SYSLOG
#include <syslog.h>
#endif
#include "postgres.h" #include "postgres.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "libpq/libpq.h" #include "libpq/libpq.h"
#include "storage/proc.h" #include "storage/proc.h"
#include "utils/trace.h"
#ifdef USE_SYSLOG
/*
* Global option to control the use of syslog(3) for logging:
*
* 0 stdout/stderr only
* 1 stdout/stderr + syslog
* 2 syslog only
*/
#define UseSyslog pg_options[OPT_SYSLOG]
#define PG_LOG_FACILITY LOG_LOCAL0
#else
#define UseSyslog 0
#endif
static int Debugfile = -1; static int Debugfile = -1;
static int Err_file = -1; static int Err_file = -1;
...@@ -52,12 +71,12 @@ elog(int lev, const char *fmt,...) ...@@ -52,12 +71,12 @@ elog(int lev, const char *fmt,...)
#ifndef PG_STANDALONE #ifndef PG_STANDALONE
extern FILE *Pfout; extern FILE *Pfout;
#endif
#endif /* !PG_STANDALONE */ #ifdef USE_SYSLOG
#ifdef ELOG_TIMESTAMPS int log_level;
time_t tim;
#endif #endif
int len; int len;
int i = 0; int i = 0;
...@@ -72,7 +91,7 @@ elog(int lev, const char *fmt,...) ...@@ -72,7 +91,7 @@ elog(int lev, const char *fmt,...)
i = 0; i = 0;
if (i > 30) if (i > 30)
i = i % 30; i = i % 30;
cp = "DEBUG: "; cp = "DEBUG: ";
break; break;
case DEBUG: case DEBUG:
i = ElogDebugIndentLevel; i = ElogDebugIndentLevel;
...@@ -80,27 +99,25 @@ elog(int lev, const char *fmt,...) ...@@ -80,27 +99,25 @@ elog(int lev, const char *fmt,...)
i = 0; i = 0;
if (i > 30) if (i > 30)
i = i % 30; i = i % 30;
cp = "DEBUG: "; cp = "DEBUG: ";
break; break;
case NOTICE: case NOTICE:
cp = "NOTICE: "; cp = "NOTICE: ";
break; break;
case ERROR: case ERROR:
cp = "ERROR: "; cp = "ERROR: ";
break; break;
default: default:
sprintf(line, "FATAL %d: ", lev); sprintf(line, "FATAL %d: ", lev);
cp = line; cp = line;
} }
#ifdef ELOG_TIMESTAMPS #ifdef ELOG_TIMESTAMPS
time(&tim); strcpy(buf, tprintf_timestamp());
strcat(strcpy(buf, cp), ctime(&tim) + 4); strcat(buf, cp);
bp = buf + strlen(buf) - 6;
*bp++ = ':';
#else #else
strcpy(buf, cp); strcpy(buf, cp);
bp = buf + strlen(buf);
#endif #endif
bp = buf + strlen(buf);
while (i-- > 0) while (i-- > 0)
*bp++ = ' '; *bp++ = ' ';
for (cp = fmt; *cp; cp++) for (cp = fmt; *cp; cp++)
...@@ -118,8 +135,31 @@ elog(int lev, const char *fmt,...) ...@@ -118,8 +135,31 @@ elog(int lev, const char *fmt,...)
*bp = '\0'; *bp = '\0';
vsprintf(line, buf, ap); vsprintf(line, buf, ap);
va_end(ap); va_end(ap);
#ifdef USE_SYSLOG
switch (lev) {
case NOIND:
log_level = LOG_DEBUG;
break;
case DEBUG:
log_level = LOG_DEBUG;
break;
case NOTICE:
log_level = LOG_NOTICE;
break;
case ERROR:
log_level = LOG_WARNING;
break;
case FATAL:
default:
log_level = LOG_ERR;
break;
}
write_syslog(log_level, line+TIMESTAMP_SIZE);
#endif
len = strlen(strcat(line, "\n")); len = strlen(strcat(line, "\n"));
if (Debugfile > -1) if ((Debugfile > -1) && (UseSyslog <= 1))
write(Debugfile, line, len); write(Debugfile, line, len);
if (lev == DEBUG || lev == NOIND) if (lev == DEBUG || lev == NOIND)
return; return;
...@@ -135,7 +175,7 @@ elog(int lev, const char *fmt,...) ...@@ -135,7 +175,7 @@ elog(int lev, const char *fmt,...)
* log. This is a major pain. * log. This is a major pain.
*/ */
if (Err_file > -1 && Debugfile != Err_file) if (Err_file > -1 && Debugfile != Err_file && (UseSyslog <= 1))
{ {
if (write(Err_file, line, len) < 0) if (write(Err_file, line, len) < 0)
{ {
...@@ -157,7 +197,7 @@ elog(int lev, const char *fmt,...) ...@@ -157,7 +197,7 @@ elog(int lev, const char *fmt,...)
else else
pq_putnchar("E", 1); pq_putnchar("E", 1);
/* pq_putint(-101, 4); *//* should be query id */ /* pq_putint(-101, 4); *//* should be query id */
pq_putstr(line); pq_putstr(line+TIMESTAMP_SIZE); /* don't show timestamps */
pq_flush(); pq_flush();
} }
if (Pfout == NULL) if (Pfout == NULL)
...@@ -178,7 +218,7 @@ elog(int lev, const char *fmt,...) ...@@ -178,7 +218,7 @@ elog(int lev, const char *fmt,...)
ProcReleaseSpins(NULL); /* get rid of spinlocks we hold */ ProcReleaseSpins(NULL); /* get rid of spinlocks we hold */
if (!InError) if (!InError)
{ {
kill(MyProcPid, SIGHUP); /* abort to traffic cop */ kill(MyProcPid, SIGQUIT); /* abort to traffic cop */
pause(); pause();
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# Makefile for utils/misc # Makefile for utils/misc
# #
# IDENTIFICATION # IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/utils/misc/Makefile,v 1.8 1998/07/26 04:31:06 scrappy Exp $ # $Header: /cvsroot/pgsql/src/backend/utils/misc/Makefile,v 1.9 1998/08/25 21:34:10 scrappy Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -17,7 +17,7 @@ ifdef MULTIBYTE ...@@ -17,7 +17,7 @@ ifdef MULTIBYTE
CFLAGS+= $(MBFLAGS) CFLAGS+= $(MBFLAGS)
endif endif
OBJS = database.o superuser.o OBJS = database.o superuser.o trace.o
all: SUBSYS.o all: SUBSYS.o
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment