head	1.7;
access;
symbols
	release_4_2:1.7
	aix_ok:1.7
	Version_2_1:1.7
	C_Demo_1:1.5;
locks; strict;
comment	@ * @;


1.7
date	90.09.25.16.51.41;	author kemnitz;	state Exp;
branches;
next	1.6;

1.6
date	90.02.12.19.50.56;	author cimarron;	state Exp;
branches;
next	1.5;

1.5
date	89.09.05.17.27.40;	author mao;	state C_Demo_1;
branches;
next	1.4;

1.4
date	89.06.22.22.35.58;	author hirohama;	state Exp;
branches;
next	1.3;

1.3
date	89.05.23.16.56.04;	author hirohama;	state Exp;
branches;
next	1.2;

1.2
date	89.05.03.17.46.57;	author hirohama;	state Exp;
branches;
next	1.1;

1.1
date	89.05.01.14.08.07;	author hirohama;	state Exp;
branches;
next	;


desc
@@


1.7
log
@Updating from revision 1.6 to revision 1.7
@
text
@/*
 * exc.c --
 *	POSTGRES exception handling code.
 *
 * Note:
 *	XXX this code needs improvement--check for state violations and
 *	XXX reset after handling an exception.
 */

#include <stdio.h>	/* XXX use own I/O routines */

#include "tmp/c.h"
#include "utils/exc.h"

RcsId("$Header: RCS/exc.c,v 1.7 90/08/15 08:47:36 cimarron Exp $");

/*
 * Global Variables
 */
static bool ExceptionHandlingEnabled = false;

String			ExcFileName = NULL;
Index			ExcLineNumber = 0;

ExcFrame		*ExcCurFrameP = NULL;

static	ExcProc		*ExcUnCaughtP = NULL;

/*
 * Exported Functions
 */

/*
 * Excection handling should be supported by the language, thus there should
 * be no need to explicitly enable exception processing.
 *
 * This function should probably not be called, ever.  Currently it does
 * almost nothing.  If there is a need for this intialization and checking.
 * then this function should be converted to the new-style Enable code and
 * called by all the other module Enable functions.
 */
void
EnableExceptionHandling(on)
	bool	on;
{
	if (on == ExceptionHandlingEnabled) {
		/* XXX add logging of failed state */
		exitpg(255);
		/* ExitPostgres(FatalExitStatus); */
	}

	if (on) {	/* initialize */
		;
	} else {	/* cleanup */
		ExcFileName = NULL;
		ExcLineNumber = 0;
		ExcCurFrameP = NULL;
		ExcUnCaughtP = NULL;
	}

	ExceptionHandlingEnabled = on;
}

void
ExcPrint(excP, detail, data, message)
	Exception	*excP;
	ExcDetail	detail;
	ExcData		data;
	ExcMessage	message;
{
	extern	int	errno;
	extern	int	sys_nerr;
	extern	char	*sys_errlist[];

#ifdef	lint
	data = data;
#endif

	(void) fflush(stdout);	/* In case stderr is buffered */

#if	0
	if (ProgramName != NULL && *ProgramName != '\0')
		(void) fprintf(stderr, "%s: ", ProgramName);
#endif

	if (message != NULL)
		(void) fprintf(stderr, "%s", message);
	else if (excP->message != NULL)
		(void) fprintf(stderr, "%s", excP->message);
	else
#ifdef	lint
		(void) fprintf(stderr, "UNNAMED EXCEPTION 0x%lx", excP);
#else
		(void) fprintf(stderr, "UNNAMED EXCEPTION 0x%lx", (long)excP);
#endif

	(void) fprintf(stderr, " (%ld)", detail);

	if (errno > 0 && errno < sys_nerr &&
	    sys_errlist[errno] != NULL && sys_errlist[errno][0] != '\0')
		(void) fprintf(stderr, " [%s]", sys_errlist[errno]);
	else if (errno != 0)
		(void) fprintf(stderr, " [Error %d]", errno);

	(void) fprintf(stderr, "\n");

	(void) fflush(stderr);
}

ExcProc *
ExcGetUnCaught()
{
	return (ExcUnCaughtP);
}

ExcProc *
ExcSetUnCaught(newP)
	ExcProc	*newP;
{
	ExcProc	*oldP = ExcUnCaughtP;

	ExcUnCaughtP = newP;

	return (oldP);
}

void
ExcUnCaught(excP, detail, data, message)
	Exception	*excP;
	ExcDetail	detail;
	ExcData		data;
	ExcMessage	message;
{
	ExcPrint(excP, detail, data, message);

	ExcAbort(excP, detail, data, message);
	/*NOTREACHED*/
}

void
ExcRaise(excP, detail, data, message)
	Exception	*excP;
	ExcDetail	detail;
	ExcData		data;
	ExcMessage	message;
{
	register ExcFrame	*efp;

	efp = ExcCurFrameP;
	if (efp == NULL) {
		if (ExcUnCaughtP != NULL)
			(*ExcUnCaughtP)(excP, detail, data, message);

		ExcUnCaught(excP, detail, data, message);
		/*NOTREACHED*/
	} else {
		efp->id		= excP;
		efp->detail	= detail;
		efp->data	= data;
		efp->message	= message;

		ExcCurFrameP = efp->link;

		longjmp(efp->context, 1);
		/*NOTREACHED*/
	}
	/*NOTREACHED*/
}
@


1.6
log
@added buffer manager statistics and exitpg() stuff -cim
@
text
@d12 2
a13 1
#include "c.h"
d15 1
a15 3
#include "exc.h"

RcsId("$Header: RCS/exc.c,v 1.5 89/09/05 17:27:40 mao C_Demo_1 $");
@


1.5
log
@Working version of C-only demo
@
text
@d16 1
a16 1
RcsId("$Header: /usr6/postgres/mao/postgres/src/utils/error/RCS/exc.c,v 1.4 89/06/22 22:35:58 hirohama Exp $");
d49 1
a49 1
		exit(255);
@


1.4
log
@removed references to utils/init/pinit.c; no more ExitPostgres/AbortPostgres
@
text
@d16 1
a16 1
RcsId("$Header: exc.c,v 1.3 89/05/23 16:56:04 hirohama Locked $");
@


1.3
log
@added a comment
@
text
@a13 2
#include "pinit.h"	/* for ExitPostgres */

d16 1
a16 1
RcsId("$Header: exc.c,v 1.2 89/05/03 17:46:57 hirohama Locked $");
d49 2
a50 1
		ExitPostgres(FatalExitStatus);
a108 11
}

/*ARGSUSED*/
void
ExcAbort(excP, detail, data, message)
	Exception	*excP;
	ExcDetail	detail;
	ExcData		data;
	ExcMessage	message;
{
	AbortPostgres();
@


1.2
log
@changed interface
@
text
@d18 1
a18 1
RcsId("$Header: exc.c,v 1.1 89/05/01 14:08:07 hirohama Locked $");
d36 9
@


1.1
log
@Initial revision
@
text
@d4 4
d18 1
a18 1
RcsId("$Header$");
d23 1
d37 2
a38 2
InitExceptionHandling(firstTime)
	bool	firstTime;
d40 2
a41 3
	static bool	called = false;

	if (firstTime == called) {
d45 1
a45 4
	called = true;

	if (firstTime) {
		/* initialize */
d47 1
a47 3
	} else {
		/* do deallocations and cleanup */
		/* reinitialize */
d53 2
@
