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

Commit8103f49

Browse files
committed
Be more robust when strerror() doesn't give a useful result.
Back-patch commits8e68816 and8dace66 into the stable branches.Buildfarm testing revealed no great portability surprises, and itseems useful to have this robustness improvement in all branches.
1 parent352ab59 commit8103f49

File tree

1 file changed

+183
-4
lines changed

1 file changed

+183
-4
lines changed

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

Lines changed: 183 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ static void send_message_to_server_log(ErrorData *edata);
153153
staticvoidsend_message_to_frontend(ErrorData*edata);
154154
staticchar*expand_fmt_string(constchar*fmt,ErrorData*edata);
155155
staticconstchar*useful_strerror(interrnum);
156+
staticconstchar*get_errno_symbol(interrnum);
156157
staticconstchar*error_severity(intelevel);
157158
staticvoidappend_with_tabs(StringInfobuf,constchar*str);
158159
staticboolis_log_level_output(intelevel,intlog_min_level);
@@ -2650,7 +2651,7 @@ expand_fmt_string(const char *fmt, ErrorData *edata)
26502651
staticconstchar*
26512652
useful_strerror(interrnum)
26522653
{
2653-
/* this buffer is only used iferrno has a bogus value */
2654+
/* this buffer is only used ifstrerror() and get_errno_symbol() fail */
26542655
staticcharerrorstr_buf[48];
26552656
constchar*str;
26562657

@@ -2662,10 +2663,16 @@ useful_strerror(int errnum)
26622663
str=strerror(errnum);
26632664

26642665
/*
2665-
* Some strerror()s return an empty string for out-of-range errno. This is
2666-
* ANSI C spec compliant, but not exactly useful.
2666+
* Some strerror()s return an empty string for out-of-range errno.This
2667+
* is ANSI C spec compliant, but not exactly useful. Also, we may get
2668+
* back strings of question marks if libc cannot transcode the message to
2669+
* the codeset specified by LC_CTYPE. If we get nothing useful, first try
2670+
* get_errno_symbol(), and if that fails, print the numeric errno.
26672671
*/
2668-
if (str==NULL||*str=='\0')
2672+
if (str==NULL||*str=='\0'||*str=='?')
2673+
str=get_errno_symbol(errnum);
2674+
2675+
if (str==NULL)
26692676
{
26702677
snprintf(errorstr_buf,sizeof(errorstr_buf),
26712678
/*------
@@ -2678,6 +2685,178 @@ useful_strerror(int errnum)
26782685
returnstr;
26792686
}
26802687

2688+
/*
2689+
* Returns a symbol (e.g. "ENOENT") for an errno code.
2690+
* Returns NULL if the code is unrecognized.
2691+
*/
2692+
staticconstchar*
2693+
get_errno_symbol(interrnum)
2694+
{
2695+
switch (errnum)
2696+
{
2697+
caseE2BIG:
2698+
return"E2BIG";
2699+
caseEACCES:
2700+
return"EACCES";
2701+
#ifdefEADDRINUSE
2702+
caseEADDRINUSE:
2703+
return"EADDRINUSE";
2704+
#endif
2705+
#ifdefEADDRNOTAVAIL
2706+
caseEADDRNOTAVAIL:
2707+
return"EADDRNOTAVAIL";
2708+
#endif
2709+
caseEAFNOSUPPORT:
2710+
return"EAFNOSUPPORT";
2711+
#ifdefEAGAIN
2712+
caseEAGAIN:
2713+
return"EAGAIN";
2714+
#endif
2715+
#ifdefEALREADY
2716+
caseEALREADY:
2717+
return"EALREADY";
2718+
#endif
2719+
caseEBADF:
2720+
return"EBADF";
2721+
#ifdefEBADMSG
2722+
caseEBADMSG:
2723+
return"EBADMSG";
2724+
#endif
2725+
caseEBUSY:
2726+
return"EBUSY";
2727+
caseECHILD:
2728+
return"ECHILD";
2729+
#ifdefECONNABORTED
2730+
caseECONNABORTED:
2731+
return"ECONNABORTED";
2732+
#endif
2733+
caseECONNREFUSED:
2734+
return"ECONNREFUSED";
2735+
#ifdefECONNRESET
2736+
caseECONNRESET:
2737+
return"ECONNRESET";
2738+
#endif
2739+
caseEDEADLK:
2740+
return"EDEADLK";
2741+
caseEDOM:
2742+
return"EDOM";
2743+
caseEEXIST:
2744+
return"EEXIST";
2745+
caseEFAULT:
2746+
return"EFAULT";
2747+
caseEFBIG:
2748+
return"EFBIG";
2749+
#ifdefEHOSTUNREACH
2750+
caseEHOSTUNREACH:
2751+
return"EHOSTUNREACH";
2752+
#endif
2753+
caseEIDRM:
2754+
return"EIDRM";
2755+
caseEINPROGRESS:
2756+
return"EINPROGRESS";
2757+
caseEINTR:
2758+
return"EINTR";
2759+
caseEINVAL:
2760+
return"EINVAL";
2761+
caseEIO:
2762+
return"EIO";
2763+
#ifdefEISCONN
2764+
caseEISCONN:
2765+
return"EISCONN";
2766+
#endif
2767+
caseEISDIR:
2768+
return"EISDIR";
2769+
#ifdefELOOP
2770+
caseELOOP:
2771+
return"ELOOP";
2772+
#endif
2773+
caseEMFILE:
2774+
return"EMFILE";
2775+
caseEMLINK:
2776+
return"EMLINK";
2777+
caseEMSGSIZE:
2778+
return"EMSGSIZE";
2779+
caseENAMETOOLONG:
2780+
return"ENAMETOOLONG";
2781+
caseENFILE:
2782+
return"ENFILE";
2783+
caseENOBUFS:
2784+
return"ENOBUFS";
2785+
caseENODEV:
2786+
return"ENODEV";
2787+
caseENOENT:
2788+
return"ENOENT";
2789+
caseENOEXEC:
2790+
return"ENOEXEC";
2791+
caseENOMEM:
2792+
return"ENOMEM";
2793+
caseENOSPC:
2794+
return"ENOSPC";
2795+
caseENOSYS:
2796+
return"ENOSYS";
2797+
#ifdefENOTCONN
2798+
caseENOTCONN:
2799+
return"ENOTCONN";
2800+
#endif
2801+
caseENOTDIR:
2802+
return"ENOTDIR";
2803+
#if defined(ENOTEMPTY)&& (ENOTEMPTY!=EEXIST)/* same code on AIX */
2804+
caseENOTEMPTY:
2805+
return"ENOTEMPTY";
2806+
#endif
2807+
#ifdefENOTSOCK
2808+
caseENOTSOCK:
2809+
return"ENOTSOCK";
2810+
#endif
2811+
#ifdefENOTSUP
2812+
caseENOTSUP:
2813+
return"ENOTSUP";
2814+
#endif
2815+
caseENOTTY:
2816+
return"ENOTTY";
2817+
caseENXIO:
2818+
return"ENXIO";
2819+
#if defined(EOPNOTSUPP)&& (!defined(ENOTSUP)|| (EOPNOTSUPP!=ENOTSUP))
2820+
caseEOPNOTSUPP:
2821+
return"EOPNOTSUPP";
2822+
#endif
2823+
#ifdefEOVERFLOW
2824+
caseEOVERFLOW:
2825+
return"EOVERFLOW";
2826+
#endif
2827+
caseEPERM:
2828+
return"EPERM";
2829+
caseEPIPE:
2830+
return"EPIPE";
2831+
caseEPROTONOSUPPORT:
2832+
return"EPROTONOSUPPORT";
2833+
caseERANGE:
2834+
return"ERANGE";
2835+
#ifdefEROFS
2836+
caseEROFS:
2837+
return"EROFS";
2838+
#endif
2839+
caseESRCH:
2840+
return"ESRCH";
2841+
#ifdefETIMEDOUT
2842+
caseETIMEDOUT:
2843+
return"ETIMEDOUT";
2844+
#endif
2845+
#ifdefETXTBSY
2846+
caseETXTBSY:
2847+
return"ETXTBSY";
2848+
#endif
2849+
#if defined(EWOULDBLOCK)&& (!defined(EAGAIN)|| (EWOULDBLOCK!=EAGAIN))
2850+
caseEWOULDBLOCK:
2851+
return"EWOULDBLOCK";
2852+
#endif
2853+
caseEXDEV:
2854+
return"EXDEV";
2855+
}
2856+
2857+
returnNULL;
2858+
}
2859+
26812860

26822861
/*
26832862
* error_severity --- get localized string representing elevel

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp