Header And Logo

PostgreSQL
| The world's most advanced open source database.

assert.c

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * assert.c
00004  *    Assert code.
00005  *
00006  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00007  * Portions Copyright (c) 1994, Regents of the University of California
00008  *
00009  *
00010  * IDENTIFICATION
00011  *    src/backend/utils/error/assert.c
00012  *
00013  * NOTE
00014  *    This should eventually work with elog()
00015  *
00016  *-------------------------------------------------------------------------
00017  */
00018 #include "postgres.h"
00019 
00020 #include <unistd.h>
00021 
00022 /*
00023  * ExceptionalCondition - Handles the failure of an Assert()
00024  */
00025 void
00026 ExceptionalCondition(const char *conditionName,
00027                      const char *errorType,
00028                      const char *fileName,
00029                      int lineNumber)
00030 {
00031     if (!PointerIsValid(conditionName)
00032         || !PointerIsValid(fileName)
00033         || !PointerIsValid(errorType))
00034         write_stderr("TRAP: ExceptionalCondition: bad arguments\n");
00035     else
00036     {
00037         write_stderr("TRAP: %s(\"%s\", File: \"%s\", Line: %d)\n",
00038                      errorType, conditionName,
00039                      fileName, lineNumber);
00040     }
00041 
00042     /* Usually this shouldn't be needed, but make sure the msg went out */
00043     fflush(stderr);
00044 
00045 #ifdef SLEEP_ON_ASSERT
00046 
00047     /*
00048      * It would be nice to use pg_usleep() here, but only does 2000 sec or 33
00049      * minutes, which seems too short.
00050      */
00051     sleep(1000000);
00052 #endif
00053 
00054     abort();
00055 }