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

Commit23b0387

Browse files
committed
Fix too long syslog message problem
1 parent8bba4b4 commit23b0387

File tree

1 file changed

+81
-1
lines changed

1 file changed

+81
-1
lines changed

‎src/backend/utils/misc/trace.c

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
#include"miscadmin.h"
2525
#include"utils/trace.h"
2626

27+
#include<ctype.h>
28+
29+
#ifdefMULTIBYTE
30+
#include"mb/pg_wchar.h"
31+
#endif
32+
2733
/*
2834
* We could support trace messages of indefinite length, as elog() does,
2935
* but it's probably not worth the trouble. Instead limit trace message
@@ -204,16 +210,90 @@ eprintf(const char *fmt,...)
204210
void
205211
write_syslog(intlevel,char*line)
206212
{
213+
#ifndefPG_SYSLOG_LIMIT
214+
#definePG_SYSLOG_LIMIT 128
215+
#endif/* PG_SYSLOG_LIMIT */
216+
207217
staticintopenlog_done=0;
218+
staticcharbuf[PG_SYSLOG_LIMIT+1];
219+
staticintlogid=0;
208220

209221
if (UseSyslog >=1)
210222
{
223+
intlen=strlen(line);
224+
intbuflen;
225+
intseq=0;
226+
intl;
227+
inti;
228+
211229
if (!openlog_done)
212230
{
213231
openlog_done=1;
214232
openlog(PG_LOG_IDENT,LOG_PID |LOG_NDELAY,PG_LOG_FACILITY);
215233
}
216-
syslog(level,"%s",line);
234+
235+
/* divide into multiple syslog() calls if message is
236+
* too long
237+
*/
238+
if (len>PG_SYSLOG_LIMIT)
239+
{
240+
logid++;
241+
242+
while (len>0)
243+
{
244+
strncpy(buf,line,PG_SYSLOG_LIMIT);
245+
buf[PG_SYSLOG_LIMIT]='\0';
246+
247+
l=strlen(buf);
248+
#ifdefMULTIBYTE
249+
/* trim to multibyte letter boundary */
250+
buflen=pg_mbcliplen(buf,l,l);
251+
buf[buflen]='\0';
252+
l=strlen(buf);
253+
#endif
254+
/* already word boundary? */
255+
if (isspace(line[l])||line[l]=='\0')
256+
{
257+
buflen=l;
258+
}
259+
else
260+
{
261+
/* try to divide in word boundary */
262+
i=l-1;
263+
while(i>0&& !isspace(buf[i]))
264+
{
265+
i--;
266+
}
267+
if (i <=0)/* couldn't divide word boundary */
268+
{
269+
buflen=l;
270+
}
271+
else
272+
{
273+
buflen=i;
274+
buf[i]='\0';
275+
}
276+
}
277+
278+
seq++;
279+
/*
280+
* Here we actually call syslog().
281+
* For segmented messages, we add logid
282+
* (incremented at each write_syslog call),
283+
* and seq (incremented at each syslog call
284+
* within a write_syslog call).
285+
* This will prevent syslog to surpress
286+
* "same" messages...
287+
*/
288+
syslog(level,"[%d-%d] %s",logid,seq,buf);
289+
line+=buflen;
290+
len-=buflen;
291+
}
292+
}
293+
else
294+
{
295+
syslog(level,"%s",line);
296+
}
217297
}
218298
}
219299

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp