Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 18c170a

Browse files
committed
Include the process PID in assertion-failure messages.
This should help to identify what happened when studying the postmaster log after-the-fact. While here, clean up some old comments in the same function. Discussion: https://postgr.es/m/1568983.1601845687@sss.pgh.pa.us
1 parent 53c6daf commit 18c170a

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/backend/utils/error/assert.c

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*-------------------------------------------------------------------------
22
*
33
* assert.c
4-
* Assert code.
4+
* Assert support code.
55
*
66
* Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
@@ -10,9 +10,6 @@
1010
* IDENTIFICATION
1111
* src/backend/utils/error/assert.c
1212
*
13-
* NOTE
14-
* This should eventually work with elog()
15-
*
1613
*-------------------------------------------------------------------------
1714
*/
1815
#include "postgres.h"
@@ -24,27 +21,32 @@
2421

2522
/*
2623
* ExceptionalCondition - Handles the failure of an Assert()
24+
*
25+
* We intentionally do not go through elog() here, on the grounds of
26+
* wanting to minimize the amount of infrastructure that has to be
27+
* working to report an assertion failure.
2728
*/
2829
void
2930
ExceptionalCondition(const char *conditionName,
3031
const char *errorType,
3132
const char *fileName,
3233
int lineNumber)
3334
{
35+
/* Report the failure on stderr (or local equivalent) */
3436
if (!PointerIsValid(conditionName)
3537
|| !PointerIsValid(fileName)
3638
|| !PointerIsValid(errorType))
37-
write_stderr("TRAP: ExceptionalCondition: bad arguments\n");
39+
write_stderr("TRAP: ExceptionalCondition: bad arguments in PID %d\n",
40+
(int) getpid());
3841
else
39-
{
40-
write_stderr("TRAP: %s(\"%s\", File: \"%s\", Line: %d)\n",
42+
write_stderr("TRAP: %s(\"%s\", File: \"%s\", Line: %d, PID: %d)\n",
4143
errorType, conditionName,
42-
fileName, lineNumber);
43-
}
44+
fileName, lineNumber, (int) getpid());
4445

4546
/* Usually this shouldn't be needed, but make sure the msg went out */
4647
fflush(stderr);
4748

49+
/* If we have support for it, dump a simple backtrace */
4850
#ifdef HAVE_BACKTRACE_SYMBOLS
4951
{
5052
void *buf[100];
@@ -55,12 +57,12 @@ ExceptionalCondition(const char *conditionName,
5557
}
5658
#endif
5759

58-
#ifdef SLEEP_ON_ASSERT
59-
6060
/*
61-
* It would be nice to use pg_usleep() here, but only does 2000 sec or 33
62-
* minutes, which seems too short.
61+
* If configured to do so, sleep indefinitely to allow user to attach a
62+
* debugger. It would be nice to use pg_usleep() here, but that can sleep
63+
* at most 2G usec or ~33 minutes, which seems too short.
6364
*/
65+
#ifdef SLEEP_ON_ASSERT
6466
sleep(1000000);
6567
#endif
6668

0 commit comments

Comments
 (0)