diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2007-07-21 22:12:38 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2007-07-21 22:12:38 +0000 |
| commit | 681690f4e374d88877ea2f4de1baa04f780abd8e (patch) | |
| tree | aa8c99f9e996226746f4737973811a9086eddc69 /src/backend/utils/error/elog.c | |
| parent | c556447c70c937e5910fbbbc9653adc22c42a5ee (diff) | |
Fix elog.c to avoid infinite recursion (leading to backend crash) when
log_min_error_statement is active and there is some problem in logging the
current query string; for example, that it's too long to include in the log
message without running out of memory. This problem has existed since the
log_min_error_statement feature was introduced. No doubt the reason it
wasn't detected long ago is that 8.2 is the first release that defaults
log_min_error_statement to less than PANIC level.
Per report from Bill Moran.
Diffstat (limited to 'src/backend/utils/error/elog.c')
| -rw-r--r-- | src/backend/utils/error/elog.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index b2b431a984e..513288cd08b 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.104.2.1 2005/10/14 16:41:41 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.104.2.2 2007/07/21 22:12:38 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -429,13 +429,18 @@ elog(int lev, const char *fmt,...) free(msg_buf); /* - * If the user wants this elog() generating query logged, do so. We - * only want to log if the query has been written to - * debug_query_string. Also, avoid infinite loops. + * If the user wants this elog() generating query logged, do so. + * To avoid possible infinite recursion, temporarily clear + * debug_query_string while recursing. */ + if (lev >= log_min_error_statement && debug_query_string) + { + char *q_str = debug_query_string; - if (lev != LOG && lev >= log_min_error_statement && debug_query_string) - elog(LOG, "statement: %s", debug_query_string); + debug_query_string = NULL; + elog(LOG, "statement: %s", q_str); + debug_query_string = q_str; + } /* * Perform error recovery action as specified by lev. |
