Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit08ede42

Browse files
committed
Make elog() switch to ErrorContext while invoking libpq output routines,
since those routines may do palloc's. We want to be fairly sure we cansend the error message to the client even under low-memory conditions.That's what we stashed away 8K in ErrorContext for, after all ...
1 parenta49436d commit08ede42

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

‎src/backend/utils/error/elog.c

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.69 2000/11/25 19:09:22 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.70 2000/12/01 19:52:04 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -30,12 +30,13 @@
3030
#include<syslog.h>
3131
#endif
3232

33+
#include"commands/copy.h"
3334
#include"libpq/libpq.h"
3435
#include"libpq/pqformat.h"
3536
#include"miscadmin.h"
3637
#include"storage/proc.h"
3738
#include"tcop/tcopprot.h"
38-
#include"commands/copy.h"
39+
#include"utils/memutils.h"
3940

4041
#ifdefMULTIBYTE
4142
#include"mb/pg_wchar.h"
@@ -374,8 +375,17 @@ elog(int lev, const char *fmt, ...)
374375
if (lev>DEBUG&&whereToSendOutput==Remote)
375376
{
376377
/* Send IPC message to the front-end program */
378+
MemoryContextoldcxt;
377379
charmsgtype;
378380

381+
/*
382+
* Since backend libpq may call palloc(), switch to a context where
383+
* there's fairly likely to be some free space. After all the
384+
* pushups above, we don't want to drop the ball by running out of
385+
* space now...
386+
*/
387+
oldcxt=MemoryContextSwitchTo(ErrorContext);
388+
379389
if (lev==NOTICE)
380390
msgtype='N';
381391
else
@@ -402,6 +412,8 @@ elog(int lev, const char *fmt, ...)
402412
* much ...
403413
*/
404414
pq_flush();
415+
416+
MemoryContextSwitchTo(oldcxt);
405417
}
406418

407419
if (lev>DEBUG&&whereToSendOutput!=Remote)
@@ -612,6 +624,7 @@ write_syslog(int level, const char *line)
612624
staticboolopenlog_done= false;
613625
staticunsigned longseq=0;
614626
staticintsyslog_fac=LOG_LOCAL0;
627+
615628
intlen=strlen(line);
616629

617630
if (Use_syslog==0)
@@ -649,19 +662,21 @@ write_syslog(int level, const char *line)
649662
/* or if the message contains embedded NewLine(s) '\n' */
650663
if (len>PG_SYSLOG_LIMIT||strchr(line,'\n')!=NULL )
651664
{
652-
staticcharbuf[PG_SYSLOG_LIMIT+1];
653-
intchunk_nr=0;
654-
intbuflen;
665+
intchunk_nr=0;
655666

656667
while (len>0)
657668
{
658-
intl;
659-
inti;
669+
charbuf[PG_SYSLOG_LIMIT+1];
670+
intbuflen;
671+
intl;
672+
inti;
673+
660674
/* if we start at a newline, move ahead one char */
661675
if (line[0]=='\n')
662676
{
663677
line++;
664678
len--;
679+
continue;
665680
}
666681

667682
strncpy(buf,line,PG_SYSLOG_LIMIT);
@@ -681,9 +696,9 @@ write_syslog(int level, const char *line)
681696
buflen=l;
682697
else
683698
{
684-
/* try to dividein word boundary */
699+
/* try to divideat word boundary */
685700
i=l-1;
686-
while(i>0&& !isspace(buf[i]))
701+
while(i>0&& !isspace(buf[i]))
687702
i--;
688703

689704
if (i <=0)/* couldn't divide word boundary */
@@ -702,9 +717,11 @@ write_syslog(int level, const char *line)
702717
len-=buflen;
703718
}
704719
}
705-
/* message short enough */
706720
else
721+
{
722+
/* message short enough */
707723
syslog(level,"[%lu] %s",seq,line);
724+
}
708725
}
709726

710727
#endif/* ENABLE_SYSLOG */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp